Skip to main content
CNC.wiki

Mastering G66 Custom Macro Modal Call on CNC Control Systems

Learn to program the G66 custom macro modal call. Compare Fanuc Parameter 3402, Siemens MD 18800, and Mitsubishi parameters to prevent hard collisions.

Hakan Gündoğdu
Hakan Gündoğdu

CNC CARE Co-founder

Introduction to G66 Custom Macro Modal Call

Executing automated cycle operations without checking macro variables and offsets introduces a critical production risk on the shop floor. If an uncompensated tool path is executed during G66 modal macro loops (due to tool nose radius compensation calculations or look-ahead failures), the tool indexing turret will travel along a dangerously shifted trajectory. Bypassing soft travel limits can drive the cutting tool on the indexing turret directly into table-mounted fixture clamps, a workpiece fixture vise jaw, or the rotating jaws of a spindle chuck. This sudden positioning error results in a catastrophic hard collision (crash), shatters the cutting tool, damages the axis ball screws, throws an NC system alarm code, and converts the raw stock into a completely ruined scrap part.

To prevent these physical consequences, programmers and setup operators must establish a secure electronic protection envelope around sensitive workholding. Modifying parameters and G-code execution modes requires a deep understanding of how different CNC control systems handle Group 12 or Group 14 modal macro calls. Proper management of active coordinate offsets, such as the G65 custom macro call, the G64 continuous path mode, and the G61 exact stop mode, is critical to ensure that transitions back to the main program remain safe and aligned. This text establishes the rules, syntax structures, and parameter overrides required to program custom macro modal calls safely.

Technical Summary

Technical AttributeSpecifications
Command CodesG66 (Macro Modal Call A), G66.1 (Macro Modal Call B), G67 (Cancel)
Modal GroupsGroup 12 on Fanuc, Group 14 on Mitsubishi, Modal on Siemens
Supported BrandsFanuc, Siemens, Mitsubishi
Critical ParametersParameter No. 3402 Bit 6 (Fanuc CLR), $MC_EXTERN_FUNCTION_MASK Bit 6 (Siemens digit padding), Parameter #1241 set13/bit5 (Mitsubishi L/P valid)
Main ConstraintMaximum nesting level is 4 levels. High-density non-motion blocks inside the subprogram can exhaust the look-ahead buffer (Parameter No. 19625) and trigger tool trajectory errors.

Quick Read

  • Decide between G66 and G66.1 based on whether the custom macro subprogram must trigger only on movement blocks (G66) or unconditionally on every block (G66.1).
  • Program a standalone G67 block immediately after completing the coordinate cycle to prevent subsequent standard travel blocks from triggering the macro.
  • Limit the depth of nested macro calls (G65 and G66/G66.1 combined) to a maximum of 4 levels to avoid system stacking overflows.
  • Verify that MD 18800 is set to 1 and active external language compilation (G291) is enabled before executing G66 on Siemens SINUMERIK controls.
  • Enable Mitsubishi parameter #1241 (set13/bit5) to permit passing subprogram repetition (L) and calling program number (P) as transfer arguments.
  • Prevent preprocessor stops in Siemens G64 continuous-path mode by avoiding display commands (MSG) and status variable queries ($A...) inside the modal macro subprogram.

Basic Concepts of Modal Macro Calls

Practical programming of the custom macro modal call (G66/G66.1) on Fanuc controls provides applications engineers with the mathematical flexibility to coordinate repetitive machining geometries with dynamic logic variables. This modal structure is highly effective for grid drilling, pocket milling patterns, or custom roughing loops because it automatically triggers the specified macro program at every coordinate end-point on subsequent motion blocks, drastically reducing program length. Setup operators and programmers must be aware that while G66 modal calls execute rapidly, the single block stop points during single block operation stop at the end points of internally created blocks, requiring multiple starts to execute a single coordinate sequence.

To prevent unexpected movement of the machine, feed hold, feedrate override, and single block functions can be disabled programmatically by modifying custom macro system variable #3004, meaning the operator has no manual control once the cycle begins. Setup operators must properly calibrate workpiece coordinate settings, tool offsets, and stored stroke limits before automatic cycle start. Prior to initiating automatic cycles, the setup operator must physically position and secure the raw stock within the workpiece fixture vise jaw, spindle chuck, or table-mounted clamp.

