G65, G66, G67 Custom Macro Call Commands: Fanuc, Siemens, Mitsubishi
Master G65, G66, and G67 macro calls on Fanuc, Siemens, and Mitsubishi. Learn parameter configurations, prevent collisions, and troubleshoot common alarm codes.
Introduction to Custom Macro Call Commands
A carbide cutting tool driving at high velocity into a hardened steel vise jaw, a closed chuck, a clamp, or an indexing turret is the immediate physical consequence of a single uncancelled modal macro call. Programmers and operators frequently configure custom subprograms using G65 and G66 to pass local variable arguments for repetitive operations like probing or pocket milling, but neglecting to cancel these states instantly transforms safe G-code into runaway positioning commands. If the operator forgets to execute a G67 cancellation block before transitioning to a tool change or a secondary coordinate path, the controller continues to execute the subprogram macro automatically after subsequent traverses, resulting in catastrophic mechanical collisions and scrap parts.
Technical Summary
| Specification | Details |
|---|---|
| Command Codes | G65 (Simple Call), G66 (Modal Call A), G66.1 (Modal Call B), G67 (Modal Cancel) |
| Modal Group | Group 00 / Non-modal (G65), Group 12 / Modal (G66, G66.1), Cancel (G67) |
| Supported Brands | Fanuc, Siemens, Mitsubishi |
| Critical Parameters | Fanuc Parameter 6000 (Bit 0 - G67, Bit 5 - SBM), Siemens $MC_EXTERN_FUNCTION_MASK (Bit 6), Mitsubishi Parameter #1241 set13/bit5, Parameter #11053 UserProgramStorage |
| Main Constraint | Macro nesting depth is strictly limited (5 levels deep on Fanuc, 4 levels deep on Mitsubishi) compared to M98 subprogram calls, and programming G65/G66 in the same block as fixed cycles is strictly forbidden. |
Quick Read: Best Practices and Constraints
- Deploy G65 for Single-Block Executions: Program G65 when a custom subprogram needs to execute unconditionally exactly once without leaving a modal state active.
- Deselect Modality via G67: Always program a standalone G67 command immediately after completing G66 or G66.1 loops to prevent unintended macro execution in subsequent traverses.
- Verify Parameter Numeric Types: Pass only integers for subroutine numbers (P) and repetitions (L) to avoid instant controller faults on Siemens and Mitsubishi systems.
- Manage Strict Nesting Limits: Monitor nesting depths closely, keeping calls within the 5-level ceiling on Fanuc and the 4-level ceiling on Mitsubishi to avoid overrun alarms.
- Anchor Storage Destinations: Register subprogram files within the precise disk or memory device paths declared by parameters like Mitsubishi #11053 UserProgramStorage.
- Isolate Call Blocks: Program only one macro call or fixed cycle per NC block to prevent duplicate word clashes and program execution halts.
Basic Concepts of G65, G66, and G67
Custom macro commands like G65, G66, and G66.1 provide programmers with the practical programming effect of passing variable arguments directly into subprograms, enabling highly dynamic part programming and repetitive cycle creation. A common failure cause occurs when programmers mistakenly utilize reserved addresses—such as attempting to pass address G as an argument during a standard G65 call—which instantly triggers a PS0129 alarm code and halts operation. Programmers and operators must also carefully watch the active modal state when using G66 (which executes the macro after every axis movement) or G66.1 (which executes for every block). If an operator forgets to program a G67 to cancel the modal call before transitioning to a new toolpath or a tool change, the CNC will continue to execute the macro unexpectedly. While the provided manuals focus heavily on syntax faults rather than detailing mechanical destruction, an uncancelled modal macro could easily command erratic, compounding secondary movements that drive the tool out of bounds into a vise jaw, chuck, clamp, or turret, ultimately causing a hard collision or yielding a ruined scrap part.
Safe use dictates strict control over how these macros execute during test runs. By utilizing parameter 6000#5 (SBM), operators can explicitly dictate whether a single-block stop is valid or invalid within the custom macro statement, physically preventing the machine from blasting through complex, unchecked logic loops during first-article proving. Fanuc's architecture exhibits highly distinct behaviors in its macro call management. First, Fanuc explicitly splits its modal macro functionality into two distinct behaviors: G66 mathematically delays the macro execution until after an axis movement block completes (ideal for custom drilling patterns), whereas G66.1 unconditionally executes the macro for every single NC block regardless of movement. Second, Fanuc integrates a rigid parameter-aliasing hierarchy (such as parameters 6050 through 6059), allowing machine tool builders to map standard G-codes or M-codes directly to 9000-series macro programs, effectively masking the complex G65 syntax from the operator. Finally, Fanuc strictly separates its mathematical nesting limits, enforcing a maximum five-level deep restriction specifically for macro calls, functioning completely independently from its 15-level subprogram nesting limit.
The practical programming effect of utilizing G65 and G66 is the ability to instantly execute custom logic while dynamically passing variables into the controller's background memory without modifying the core subroutine. While G65 runs the macro exactly once, programmers and operators must intensely watch the system state when G66 is active. Because a modal macro implicitly executes after every single traversing block, any unmonitored active state can prove disastrous during transitional movements. For example, if an operator forgets to command G67 and executes a rapid tool change movement or positions the axes near a rigid peripheral holding device, the controller will automatically plunge into the macro machining logic at the wrong location. This uncommanded execution can drive the tool directly into a hardened vise jaw, a closed chuck, or an indexing turret, resulting in a catastrophic hard collision or generating a scrap part due to unintended over-machining. To ensure safe use, operators must guarantee that the coordinate frame is clear, verify that mechanical holding devices like a clamp are properly engaged, and always systematically isolate modal macros within discrete program blocks to prevent runaway execution. A failure to manage these states will inevitably lead to severe coordinate violations and throw an alarm code that completely paralyzes the channel.
Command Structure and Syntax
The structure of a macro call consists of the calling G-code, the program number target, the repetition count, and the argument list. The argument list assigns numeric values directly to corresponding variables in the subroutine, which lets a single program perform multiple tasks based on input dimensions.
Depending on the CNC system type, the variables map either to numbered local variables or named system variables. The calling syntax remains uniform across major industrial platforms, though each brand supports unique parameter expansions and variable mapping limits.
[Fanuc & Mitsubishi Syntax] G65 P_ L_ [Variable Arguments] ; G66 P_ L_ [Variable Arguments] ; G66.1 P_ L_ [Variable Arguments] ; G67 ;
[Siemens Syntax] G65 P... L... [Parameters] G66 P... L... [Parameters] G67
| Address | Description | Format | Notes |
|---|---|---|---|
| P | Called subprogram number or filename | Integer or bracketed string | Rigidly integer on Fanuc/Siemens; Mitsubishi supports <File name> up to 32 characters |
| L | Repetition count (number of passes) | Integer | Defaults to L1 if omitted. Siemens and Mitsubishi strictly reject decimal formats. |
| Arguments | Dynamic variables passed to macro | Letters A-Z (excluding P, L, O, N) | Mapped to local variables (#1-#33) on Fanuc/Mitsubishi, or variables $C_A-$C_Z on Siemens |
Brand Applications: Fanuc, Siemens, and Mitsubishi
Fanuc
In Fanuc systems, custom macro calling behavior is deeply governed by system variables and configuration parameters. Programmers use Parameter 6000 and Parameter 6007 to modify macro control parameters.
Standard syntax configurations utilize G65 for single calls, G66 for movement-triggered modal calls, and G66.1 for block-by-block modal execution, with G67 providing the cancellation mechanism.
| Parameter / Variable | Setting Behavior | Associated Alarm / Version |
|---|---|---|
| Parameter No. 6000 (Bit 0) | 0 (Issues alarm PS1100 on redundant G67); 1 (Ignores redundant G67) | PS1100 Cancel without modal call |
| Parameter No. 6000 (Bit 5) | 0 (Single-block stop disabled in macro); 1 (Single-block stop valid in macro) | SBM Control |
| Parameter No. 6007 (Bit 3) | 0 (Custom G-code modal call acts like G66.1); 1 (Acts like G66) | MGE Control |
| Parameter No. 6007 (Bit 4) | 0 (Pass arguments in standard NC format); 1 (Convert to macro format) | CVA Control |
Warning: Leaving a modal macro active when executing manual tool changes or rapids will trigger unintended macro looping and lead to hard collisions with the turret or chuck.
Siemens
Siemens controls achieve highly flexible integration by mapping standard ISO-style dialect calls to native Sinumerik variables. The controller expands program names using variable $MC_EXTERN_FUNCTION_MASK.
Syntax execution utilizes G65 for non-modal operations, G66 for modal macro calls, and G67 to delete active modal macro selections.
| Parameter / Variable | Setting Behavior | Associated Alarm / Version |
|---|---|---|
| $C_A to $C_Z | Transfer parameters mapped from A-Z addresses (except P, L, O, N) | System variables |
| $C_I[], $C_J[], $C_K[] | Chronological sequence arrays storing multiple I, J, K parameter passes | Sequence tracking in $C_I_ORDER |
| $MC_EXTERN_FUNCTION_MASK (Bit 6) | 0 (Pads P to 4 digits, >4 digits alarms); 1 (No zero expansion, up to 8 digits) | Alarm 12720 |
Warning: Violating the strict integer format for program number P or loop limit L results in immediate block execution faults and paralyzes the channel.
Mitsubishi
Mitsubishi CNC platforms integrate parameter-driven aliasing to map subprograms to custom codes. Operators configure Parameter #1241 and Parameter #11053 to control argument mapping and program storage.
The platform supports G65 for simple calls, G66 for Modal Call A, G66.1 for Modal Call B, and G67 to cancel active modal states.
| Parameter / Variable | Setting Behavior | Associated Alarm / Version |
|---|---|---|
| Parameter #1241 set13/bit5 | 0 (L and P invalid as variable arguments); 1 (L and P valid as variable arguments) | Macro argument valid setting |
| Parameter #11053 | Defines search device and directory path for the called macro program | P232 Program Error if saved elsewhere |
| Parameter #7202 G[10] Type | 0 (Equivalent to M98); 1 (Equivalent to G65); 2 (G66); 3 (G66.1) | Custom G-code execution type |
| Parameter #1081 Gmac_P | 0 (Standard G-code behavior); 1 (Aliased macro active for system G-code) | G-code aliasing activation |
Warning: Activating a user macro call in conjunction with high-speed high-accuracy control modes triggers immediate program errors.
Brand Comparison Table
| Feature Comparison | Fanuc | Siemens | Mitsubishi |
|---|---|---|---|
| Macro Nesting Depth | Strictly limited to 5 levels deep. | — (no source) | Up to 4 levels deep. |
| Subprogram Nesting Depth | Up to 15 levels deep using M98. | — (no source) | Up to 27 levels deep using M98/M99. |
| String File Naming | — (no source) (numeric-only programs) | — (no source) | Supported. Can enclose up to 32 characters in brackets like <File name>. |
| Modal Call Varieties | Supports G66 (movement trigger) and G66.1 (per-block execution). | Supports G66 (axis traversing trigger). | Supports G66 (Modal Call A, movement trigger) and G66.1 (Modal Call B, per-block execution). |
| Parameter Array Passing | Standard address mapping to local variables #1-#33. Address G is forbidden. | Maps to variables $C_A-$C_Z. Supports up to 10 instances of I, J, K via array sequence mapping. | Standard assignment. Supports simultaneous usage of L and P as variables when Parameter #1241 set13/bit5 = 1. |
Technical Analysis of Control Architectures
The core differences between Fanuc, Siemens, and Mitsubishi macro architectures lie in how they manage system variables, memory allocation, and syntax boundaries. Fanuc enforces a highly structured, rigid address mapping system, where letters are strictly tied to specific numbered local variables, and nesting is tightly capped at five levels. The system divides modal execution clearly between G66 and G66.1, preventing any overlap in movement-based and block-based calls, and relies on strict parameter maps like 6050-6059 for custom aliasing.
Siemens highly distinguishes its macro architecture from other control brands through three advanced behavioral structures. First, Siemens provides unparalleled cross-dialect interoperability; a macro called via an ISO-style G65 seamlessly and automatically populates native Siemens system variables (like $C_X or $C_A), meaning the background subroutine can be written entirely in the powerful native G290 Siemens language while the main program remains 100% compatible with legacy ISO Dialect part programs. Second, Siemens embeds incredibly deep array-based parameter passing capabilities directly into the standard block string. Unlike other controls that overwrite duplicate parameters, Siemens allows programmers to pass up to ten separate I, J, and K values in a single G65 block, natively organizing them into chronological arrays (e.g., $C_I to $C_I[12]) and tracking their exact programming sequence via $C_I_ORDER, enabling highly complex geometric patterns to be passed without requiring custom variable tables. Finally, Siemens allows the machine builder to deeply govern how macro program numbers are digested via machine data bit masks, granting the unique flexibility to rigidly enforce legacy 4-digit zero-padded program limits, or expand the P address interpretation to accommodate modern 8-digit program naming conventions without throwing syntax errors.
Mitsubishi distinguishes its macro architecture from other control platforms through three distinct, highly flexible behaviors. First, Mitsubishi incorporates a highly unique G66.1 "Macro Modal Call B" function that unconditionally calls the macro for each individual block (handling all block data except O, N, and G codes as arguments), rather than only executing after axis movement blocks like the standard G66 command. Second, the Mitsubishi platform natively supports alphanumeric string targeting directly in the G-code block; programmers can call a macro by designating a specific <File name> up to 32 characters long enclosed in angle brackets instead of being rigidly restricted to traditional numeric P-addresses. Finally, Mitsubishi integrates a massive parameter-driven aliasing system that allows users to explicitly map up to 538 custom or system G-codes directly to G65, G66, or G66.1 macro calls. Utilizing parameters such as #7202 G[10] Type, this allows machine tool builders to permanently embed proprietary cycle logic into the machine's base architecture without requiring operators to memorize complex variable strings.
Program Examples and Dry Run Walkthroughs
Fanuc Example: Pocket Milling Cycle
%
O0001 (MAIN PROGRAM - POCKETING SETUP) ;
G90 G54 G00 X0 Y0 Z10. ;
G65 P9010 L1 X100.0 Y80.0 Z-5.0 F300 ; ; Simple call of pocket routine with dimensions
G00 Z100. M30 ;
%
%
O9010 (POCKET ROUTINE - SUBPROGRAM) ;
#10 = #24 / 2.0 (X HALF-WIDTH) ;
#11 = #25 / 2.0 (Y HALF-WIDTH) ;
G01 Z#26 F#9 ; ; Plunge to target depth Z
G01 X#10 F#9 ; ; Cut along X half-width
Y#11 ; ; Cut along Y half-width
X-#10 ; ; Cut negative X
Y-#11 ; ; Cut negative Y
X0 Y0 ; ; Return to center
M99 ; ; Return to main program
%
dry run: The operator executes block G65. The control reads program O9010, mapping address X (100.0) to variable #24, Y (80.0) to #25, Z (-5.0) to #26, and F (300) to #9. The tool plunges to Z-5.0 at feedrate 300. It then computes half-widths #10 (50.0) and #11 (40.0), executing a rectangular pocket path sequentially. At block M99, the subroutine exits, returning path control directly to block G00 in main program O0001.
Siemens Example: Interpolated Bore Array
; MAIN PROGRAM - CIRCULAR MOVEMENT
G90 G54 G00 X0 Y0 Z50.0
G66 P1234 A10.0 C45.0 X100.0 Z-10.0 ; Modal call executes after traverses
X50.0 Y50.0 ; Traversing block triggers subprogram 1234
X150.0 Y100.0 ; Second traversing block triggers subprogram 1234
G67 ; Cancel active modal macro call
G00 Z100.0 M30
%
; SUBPROGRAM 1234 - BORE HELIX
G01 Z$C_Z F250 ; Plunge to Z depth passed from address Z
G03 I$C_A U$C_C ; Circular helical entry using parameters A and C
G01 Z5.0
M99
%
dry run: The control processes G66 and loads subprogram 1234 with arguments A=10.0, C=45.0, X=100.0, and Z=-10.0. The axis traverses to X50.0 Y50.0. Upon reaching this coordinate, the modal trigger fires, executing subroutine 1234. The tool plunges to Z-10.0 ($C_Z) and performs helical entry using arguments $C_A and $C_C. After M99, the tool traverses to X150.0 Y100.0, which immediately re-triggers subprogram 1234 at the new position. The G67 block executes, cancelling modal state before tool retraction.
Mitsubishi Example: Custom Probing Routine
; MAIN PROGRAM - FILENAME TARGETING
G90 G54 G00 X0 Y0 Z25.
G65 <PROBE_X> L1 X150. Y100. S2. ; ; Call macro by filename with target variables
G00 Z100. M30
%
; FILENAME: PROBE_X
(SUBPROGRAM FOR SIDE MEASUREMENT)
G01 X#24 F150 ;
IF [#19 EQ 2.] GOTO 10 ;
#30 = #5021 ;
GOTO 20 ;
N10 #30 = #5022 ;
N20 G00 X0 ;
M99 ;
%
dry run: The operator initiates G65 with alphanumeric target <PROBE_X>. The control searches Parameter #11053 UserProgramStorage disk, loads file PROBE_X, and assigns X (150.0) to variable #24, Y (100.0) to #25, and S (2.0) to #19. The probe moves to X150.0 at feedrate 150. Finding variable #19 equals 2.0, the logic jumps to N10, capturing coordinate register #5022 into #30. The probe retracts to X0 and exits via M99 back to the main program.
Error Analysis and Troubleshooting
| Brand & Alarm | Trigger Condition | Operator Symptom | Root Cause / Fix |
|---|---|---|---|
| Fanuc - PS1100 | G67 cancel command executed when no G66 modal state is active. | Program halts instantly with red status indicator on panel. | Parameter 6000#0 is set to 0. Correct the program to remove redundant G67 or set Parameter 6000#0 to 1. |
| Fanuc - PS0129 | Address 'G' is included in G65 or G66 argument assignment list. | Immediate syntax alarm block stop when parsing the call. | Address G is reserved. Switch argument code from G to another variable letter (A-Z except P, L, O, N) or use G66.1. |
| Siemens - Alarm 12720 | G65 or G66 is programmed without defining a subprogram number via address P. | Machine halts, throwing cycle execution alarm on display. | Missing subprogram number target. Add a valid subroutine number using the P address in the macro call. |
| Siemens - Alarm 12722 | G65/G66 programmed in the same block as a fixed cycle (G81-G89) or another macro. | CNC rejects block parsing and freezes channel movement. | Block conflict. Separate the macro call and the fixed cycle or secondary command into separate consecutive blocks. |
| Mitsubishi - P276 | G67 cancel command is issued while the CNC is not in an active G66/G66.1 modal state. | NC cycles stop, returning program execution error. | Illegal cancellation sequence. Program G67 only after active modal macro routines. |
| Mitsubishi - P232 | Designated macro subroutine is registered in an unauthorized storage device. | Control throws file missing error, halting mid-cycle. | Path mismatch. Move the subroutine file to the device matching Parameter #11053 UserProgramStorage. |
Application Note: Avoiding Mechanical Collisions
Driving a carbide cutting tool directly into a hardened steel vise jaw, a closed chuck, a clamp, or an indexing turret is the immediate physical consequence of a single uncancelled modal macro call. Safe operation relies on isolating modal calls within discrete program blocks and validating variable limits before execution. Programmers must enforce strict nesting boundaries, verifying that the subprogram layers do not exceed the five-level maximum on Fanuc or the four-level maximum on Mitsubishi to prevent overrun alarms. Utilizing parameter 6000#5 (SBM) on Fanuc systems allows operators to safely single-step through macro logic during first-article proving, ensuring that internal coordinate offsets do not result in uncommanded axis traverses. In Siemens systems, operators must monitor array variables like $C_I[] to $C_I[12] and sequence tracking via $C_I_ORDER when multiple arguments are loaded in a single block. In Mitsubishi setups, the program must be verified against Parameter #11053 UserProgramStorage to prevent unexpected storage search errors that freeze axis drives mid-operation.
Related Command Network
- M98 / M99 Subprogram Call: Executes subprograms without argument variable transmission, allowing nesting up to 15 levels on Fanuc and 27 levels on Mitsubishi.
- G60 Exact Stop / Continuous Path: Often paired with custom macro routines to force complete axis deceleration between coordinate steps, preventing corner rounding during high-feed macro loops, which is detailed in the G60 Exact Stop / Continuous Path.
- G62 / G63 Corner Override / Tapping: Prevents cutting feed deceleration or corner chipping inside critical macro pocketing and tapping subprograms, as described in the G62/G63 Corner Override / Tapping.
- G50 / G92 Coordinate System Setting: Establishes global work coordinates, ensuring that variable macro offsets align perfectly with physical workpiece references, as covered in the G50 and G92 Coordinate System Setting.
Conclusion
Deploying G65, G66, and G67 commands optimizes program structure by converting static G-code into dynamic, argument-driven cycles. Maintaining clear isolation between modal commands and subsequent movements prevents disastrous axis overruns and coordinate drift. Systematic parameter validation, strict nesting adherence, and the mandatory execution of G67 cancellation blocks prior to tool changes preserve machine tool integrity and guarantee high-accuracy surface finishes.
Frequently Asked Questions
Can a decimal value be passed as a macro program number?
No. Passing a decimal or real value to address P triggers an immediate controller alarm. The subroutine program number P must be declared strictly as an integer. Always double-check program calls in the main routine to verify that no decimal point is appended to the program number.
What occurs if G67 is commanded when no modal macro call is active?
The behavior depends entirely on parameter configuration. In Fanuc systems, if Parameter 6000#0 is set to 0, the control throws alarm PS1100. If set to 1, the control ignores the redundant cancel block. On Mitsubishi platforms, redundant G67 commands trigger a P276 error, halting program execution. Systematically match parameter selections to avoid unnecessary alarm halts.
How does single-block execution behave inside a custom macro call?
Control behavior is governed by specific parameters. On Fanuc, Parameter 6000#5 (SBM) decides if single-block stops are active (1) or ignored (0) during macro blocks. Enabling SBM is highly recommended when proving first-article macro paths to allow step-by-step verification of coordinate math, preventing rapid unchecked crashes.
Still not resolved?
Ask our AI assistant about this topic in natural language. Grounded in verified sources, no hallucinations.

- CNC CARE Co-Founder (May 2025 - Present)
- Mitsubishi Electric NC Sales & Service Section Manager (2008 - 2025)
- Reis CNC Service Engineer (2003 - 2005)
- Ören Kalıp CNC Mold Line Team Leader (1999 - 2002)
With over 25 years of experience working in all areas of the CNC machine industry, I continue my activities as a co-founder of CNC CARE, where we offer brand-independent consulting, engineering, and original spare parts services.
Related Articles
Other articles on this topic
Siemens CYCLE800 G-Code: Swivel Planes & Tool Alignment
Master Siemens CYCLE800 for 3+2 axis machining. Learn plane swiveling, tool alignment, parameter setup, and how to troubleshoot Alarm 61190 and 61153.
Siemens CYCLE72 Contour Milling: Guide to Sinumerik Path Milling
Master Siemens CYCLE72 for contour milling on Sinumerik CNC controls. Learn parameter setup, avoid simulation alarm 61123, and prevent machine collisions.
Siemens CYCLE952 Contour Turning Cycle Programming Guide
Master Siemens CYCLE952 contour turning on Sinumerik CNC controls. Learn parameter lists, resolve Alarm 61051, and configure balance cutting.
Siemens SLOT1 and SLOT2 Slot Milling Cycles Programming Guide
Master slot milling on Siemens Sinumerik controls using SLOT1 and SLOT2 cycles. Learn parameter configurations, alarm 61000 prevention, and optimal tool paths.