Custom G/M Cycles

Custom G-Code Assignment

Parameters 6050-6059 map custom G-codes to programs O9010-O9019. When the control reads the custom G-code, it executes the mapped O9xxx program with G65-style argument passing. The program O9010-O9019 must exist in the CNC memory (usually in protected memory).

Parameter Program Called Example: Set to Result
6050O9010100G100 calls O9010
6051O9011101G101 calls O9011
6052O9012102G102 calls O9012
6053O9013200G200 calls O9013
6054O9014201G201 calls O9014
6055O9015500G500 calls O9015
6056O9016
6057O9017
6058O9018
6059O9019

G-code numbers should use numbers not already assigned to standard functions. Typically G100+, G200+, or G500+ are safe ranges.

Custom G-Code Numbering Rules

Selecting the right G-code number is critical. You cannot reuse numbers already assigned to standard Fanuc functions.

Rule Details
Reserved G-codesCannot use G00, G01, G02, G03, G17, G20, G21, G28, G40-G43, G54-G59, G73-G89, G90, G91, G98, G99, etc.
Safe rangesG100-G199, G200-G299, G500-G599
Parameter valueMust be the G-code number WITHOUT the "G" prefix (e.g., set to 100, not G100)
Integer onlyOnly integer values allowed (no decimal G-codes)

Custom M-Code Macros

M-codes can also trigger macro programs, but through a fundamentally different mechanism than custom G-codes. M-code macros run through the PMC (Programmable Machine Controller) interface, not directly through the macro executor.

Aspect Custom G-Code Custom M-Code
Setup methodParameters 6050-6059PMC ladder logic
Execution pathMacro executor (direct)PMC interface
ComplexitySimple parameter settingRequires ladder logic configuration
Common rangeG100+, G200+, G500+M100+ range
Typical setup byProgrammer / operatorMachine tool builder

Argument Passing

Custom G-codes use the same argument system as G65 macro calls. Argument style 1 maps all letters A-Z (except G, L, N, O, P) to local variables in the called program.

Example Call

G100 A1.5 B2.0 X10.0 Y20.0 Z-5.0
(Passes values to O9010:)
(  #1 = 1.5   from A)
(  #2 = 2.0   from B)
(  #24 = 10.0 from X)
(  #25 = 20.0 from Y)
(  #26 = -5.0 from Z)

The argument style (1 or 2) is determined by parameter 6200 (bit setting). Argument style 1 is the most common and maps single letters to variables. Argument style 2 allows multi-use of certain letters (I, J, K) for additional data pairs.

Designing a Custom Cycle

Follow these steps to create a reliable custom G-code cycle.

Step Action Details
1Choose a G-code numberCheck it is not in use (G100+, G200+, G500+)
2Set the parametere.g., Parameter 6050 = 100 for G100
3Write the O90xx programInclude argument validation and error handling
4Document the interfaceHeader comments listing all inputs/outputs
5Protect the programParameter 3202 bit 4 = lock O9000 programs

Best Practices

Always validate arguments with #3000 alarms so the operator gets a clear error message instead of unexpected behavior. Document all inputs and outputs in the program header comments. Save and restore the modal state (#3003, #3004, G90/G91) so the calling program is not affected. Use M99 to return from the macro.

Worked Example - Custom Probing Cycle

This example creates a custom G100 single-surface probing cycle. It validates all required arguments, sets defaults where appropriate, and stores the measured Z position in #500.

(O9010 - CUSTOM SINGLE SURFACE PROBE G100)
(G100 X_ Y_ Z_ F_ H_)
(X,Y = APPROACH POSITION)
(Z = PROBE DEPTH)
(F = PROBE FEED RATE - DEFAULT 200)
(H = TOOL LENGTH OFFSET NUMBER)
(OUTPUT: #500=MEASURED Z)
(-----------------------------------)
IF [#24 EQ #0] THEN #3000=100(X POSITION REQUIRED)
IF [#25 EQ #0] THEN #3000=101(Y POSITION REQUIRED)
IF [#26 EQ #0] THEN #3000=102(Z DEPTH REQUIRED)
IF [#9 EQ #0] THEN #9=200. (DEFAULT FEED)
IF [#11 EQ #0] THEN #3000=103(H OFFSET REQUIRED)
(-----------------------------------)
#3003=1 (DISABLE SINGLE BLOCK)
G90 G00 X#24 Y#25
G43 Z10.0 H#11
G31 Z#26 F#9 (PROBE MOVE)
#500=#5063 (STORE Z AT SKIP SIGNAL)
G90 G00 Z10.0
#3003=0
M99

See also: Macro Structure for G65 vs G66 macro call details, Fanuc Parameters for parameter 6050-6059 setup, and Argument Variables for letter-to-variable mapping.

References

  • Peter Smid, Fanuc CNC Custom Macros, Industrial Press, 2004.
  • Fanuc, Operator’s Manual / Parameter Manual, FANUC Corporation.

Have a question or want to contribute?

Contact us with corrections, additions, or topics you'd like covered.

Get in Touch