If a coordinate system is incorrectly set, or if an uncompensated tool path is executed during G66 modal macro loops (such as due to tool nose radius compensation calculations or look-ahead failures), the tool indexing turret will travel along a dangerously shifted trajectory. If soft travel limits are exceeded or barriers are bypassed, the axis can drive the cutting tool on the indexing turret directly into table-mounted fixture clamps, a workpiece fixture vise jaw, or the rotating jaws of a spindle chuck. This sudden positioning error results in a catastrophic hard collision (crash), shatters the cutting tool, damages the axis ball screws, throws an NC system alarm code (such as Alarm PS0325 or Alarm PS0368), and converts the raw stock into a completely ruined scrap part. Operators must dry-run macro-based programs in single-block mode and utilize the stored stroke limits (G22/G23) and PMC selector signals to establish a secure electronic protection envelope around sensitive workholding.

Command Structure and Syntax

The syntax structure of a modal macro call assigns specific address letters to pass arguments into local variables inside the subroutine. When G66 is active, the machine processes coordinate positions in the main program and automatically calls the macro program immediately after motion completes. This allows the subprogram to read local variables, calculate new toolpaths or coordinate shifts on-the-fly, and perform tasks like hole preparation or localized milling.

The cancel command G67 must be written in a separate block. If this cancel command is omitted, the controller remains in modal call mode, which means any future axis motion will trigger the subprogram. A separate parameter determines whether the system resets this modal state to clear when the CNC machine is turned on or reset.

G66 P__ L__ [arguments] ;

For Siemens SINUMERIK native mode, the syntax includes additional sub-codes and parameters:

G66 Pxxxx Lyyyy <arguments> ;
BrandParameter ReferenceFunction DescriptionValue / State Range
FanucParameter No. 3402 Bit 6 (CLR)Configures G-code Group 12 clear state default setting on power-on or system reset.0 (not cleared) or 1 (cleared on reset)
FanucParameter No. 19625Maximum look-ahead blocks in tool radius offset mode to prevent buffer exhaustion.Integer value ($N$ blocks)
FanucParameter No. 5040 Bit 3 (TCT)Tool Change Type configuration register.0 (turret) or 1 (ATC)
FanucParameter No. 5000 Bit 3 (GNI)Vector calculations in G40 cutter compensation cancel blocks.0 (normal vectors) or 1 (legacy math emulation)
Siemens$MC_EXTERN_FUNCTION_MASK Bit 6Controls digit padding and program number verification limits.0 (padded to 4 digits) or 1 (unpadded up to 8 digits)
SiemensMD 18800 $MN_MM_EXTERN_LANGUAGEMachine data parameter to enable external ISO Dialect compiling.1 (enabled) or 0 (disabled)
MitsubishiParameter #1241 set13/bit5Determines macro argument valid configuration for addresses L and P.0 (disabled) or 1 (passes L and P to #12 and #16)
MitsubishiParameter #1296 ext32/bit5Configures batch statement processing for continuous axis movement.0 (disabled) or 1 (batch execution active)
MitsubishiParameter #8129Configures subprogram search digit count for evaluating P codes.4-digit or 8-digit program search mode

Brand-Specific Applications

Fanuc

Fanuc controls integrate modal macro calling in preparatory Group 12. Programmers can modify Parameter No. 3402 Bit 6 to control the default clear state, while Parameter No. 19625 defines the maximum look-ahead buffer capacity. The basic command string uses G66 P_ L_ followed by letters representing variable arguments, and is canceled by executing G67.

CategorySystem ItemDescription
ParametersParameter No. 3402 Bit 6 (CLR), Parameter No. 19625, Parameter No. 5040 Bit 3 (TCT), Parameter No. 5000 Bit 3 (GNI)Configures G-code Group 12 clear state default setting on power-on or reset, maximum look-ahead blocks in offset mode, tool change type, and G40 vector calculation.
AlarmsAlarm PS0325, Alarm PS0368, Alarm PS0010, Alarm PS0538Triggered by macro calls within cycles like G71/G72, active offsets during parameter changes, improper G-codes, and omitted G40 cancel blocks.
VersionsSeries 15 Format, Series 30i/31i/32i-B PlusSeries 15 format (Parameter No. 0001 Bit 1 FCV = 1) allows address L for repeats; modern Series 30i/31i/32i-B Plus uses Parameter No. 5000 Bit 3 GNI for legacy G40 compatibility.

