Parametric Programming in CNC: G65, G66, G67 Macro Calls Explained with Examples
Parametric programming allows you to write reusable, dynamic, and intelligent CNC programs using variables and logic — just like coding for machines. It’s widely supported on Fanuc, Haas, Siemens, and other controllers (as Macro B or Custom Macros).
This guide focuses on using G65, G66, and G67 to execute macros and pass variables to subroutines.
🔍 What is Parametric Programming?
In basic G-code, values like coordinates and feedrates are fixed. Parametric programming allows you to use variables (like #1, #2, etc.) to make programs adaptable and automated.
Benefits:
- Reuse logic with different inputs
- Perform calculations
- Create loops, conditions, and branching
- Build custom machining cycles
📘 Key G-Codes: G65, G66, G67
| G-Code | Function |
|---|---|
| G65 | Call a macro subprogram once |
| G66 | Call a macro subprogram modal |
| G67 | Cancel G66 modal macro call |
🧪 G65 – One-Time Macro Call
Syntax:
G65 Pxxxx Axx Bxx Cxx...
P= Program number to call (e.g., P9010)A,B,C, etc. = Arguments passed as variables (#1, #2, etc.)
📍 Example: Drilling Holes with Variable Depth
G65 P9001 X10 Y10 Z-15 F200
G65 P9001 X30 Y10 Z-10 F200
G65 P9001 X50 Y10 Z-20 F200
O9001 Macro Program (Stored Separately):
O9001
G0 X#24 Y#25 (Move to X and Y)
G1 Z#26 F#9 (Drill to Z at feed F)
G0 Z5
M99
| Letter | Maps to Variable |
|---|---|
| X | #24 |
| Y | #25 |
| Z | #26 |
| F | #9 |
🔁 G66 – Modal Macro Call
Calls the macro repeatedly on each new line, until canceled by G67.
📍 Example:
G66 P9002 Z-10 F100
X0 Y0
X30 Y0
X60 Y0
G67
Each X/Y move triggers the macro.
O9002:
O9002
G0 X#24 Y#25
G1 Z#26 F#9
G0 Z5
M99
⛔ G67 – Cancel Modal Macro
Cancels the effect of G66 and returns control to normal G-code flow.
🧠 Advanced Macro Example – Bolt Circle Pattern
This macro drills holes in a circular pattern:
Main Program:
G65 P9010 R50 I6 X0 Y0 Z-10 F200
| Param | Meaning |
|---|---|
| R | Radius (mm) |
| I | Number of holes |
| X/Y | Center of circle |
| Z | Drill depth |
Macro (O9010):
O9010
#100 = 0
#101 = 360 / #4 (angle step = 360 / holes)
WHILE [#100 LT #4] DO1
#110 = COS[#100 * #101] * #3 + #24
#111 = SIN[#100 * #101] * #3 + #25
G0 X#110 Y#111
G1 Z#26 F#9
G0 Z5
#100 = #100 + 1
END1
M99
⚙️ Tips for Using G65/G66 Macros
- Always simulate macro programs first — they can behave differently than expected.
- Use clear variable mapping and comments.
- Group related macros by program number range (e.g., 9000–9099).
- Store macros in the control’s library or memory card.
✅ Use Cases of Parametric Programming
| Application | Macro Use |
|---|---|
| Drilling patterns | Bolt circles, grid arrays |
| Probe cycles | Part location verification |
| Fixture offsets | Automated WCS switching |
| Tool life management | Counting, replacement logic |
| Repeating subroutines | Family-of-parts programming |
📌 Summary
Parametric programming unlocks a new level of CNC automation. With G65, G66, and G67, you can:
- Call powerful macros
- Pass dynamic values
- Build intelligent, reusable programs
- Automate repetitive cycles with fewer lines of G-code
Once you master macros, you don’t just write G-code — you engineer CNC logic.
✅ Next Suggested Topic:
“Understanding Modal vs Non-Modal G-Codes – The Hidden Cause of G-Code Mistakes”
Leave a comment