Skip to main content
CNC.wiki

G65 Custom Macro Call: Non-Modal Parameter Programming Guide

Master G65 non-modal macro calls on Fanuc, Siemens, and Mitsubishi CNC systems. Configure variables, prevent hard collisions, and resolve program alarm codes.

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

CNC CARE Co-founder

Introduction to G65 Custom Macro Call

A catastrophic hard collision that shatters the cutting tool, damages the axis ball screws, and converts the raw stock into a completely ruined scrap part occurs if the cutting tool on the indexing turret travels along a shifted, uncompensated trajectory and strikes table-mounted fixture clamps, a workpiece fixture vise jaw, or the rotating jaws of a spindle chuck due to a mathematical or coordinate calculation error inside G65 macro equations. Because G65 is non-modal, the compiler parses and transfers arguments immediately upon execution, applying deceleration checks. Bypassing soft travel limits or deactivating protection barriers (such as G22/G23 chuck/tailstock barriers on Fanuc and Mitsubishi, or WALIMON on Siemens) removes the electronic envelope, causing the tool post turret or tool carrier to crash directly into table-mounted fixture clamps, a raw stock fixture vise jaw, or the rotating jaws of a spindle chuck. Operators must perform dry runs in single-block mode and verify workpiece zero shifts on the setup screen prior to automatic operation.

Parametric programming of the non-modal G65 custom macro call on CNC controls provides programmers with the mathematical flexibility to develop highly dynamic, parametric toolpaths. Unlike standard subprograms called with M98 which simply repeat static geometry, G65 executes a one-shot macro call while transferring critical parameter values as local variables. This lets the macro program compute coordinates, feedrates, and scaling on-the-fly, which is highly effective for families of parts. Proper management of active coordinate offsets, such as the G54 workpiece coordinate system, the G53 machine coordinate selection, and the G52 local coordinate system, is critical to ensure that transitions back to the main program remain safe and aligned.

Technical Summary

Technical AttributeSpecification
Command CodeG65
Modal GroupGroup 00 (Non-modal / One-shot)
Supported BrandsFanuc, Siemens, Mitsubishi
Critical ParametersFanuc: Parameter 1241, Parameter 3402; Siemens: MD 18800, $MC_EXTERN_FUNCTION_MASK; Mitsubishi: Parameter #1241, Parameter #1296
Main ConstraintNesting depth is limited to 4 levels, and consecutive macro statements can cause look-ahead pre-read buffer exhaustion.

Quick Read

  • Deciding to use G65 allows dynamic parameter transfer to local variables, enabling parametric geometry calculations.
  • Activating G65 calls the subprogram only in the block where it is written, as it is a non-modal instruction.
  • Configuring parameter 1241 on Fanuc and Mitsubishi determines whether address letters L and P are treated as arguments.
  • Toggling the Siemens interpreter to ISO Dialect mode via G291 is required to parse and process G65 blocks.
  • Limiting macro nesting to a maximum of four levels prevents register stack overflows across all control systems.
  • Avoiding comma separators in argument definitions is mandatory to prevent syntax errors such as Program Error P33.

Basic Concepts of Non-Modal Macro Calls