Warning: Modifying Tool Change Type parameter settings while offsets are active will trigger an immediate NC emergency halt.

Siemens

Siemens controls manage modal macro execution by switching from native mode to ISO Dialect mode. Programmers must verify MD 18800 is enabled, and can adjust the program number padding using the mask variable $MC_EXTERN_FUNCTION_MASK. Transitioning to ISO Dialect mode requires programming G291 before executing G66 P_ L_ <arguments>, and returning to native mode uses G290.

CategorySystem ItemDescription
ParametersMD 18800 $MN_MM_EXTERN_LANGUAGE, $MC_EXTERN_FUNCTION_MASK Bit 6, MD 20150 $MC_GCODE_RESET_VALUESMachine data parameter to enable external ISO Dialect compiling, digit padding and program number verification limits, and default G-code reset values.
AlarmsAlarm 61800, Alarm 12470, Alarm 14016, Alarm 12722Triggered by missing external NC language, concurrent subroutine calls, concurrent replacement cycle conflicts, and multiple calls per part program line.
VersionsSINUMERIK 840D sl vs. 802D sl840D sl supports fully adjustable SLASH_MASK and MD 10604 machine data, widescreen multi-touch panel HMI formats, and active collision avoidance options, while 802D sl has locked configurations.

Warning: Attempting to call multiple M-function replacements and modal subroutine calls in the same line triggers a preprocessor compiler conflict.

Mitsubishi

Mitsubishi controls execute modal calls within G-code Group 14. Programmers adjust Parameter #1241 set13/bit5 to control L/P variable parsing, and check Parameter #1296 ext32/bit5 to adjust execution modes. Commands are parsed as G66 P_ L_ for axis movement execution (Modal A) or G66.1 for unconditional per-block macro execution (Modal B), terminated by G67.

CategorySystem ItemDescription
ParametersParameter #1241 set13/bit5, Parameter #1296 ext32/bit5, Parameter #8129, Parameter #11053 UserProgramStorageControls macro argument L/P validity mapping, macro execution batch block processing, program number search digit count, and storage device search order.
AlarmsProgram Error (P232), Program Error (P33), Program Error (P652), Program Error (P39)Triggered by missing macro programs in storage, inactive modal cancel commands, active sub part system control, and spline interpolation conflicts under active G66/G66.1.
VersionsM80V Type B Series, Legacy M2/M0 FormatM80V Type B series locks spline interpolations, TCP control (G43.4), and inclined surface machining under G66 modal calls; legacy M2/M0 format uses G22/G23/G68 and reverses L and P addresses.

Warning: Activating high-accuracy spline interpolations or coordinate systems under G66 modal calls on M80V Type B controls will trigger software locks and cause emergency halts.

Cross-Brand Comparison

