Printed from Kezuriba (kezuriba.net/en/nc/g65/)
G65
Machining center, LatheOne-shot, group 00Macro call (simple call, with arguments)
Format and notes
G65 P_ (program number) L_ (repeat count) A_ B_ … (arguments)
- Unlike M98, arguments can be passed by address (A, B, X, Z, etc.). The passed values go into the macro's local variables
- Haas: when writing an M-code in the same block, write it after G65 (writing it before causes an alarm)
- Correspondence of arguments and local variables (argument specification I): A→#1, B→#2, C→#3, I→#4, J→#5, K→#6, D→#7, E→#8, F→#9, H→#11, M→#13, Q→#17, R→#18, S→#19, T→#20, U→#21, V→#22, W→#23, X→#24, Y→#25, Z→#26. G, L, N, O and P cannot be used as arguments (Mitsubishi Electric, Haas)
- Put a decimal point on argument values. Without it, the value may be read as a number in the usual digits of that address (the least input increment). On Haas with the mm setting, A1 becomes 0.001
- When called with G65, local variables #1–#33 become a new set. The caller's values are saved, and variables not passed as arguments start empty (undefined). A subprogram called with M98 uses the same #1–#33 as the caller (Haas)
- When repeating with L, the arguments are loaded only on the first pass. From the second pass on, the values rewritten in the previous pass remain as they are (Haas)
- Difference from M98: other commands written in an M98 block are executed before the jump. In a G65 block, everything other than P and L is treated as an argument, and the block does not move. Write the arguments after G65 (writing them before causes an alarm) (Siemens ISO dialect)
- Write I, J and K in the order I, J, K. There is also a form (argument specification II) that lists up to 10 sets of I, J, K, in which case they go into #4 through #33 in order (Mitsubishi Electric, Haas)
- A macro returns to the caller with M99. G65 is one-shot, so write it on every line where you want to call it. To call it automatically after every move, use G66
Example
G90 G54 G00 X0 Y0 ; G43 H03 Z30. ; G65 P9010 X10. Y20. Z-8. R2. F120. I15. K4. ; (4 HOLES, PITCH 15) G00 Z30. ; M30 ; O9010 ; (DRILL A ROW OF HOLES) #30 = 0 ; (COUNTER) WHILE [#30 LT #6] DO1 ; (#6 = K: NUMBER OF HOLES) G00 X[#24 + #30 * #4] Y#25 ; (#24 = X, #4 = I, #25 = Y) Z#18 ; (#18 = R) G01 Z#26 F#9 ; (#26 = Z, #9 = F) G00 Z#18 ; #30 = #30 + 1 ; END1 ; M99 ;
An example that calls macro O9010, which drills 4 holes at 15 mm intervals in the X direction starting from X10. Y20., from R2. down to Z-8. at F120. Inside the macro, X is in #24, Y in #25, Z in #26, R in #18, F in #9, I in #4 and K in #6. #30 is a local variable that receives no argument and is used to count the holes. The values are for illustration.
Full guide with examples: Intro to custom macros and subprograms (M98, M99, G65, # variables)
Differences between controls and machines
The same code can be written or assigned differently depending on the CNC control and the machine builder. Always check your machine’s manual.
| Source | Machine | Item | Detail |
|---|---|---|---|
| Haas | Machining center | Notes | G65 calls can be nested up to 9 levels |
| Mitsubishi Electric | — | Format | Instead of a number, the call can use a file name, as in G65 <file name> L_ arguments |
Frequently asked questions about G65
- What is G65 (Macro call (simple call, with arguments)) used for and how is it formatted in a CNC program?
- G65 commands "Macro call (simple call, with arguments)" on Machining center, Lathe. The standard program format is "G65 P_ (program number) L_ (repeat count) A_ B_ … (arguments)". Unlike M98, arguments can be passed by address (A, B, X, Z, etc.). The passed values go into the macro's local variables
- Is G65 a modal code or a one-shot (non-modal) code?
- G65 is a one-shot (non-modal, Group 00) code. It acts only in the single block where it is written and does not carry over to the next block, so you must write G65 on every line where that action is required.
- Does G65 work differently on machining centers (mills) versus CNC lathes?
- G65 is primarily used on Machining center, Lathe. Depending on the machine type and the lathe G-code system (System A, B, or C), this code may be unavailable or assigned to a different function, so verify against your machine tool manual.
- Are there differences in G65 across FANUC, Mitsubishi, Okuma, Haas, and Siemens controls?
- Yes. Control builders such as FANUC, Mitsubishi Electric (M80/M800), Okuma (OSP), Haas, Mazak, Siemens (SINUMERIK ISO dialect), and Heidenhain can differ in argument letters, decimal-point rules, and optional parameters for G65. Review the control comparison table above and verify the exact syntax in your machine’s programming manual before proving out the program.
Sources
The meaning of this code agrees in two or more sources from different publishers. Explanations are written in our own words.
- Siemens AG — SINUMERIK 802D sl/840D/840D sl/840Di/840Di sl/810D Programming Manual ISO Milling, 04.2007 Edition (6FC5398-7BP10-0BA0) cache.industry.siemens.com
- Haas Automation, Inc. — G-code, M-code, and Setting (per-code explanation pages) haascnc.com
- Haas Automation, Inc. — Mill Operator's Manual – 17 Mill G-Codes (online version) haascnc.com
- Haas Automation, Inc. — Lathe Operator's Manual – 16 Lathe G-Codes (online version) haascnc.com
- Haas Automation, Inc. — Mill Operator's Manual – 13 Macros (online version) haascnc.com
- Mitsubishi Electric — MITSUBISHI CNC 700/70 Series Programming Manual (Lathe System) (IB-1500057) mitsubishielectric.com