Practical programming of the non-modal G65 custom macro call provides programmers with the mathematical flexibility to develop highly dynamic, parametric toolpaths. Unlike standard subprograms called with M98 which simply repeat static geometry blocks, G65 executes a one-shot macro call while transferring critical parameter values as local variables (#1 to #33) or system variables into the macro memory space. This lets the macro program compute coordinates, feedrates, and scaling on-the-fly, which is highly effective for families of parts, bolt hole circles, or custom machining cycles. However, because G65 is non-modal, it applies deceleration checks and parses immediately upon execution.

Operators and programmers must maintain absolute vigilance when setting up programs that utilize nested G65 macro calls. 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 calculation error is executed inside the macro calculations, the tool will travel along an uncompensated trajectory. Rather than stopping safely at established software boundaries, the turret or tool carrier can bypass soft travel limits and drive the cutting tool directly into a table-mounted workpiece clamp, a raw stock fixture vise jaw, or the rotating jaws of a spindle chuck. This sudden coordinate deviation results in a catastrophic hard collision, shatters the cutting tool, damages the axis ball screws, throws an axis overload or preprocessor alarm code, and converts the raw stock into a completely ruined scrap part.

A critical cause of program failure occurs when the look-ahead pre-read buffer is exhausted by too many consecutive non-movement blocks (such as variable calculations or system variable assignments) inside the macro program. If the pre-read limit is exceeded while cutter radius compensation is active, the control fails to calculate the correct intersection vectors, leading to a silent path deviation that overcuts the material, resulting in a ruined scrap part and triggering an offset alarm code. Additionally, when testing macros at the HMI, operators must never attempt to adjust manual feedrate overrides or spindle override switches when tapping or threading cycles are active inside the macro, as the axis-to-spindle synchronization rules clamp these overrides at 100% to prevent stripping.

Command Structure and Syntax

The G65 command is structured to specify the target macro subprogram and the variables that are passed to it in a single block. The program number is identified using address P, which represents the subprogram stored in the memory. Alternatively, a text-based file name can be enclosed in angle brackets to call external files. Address L specifies the repetition count for the macro program, allowing the controller to repeat the calculations and movements without returning to the main program between passes.

The remaining addresses in the block are treated as arguments that are mapped to specific local variables. There are two primary argument mapping designations supported by the compilers. Argument Designation I maps alphabetical address letters to local variables. Argument Designation II is utilized when multiple sets of coordinate values are passed, mapping coordinates sequentially. The parameter values are read by the macro and stored in local variable registers to execute math and path adjustments on-the-fly.

G65 P__ L__ [arguments] ;

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

G65 Pxxxx Lyyyy <arguments> ;
BrandParameter / VariableDescription
FanucParameter 1241 (Bit 5)Enables the macro argument L/P valid function to map L and P to local variables.
FanucParameter 3402 (Bit 6)Clear state parameter determining if modal states are initialized upon reset.
Siemens$MC_EXTERN_FUNCTION_MASK (Bit 6)Controls the digit padding and parsing limit of G65 program numbers.
SiemensMD 18800 $MN_MM_EXTERN_LANGUAGEActivates the external ISO Dialect NC compiler.
MitsubishiParameter #1241 (Bit 5)Macro argument L/P valid function configuration.
MitsubishiParameter #1296 (Bit 5)Determines if G65 is treated as an executable statement or macro statement.

Brand-Specific Applications

Fanuc

On Fanuc systems, G65 is a non-modal Group 00 command. It allows dynamic parameter mapping, which is configured via parameter 1241 and parameter 3402 to control argument mapping and clear states.

G65 P1000 A10.5 B20.0 X30.0 Y50.0 F150.0 ;
CategorySystem ItemDescription
ParameterParameter 1241Enables macro argument L/P valid function when set to 1.
ParameterParameter 3402Controls modal state initialization upon reset.
AlarmProgram Error (P232)Triggered if the designated program number P is not found.
AlarmProgram Error (P241)Triggered if a variable expression contains a negative variable number.
VersionSeries 15 FormatLegacy format (Parameter 0001 Bit 1 FCV = 1) switches subprogram formats.

Warning: Attempting to program sequence jumps with H codes will trigger a syntax error as H is interpreted as variable #11.

Siemens

Siemens controls parse G65 blocks when toggled to ISO Dialect mode via G291. Program numbers are padded to four digits if $MC_EXTERN_FUNCTION_MASK is set to 0.

G291 ;
G65 P0010 F55 X150.0 Y100.0 S2000 ;
G290 ;
CategorySystem ItemDescription
Parameter$MC_EXTERN_FUNCTION_MASK (Bit 6)Controls digit padding (Bit 6 = 0: padded to 4 digits; Bit 6 = 1: up to 8 digits).
ParameterMD 18800 $MN_MM_EXTERN_LANGUAGEMust be set to 1 to compile external G65 blocks.
AlarmAlarm 61800External CNC system missing when MD 18800 is disabled.
AlarmAlarm 12722More than one subroutine call or macro replacement per block.
Version840D sl vs. 802D slThe 802D sl hard-locks WALIM_GEOAX_CHANGE_MODE and lacks collision avoidance options.

Warning: Failing to specify an index when reading array variables like $C_I, $C_J, or $C_K will trigger preprocessor syntax errors.

Mitsubishi

On Mitsubishi systems, G65 is configured via parameter #1241 to map L and P addresses and parameter #1296 to manage block-to-block motion.

G65 P1000 A15.0 B25.0 F150.0 Z-10.0 ;
CategorySystem ItemDescription
ParameterParameter #1241Enables macro argument L/P valid function when set to 1.
ParameterParameter #1296Determines if G65 is treated as an executable or macro statement.
AlarmProgram Error (P232)Triggered if the designated program number P is not found in NC memory.
AlarmProgram Error (P33)Triggered if comma-separated arguments are programmed when parameter #1241 is active.
VersionM80V Type B SeriesHigh-accuracy modes are subject to locks, and spline interpolation (G61.2) triggers P39.

Warning: Running macros with Macro Single active will halt axis motion at each statement, potentially leaving tool dwell marks.

Cross-Brand Comparison

Feature / TopicFanucSiemensMitsubishi
Variable Register StructureFlat local variable mapping (#1 to #33)Structured variables with $C_ prefix (e.g. $C_A, $C_I[])Flat local variable mapping (#1 to #33)
Bilingual Compiler TogglingNative execution without togglingRequires toggling interpreter to ISO Dialect mode via G291 to parse ISO G65 blocksSupports format switch compiler via G188/G189 lathe/mill formats
Macro Argument L/P RestrictionParsed natively without bit configurationDiscards flat variables, relies entirely on $C_ systemSupported on M8 Series via Parameter #1241 set13/bit5 to toggle validation
Coordinate Recovery / Reverse RunHandwheel rollback and dynamic path tracking not supportedDeselects active zero offsets and modals during native frame rollbackSupports handwheel rollback via G127 manual reverse run, maintaining macro coordinate system states in modal storage

Deep Technical Analysis

Analyzing the macro architectures of the three manufacturers reveals fundamental differences in parameter variable structures. Fanuc and Mitsubishi controls map G65 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 G65 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 G65 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 G65 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

G65 P1000 A10.5 B20.0 X30.0 Y50.0 F150.0 ;

Dry Run

The operator initiates a dry run in single-block mode. Block 1 calls the macro subprogram O1000 once. The argument A is transferred to local variable #1 as value 10.5, B is mapped to #2 as 20.0, X is mapped to #24 as 30.0, Y is mapped to #25 as 50.0, and F is mapped to #9 as 150.0. The controller pauses to load these local variable registers, evaluates coordinate and feed equations within the macro program, and executes the tool path. Once the macro finishes, control returns to the main program.

Siemens Example

N10 G291 ;
N20 G65 P0010 F55 X150.0 Y100.0 S2000 ;
N30 G290 ;

Dry Run

During the program dry run, Block N10 switches the compiler to ISO Dialect mode to interpret macro structures. Block N20 calls macro program O0010, transferring parameters F, X, Y, and S to system variables. Block N30 switches the compiler back to native Siemens mode. Within the macro subprogram, the values are read from system variables (such as $C_X, $C_Y) and stored in Siemens local variables to calculate tool paths. The macro terminates with M99 or M17 to resume the main program.

Mitsubishi Example

G65 P2000 A1.1 B-2.2 D3.3 I4.4 I7.7 ;

Dry Run

The operator monitors the dry run. Block 1 calls macro subprogram O2000. Argument A is mapped to #1 as 1.1, B is mapped to #2 as -2.2, D is mapped to #7 as 3.3. Address I is programmed twice in the block: I4.4 maps to #4, but the secondary I7.7 overwrites variable #7. This duplicate argument designation overwrites the D argument, meaning variable #7 is loaded with 7.7 instead of 3.3. The control executes the path using the overwritten value, which requires careful path checking to avoid collisions.

Error and Alarm Analysis

BrandAlarm CodeTrigger ConditionOperator SymptomRoot Cause / Fix
FanucProgram Error (P232)The designated program number P_ called by G65 is not found in the NC program memory.The machine halts execution immediately at the G65 block and displays the alarm message.Ensure that the subprogram corresponding to the O-number exists in the NC memory.
FanucProgram Error (P33)G65 macro commands are not issued in an independent block, or arguments contain commas.The CNC control enters a feed hold state and halts execution before block movements begin.Isolate the G65 command in its own program block and remove any comma separators from arguments.
SiemensAlarm 61800 "External CNC system missing"G291 or a G65 macro call is commanded while machine data MD 18800 is disabled.The control system refuses to parse the G65 instruction and halts processing immediately.Enable MD 18800 or set option bit 19800 to activate the external NC dialect interpreter.
SiemensAlarm 12722More than one subroutine call or M-function macro replacement is executed per block.Preprocessor halts, preventing execution of the program block and showing the alarm code.Separate multiple macro calls and subprogram calls into distinct part program blocks.
MitsubishiProgram Error (P33)Address ,D or a string inside < > is commanded while the L/P macro argument function is enabled.The control halts axis movement and displays the alarm on the operator panel.Remove commas and verify that the syntax of argument transfer parameters matches rules.
MitsubishiProgram Error (P35)A block contains an address whose data is out of range.Machine stops execution during pre-read block analysis and generates an out-of-range alarm.Verify coordinate and value limit arguments passed through the G65 block.

Practical Application Notes

A catastrophic hard collision that shatters the cutting tool, damages the axis ball screws, and converts the raw stock into a completely ruined scrap part occurs if the cutting tool on the indexing turret travels along a shifted trajectory and strikes table-mounted fixture clamps, a workpiece fixture vise jaw, or the rotating jaws of a spindle chuck. This risk is particularly acute during G65 macro calls because the command parses parameter variables instantly. To prevent coordinate deviation, programmers must configure working area limitations such as G25/G26 and check that all coordinates remain within the soft travel limits of the axis. Setup operators must physically secure the stock, dry-run the macro programs in single block mode, and verify that active tool offsets match the coordinate systems programmed in the macro memory before initiating automatic machining cycles.

Related Command Network

  • M98: Calls standard subprograms where static geometry blocks are repeated without allowing argument parameter transfers.
  • M99: Terminates the macro program and returns execution to the next block in the calling main program.
  • G66: Activates the modal macro call, which executes the called macro after each movement block until canceled.
  • G67: Cancels the modal macro call mode, returning the compiler to standard coordinate motion execution.
  • G290 / G291: Switches the Siemens compiler interpreter between native SINUMERIK mode and external ISO Dialect mode.

Key Takeaways and Conclusion

Parametric toolpath calculation using G65 non-modal macro calls optimizes cycle efficiency and reduces program file size for families of parts. Programmers must ensure precise argument mapping to local or system variables and configure machine parameters correctly, while operators must perform initial single-block dry runs to verify coordinate safety and prevent collisions.

Frequently Asked Questions

Why does G65 map arguments differently on Fanuc compared to Siemens controls?

Fanuc maps G65 argument letters directly to flat local variables numbered #1 to #33, which are initialized within a single program system. Siemens controls running in native mode do not use flat hashes, instead using structured system variables with a $C_ prefix such as $C_A. Programmers must use G291 to compile ISO blocks and G290 to read these values into native Siemens parameters for advanced calculations.

How can coordinate overwrites be avoided when mixing G65 argument designations?

Mixing alphabetical addresses and sequential coordinate groups that map to the same local variable (such as D and a second I, which both map to #7) causes the latter programmed address to overwrite the variable. Programmers should review the variable mapping tables for turning and milling, separate overlapping arguments, and verify variables on the controller's register screen during a dry run.

What occurs if a G65 macro call is executed while the look-ahead buffer is exhausted?

Executing too many consecutive non-movement calculation blocks inside a macro exhausts the look-ahead buffer, which prevents the controller from calculating correct cutter compensation intersection vectors. Programmers should insert movement blocks or temporary stops, and operators must check for silent path deviations or surface dwell marks on the first machined part.

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