Feature / TopicFanucSiemensMitsubishi
Modal G-code GroupGroup 12Modal ISOGroup 14
Compiler ToggleNone (Native)Required (G291 to ISO, G290 to Siemens)None (Native, switches formats with G188/G189)
Parameter Locked ValidationNone (native address parsing)— (no source)Yes (Parameter #1241 set13/bit5 for L and P validity)
Handwheel Rollback Tracking (G127)NoNoYes (maintains modals and offsets using storage block)
Statement Interpretation SwitchNoNoYes (Parameter #1296 ext32/bit5 toggles statement interpretation)

Deep Technical Analysis

Analyzing the custom macro architectures of the three manufacturers reveals fundamental differences in parameter variable structures. Fanuc and Mitsubishi controls map G66 argument letters directly to flat local variables numbered #1 to #33, maintaining high compatibility. In contrast, Siemens controls running native mode completely discard flat local register hashes, instead utilizing structured, REAL or INT system variables with a $C_ prefix (such as $C_A to $C_Z, or arrays like $C_I[] for repeating addresses) to evaluate and transfer parameters, which provides a significantly more object-oriented programming environment.

Interpreter toggling and format switching represent another area of difference. Siemens requires the programmer to explicitly switch the compiler to ISO Dialect mode via G291 to compile legacy ISO-style G66 blocks, then execute native parametric frames in Siemens mode via G290, and return to ISO mode via G291 for motion. Mitsubishi uses a bimodal Program Format Switch (G188/G189) that re-maps macro modals on-the-fly between the lathe and milling systems. Fanuc parses G66 arguments natively within its standard compiler, requiring no interpreter switching.

Finally, argument locking and coordinate recovery systems differ significantly. Mitsubishi integrates a parameter-locked validation flag (parameter #1241 set13/bit5) to enable or disable addresses L and P as arguments, a function that is absent on standard Fanuc controls. Additionally, Mitsubishi integrates G66 modal coordinate states with its manual arbitrary reverse run (G127) function. When G127 is active, the operator can manually turn the handwheel backward to retract the tool. Mitsubishi’s motion kernel successfully tracks and maintains the active macro coordinate systems, nose radius compensations, and offsets using its specialized modal information storage block, preventing axis drift and maintaining coordinate safety. Fanuc and Siemens controls do not support manual handwheel rollback that can recover coordinate states in this manner.

Program Examples and Dry Runs

Fanuc Example

G28 U0 W0 ; Home return
T0101 M06 ; Tool call
G66 P1000 L2 A15.0 B30.0 ; Activate modal Macro Call A (O1000) with 2 repeats, passing arguments A and B
G00 X100.0 Z10.0 ; Rapid positioning
G01 X150.0 Z-50.0 F150.0 ; Linear move, automatically runs macro O1000
G01 X200.0 Z-100.0 ; Another linear move, runs macro O1000
G67 ; Cancel modal macro call
M30 ; End of program

Dry Run

Before running the program on raw stock, active tool nose radius compensation and coordinates must be checked. Load the subprogram O1000 into control memory. Turn on the dry run switch and single block mode on the operator panel. During execution, watch the position display screen at the end of each positioning block (G01 X150.0 Z-50.0). The tool must halt, and the operator must verify that the coordinate system is correctly offset. Visually inspect that the tool nose remains safe from the fixture vise jaw or spindle chuck jaws during the two automated cycles. Execute the cancel block G67 and verify that standard block-by-block operation is restored.

Siemens Example

G291 ; Switch compiler to ISO Dialect mode to enable G66/G67 processing
G66 P0100 L2 A15.0 B30.0 ; Activate modal Macro Call A for program 100 with 2 repetitions
G00 X100.0 Y50.0 ; Rapid move
G01 X150.0 Y75.0 F150.0 ; Linear traverse block that automatically executes the macro program upon completion
G01 X200.0 Y100.0 ; Linear traverse block, executes macro program upon completion
G67 ; Deselect the modal macro call, returning to standard block-by-block ISO Dialect processing
G290 ; Switch back to native Siemens mode
M30 ; End of program

Dry Run

Ensure that Siemens machine data MD 18800 is active (1). Switch the HMI screen to show active alarms and coordinates. With the dry run speed set to low, execute G291 to switch the interpreter. Verify that subroutine SPF0100 exists. During single-block execution, monitor each axis coordinate transition. Verify that the continuous path blending does not cause sudden axis deceleration at coordinate X150.0 Y75.0. Confirm that the subroutine return jump M99 (or native return) correctly transfers execution back to the main program before G67 cancels the modal state.

Mitsubishi Example

T0101 ; Tool call
G66 P1000 L2 A15.0 B30.0 ; Activate movement-triggered modal call for program O1000 with 2 passes
G00 X100.0 Z10.0 ; Rapid positioning
G01 X150.0 Y75.0 F150.0 ; Linear positioning; subprogram O1000 executes automatically after positioning completes
G01 X200.0 Y150.0 ; Linear positioning; subprogram O1000 executes automatically
G67 ; Deactivate Group 14 modal call to restore standard NC block processing
M30 ; End of program

Dry Run

Verify parameter #1241 is enabled to allow argument transfer for addresses L and P. Load O1000 into active storage. Enable dry run mode and run the program. Use the handwheel rollback function G127 if any coordinate shift appears incorrect, retracting the tool along the path. Verify that the modal coordinates are maintained in the modal information storage block without drifting. At the completion of the cycle, confirm that G67 cancels the modal macro call before the turret moves to tool change zones.

Error and Alarm Analysis

BrandAlarm CodeTrigger ConditionOperator SymptomRoot Cause / Fix
FanucAlarm PS0325Programming G66 modal call within finishing blocks (P/Q sequence) of cycles like G71/G72.NC console flashes "UNAVAILABLE COMMAND IS IN SHAPE PROGRAM" and halts coordinate path calculations.Remove G66/G66.1 from the repetitive cycle blocks; place the modal call outside sequence coordinates.
FanucAlarm PS0368Modifying Tool Change Type parameter (No. 5040 bit 3) when tool or coordinate offset is active.NC control locks with "OFFSET REMAIN AT OFFSET COMMAND" and stops automatic execution.Cancel all active length offsets and work coordinate offsets before changing binary parameter TCT.
SiemensAlarm 61800Compiler switch (G291) or G66 execution attempted when MD 18800 is disabled.Control displays "External CNC system missing" and rejects G66 modal call parsing.Set machine data MD 18800 $MN_MM_EXTERN_LANGUAGE = 1 to enable the ISO Dialect compiler option.
SiemensAlarm 14016Subroutine return, end of program, or G66 programmed concurrently with M/T function replacement cycle block.Program stops preprocessor compilation immediately with Alarm 14016.Do not combine modal subroutine calls and function replacements in the same program block.
MitsubishiProgram Error (P232)Designated program number P_ or macro file name inside < > cannot be found in memory or storage.Console displays Program Error P232 and refuses to start the automatic loop cycle.Verify the O-number program exists and is loaded into active memory or designated storage devices.
MitsubishiProgram Error (P33)Executing G67 cancel command when no G66 modal call is currently active.Controller halts with Program Error P33 during block processing.Ensure a G66 or G66.1 modal macro call is active in the current path before commanding G67 cancel.

Practical Application Notes

Severe axis ball screw damage and shattered cutting tools occur when operators execute coordinate shift programs under active G66/G66.1 modal loops without setting stored stroke limits (G22/G23 or Siemens G25/G26). A coordinate calculation error inside the macro, or an uncompensated path due to look-ahead failures, drives the cutting tool on the indexing turret directly into the workpiece fixture vise jaw, spindle chuck jaws, or table-mounted clamps. Setup operators must verify coordinate limits in single-block dry run mode, ensuring the axis halts before the tool nose collides with the workholding jaws.

Related Command Network

  • G65 (Custom Macro Simple Call): Triggers a custom macro program only once for the block in which it is programmed, unlike G66 which remains modally active for all subsequent movement blocks.
  • G67 (Modal Macro Call Cancel): Deactivates active macro modal calls and returns the compiler to standard block-by-block G-code processing.
  • G64 (Continuous Path Mode): Blends contour transitions without deceleration check stops, but is interrupted by preprocessor stops if display commands (MSG) are called inside an active G66 program.
  • G61 (Exact Stop Mode): Forces the control to check for deceleration at the end of every block, ensuring precise coordinate alignment between G66 macro iterations.

Key Takeaways and Conclusion

Maximizing shop floor safety and program efficiency when utilizing G66 custom macro modal calls depends on strict parameter configuration and pre-run validation. Operators must ensure that correct offset values are registered, look-ahead buffers are not overloaded, and G67 cancel blocks are programmed immediately after coordinate motion cycles. Running a dry run in single-block mode ensures electronic envelopes prevent collisions between the turret and the fixture clamps.

Frequently Asked Questions

How do G66 and G66.1 differ during execution?

G66 executes the custom macro subprogram only after completing a block that commands coordinate axis movement, whereas G66.1 triggers the subprogram unconditionally at the end of every single block, whether motion is programmed or not. Action: Use G66 for machining patterns like grid drilling, and restrict G66.1 to monitoring functions or coordinate calculations that do not require axis travel.

What causes Alarm PS0325 on Fanuc controls during macro loops?

This alarm occurs when a G66 modal call is nested within the finishing shape definition blocks (defined by P and Q sequence numbers) of multiple repetitive cycles like G71 or G72. Action: Remove the G66/G66.1 block from the sequence range, or use a simple G65 call in a separate block outside the cycle bounds.

Why does Siemens continuous-path mode G64 hesitate during a G66 call?

The SINUMERIK look-ahead preprocessor halts path blending when it encounters display instructions (MSG) or reads machine system variables ($A...) inside the macro subprogram. Action: Eliminate non-essential messages and status checks within the modal macro to allow smooth velocity blending across coordinates.

Still not resolved?

Ask our AI assistant about this topic in natural language. Grounded in verified sources, no hallucinations.

Ask AI Assistant
Hakan Gündoğdu
Hakan Gündoğdu
  • CNC CARE Co-Founder (May 2025 - Present)
  • Mitsubishi Electric NC Sales & Service Section Manager (2008 - 2025)
  • Reis CNC Service Engineer (2003 - 2008)
  • Ö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