Modal Custom Macros
These commands can fully emulate canned cycles to perform repetitive CNC machine operations like hole making.
Share





Think of how hole-making canned cycles work. You provide one command (like G81) that sets the initial variables (XY position, rapid plane, hole-bottom position and feed rate), and the CNC machines the first hole. Each subsequent command will machine another hole. You need only provide the information that changes for each additional hole, like the new XY position. Once you have listed the last hole, you specify a G80 command to cancel the canned cycle.
The G66.1 custom macro calling word lets you do the same thing with your own user-created canned-cycle custom macro programs. You can even create a user-defined G code to call it and modify the function of G80 to cancel it it (although we don’t show how to do this in this short article).
G66.1 will accomplish three things:
1. It will set local variables based on the included letter-address arguments.
2. It will execute the program specified by the P word included in the G66.1 command.
3. It will cause each subsequent command to repeat steps one and two until a G67 word is executed (canceling the modal custom macro calling state).
When the custom-macro-ending M99 word is executed, however, all local variables will be set back to vacant (null). If they are to be retained for the next (modal) command, your custom macro program must transfer local variables to more permanent common variables.
Here is a full example that uses this technique for a thread-milling custom macro:

Consider this calling program:
O0022 (Main program)
N005 G90 G54 S500 M03
N010 G00 X0 Y0
N015 G43 H01 Z1.0
N020 G66.1 P1007 X2.0 Y2.0 Z0.75 T1.0 Q0.125 M3.0 A1.0 F5.0 B1.0 (Call custom macro, mill first thread)
N025 X9.0 (Call custom macro, mill second thread)
N030 Y8.0 (Call custom macro, mill third thread)
N035 X2.0 (Call custom macro, mill fourth thread)
N040 G67
N045 G91 G28 Z0
N050 M30
In line N020, the CNC will set the local variables #24, #25, #26, #20, #17, #13, #1, #9 and #2 to the settings for letter address arguments X, Y, Z, T, Q, M, A, F and B, respectively. It will then execute program O1007 (shown below). It will do the same for line N025, machining the second hole, and two more times for lines N030 and N035. The G67 in line N040 cancels the modal calling state.
In lines N025, N030, and N035, only one local variable (per command) is being assigned. Special care must be given in program O1007 so as not to lose the values of other important arguments. The first 18 commands or so show how:
O1007 (Taper thread milling program)
(Make arguments more permanent)
IF[#24 NE #0] THEN #121 = #24 (X)
IF[#25 NE #0] THEN #122 = #25 (Y)
IF[#26 NE #0] THEN #123 = #26 (Z)
IF[#20 NE #0] THEN #124 = #20 (T)
IF[#17 NE #0] THEN #125 = #17 (Q)
IF[#13 NE #0] THEN #126 = #13 (M)
IF[#1 NE #0] THEN #127 = #1 (A)
IF[#9 NE #0] THEN #128 = #9 (F)
IF[#2 NE #0] THEN #129 = #2 (B)
(Re-assign local variables)
#24 = #121
#25 = #122
#26 = #123
#20 = #124
#17 = #125
#13 = #126
#1 = #127
#9 = #128
#2 = #129
(Reset T and M as radius values)
#20 = #20 / 2
#13 = #13 / 2
IF[#2 EQ 1.0] GOTO 20
(Calculations for top to bottom)
#101 = #24 - #1 + #20
#102 = #24 + #1 - #20
#103 = #25 + #13 - #20
#104 = #25 + #13 - #1
#105 = -[#26 + #17/4]
#106 = #105 - #17/2
#107 = #106 - #17/2
#108 = #107 - #17/4
#109 = #1 - #20
#110 = #13 - #20
#111 = #25 - #13 + #20
#112 = 2
GOTO 60
(Calculations for bottom to top)
N20 #101 = #24 + #1 - #20
#102 = #24 - #1 + #20
#103 = #25 + #13 - #20
#104 = #25 + #13 - #1
#105 = -[#26 - #17/4]
#106 = #105 + #17/2
#107 = #106 + #17/2
#108 = #107 + #17/4
#109 = #1 - #20
#110 = #13 - #20
#111 = #25 - #13 + #20
In this way, creating modal custom macros that fully emulate canned cycles can help you easily perform repetitive machining operations.
Related Content
CNC-Related Features of Custom Macro
CNC-related features of custom macro are separated into two topics: system variables and user-defined G and M codes. This column explores both.
Read MoreCombining Functions With User-Defined G & M Codes
CNC programmers gain flexibility when using custom macros to define G and M codes themselves.
Read MoreHow to Determine the Currently Active Work Offset Number
Determining the currently active work offset number is practical when the program zero point is changing between workpieces in a production run.
Read MoreA Balancing Act for Differential Gaging
Differential gaging measures using two devices, which has advantages over standard, comparative measurements using a single sensing head. These include the ability to measure size without regard to position.
Read MoreRead Next
A New Frontier in Surface Finish Control
What if your machine tool could measure surface roughness as it cuts? This article explores how in-process metrology is advancing from concept to reality, enabling real-time feedback, immediate detection of anomalies and new levels of control over surface quality. Discover the technologies making this possible.
Read MoreHow I Made It: Dennis Rymanowski
Dennis Rymanowski has worked at NSH USA for 60 years, with his passion for manufacturing living alongside his passion for his family’s polka band.
Read More