Fanuc G-Code Macros vs Haas Macros – What’s the Difference?
G-code macros are powerful tools to automate repetitive tasks, create parametric machining cycles, and add flexibility to CNC programming. However, Fanuc and Haas controllers implement macros differently, which affects how programmers write and use them.
This article compares the two systems and provides guidance on transitioning or optimizing macro code for each.
1. Macro Programming Basics
Both Fanuc and Haas support:
- Macro variables (
#100and up) - Conditional statements (
IF,WHILE,GOTO) - Subprogram calls (
Oxxxx) - Mathematical operations (
+,-,*,/,SIN,COS)
But syntax, variable ranges, and available functions differ.
2. Fanuc Macro System
- Supports Macro B, a very powerful macro system.
- Variables range from
#1to#33for system variables,#100to#999for user variables. - Macro programs typically start with an
Onumber, e.g.,O9000. - Uses
IFwith logical operators:EQ,NE,GT,LT,GE,LE. - Supports arithmetic, trigonometric functions, and advanced logic.
- Common macro commands:
#<_variable>for local variablesGOTOandM99for flow control
Example Fanuc Macro snippet:
O9000
#100=10
#101=20
IF [#100 LT #101] GOTO 100
M30
N100
G01 X[#100+5] Y[#101-5] F200
M30
3. Haas Macro System
- Simplified macro capabilities compared to Fanuc.
- Variables range:
#1to#33(system variables), and#100to#199(user variables). - Macro subprograms start with
Oxxxxas well. - Uses
IFstatements but with slightly different syntax. - Limited or no support for advanced trig or math functions.
- Flow control using
GOTO,M99. - Often used for simple parametric drilling, boring, or repetitive moves.
Example Haas Macro snippet:
O9000
#100=10
#101=20
IF [#100 LT #101] THEN GOTO 100
M30
N100
G01 X[#100+5] Y[#101-5] F200
M30
4. Key Differences
| Feature | Fanuc Macro B | Haas Macros |
|---|---|---|
| Variable Range | #1–#33 (system), #100–#999 (user) | #1–#33 (system), #100–#199 (user) |
| Advanced Math Functions | Full support (SIN, COS, TAN, etc.) | Limited or no advanced math |
| Conditional Syntax | Uses EQ, NE, GT, LT | Uses =, !=, <, > |
| Macro Programming Power | High (complex loops, calculations) | Moderate (simpler tasks) |
| Subroutine Calling | Yes, with parameters | Yes, limited parameters |
5. Transition Tips
- When porting macros from Fanuc to Haas, simplify math and logic.
- Replace unsupported functions with pre-calculated values or simpler code.
- Test extensively due to syntax differences.
- Use comments liberally to document differences.
6. Practical Applications
- Fanuc macros suit complex automation, adaptive machining, probing routines.
- Haas macros are great for standardized repetitive tasks, tool offsets, simple parametric moves.
7. Conclusion
Understanding these differences allows CNC programmers to:
- Write portable code
- Maximize controller capabilities
- Reduce debugging time
- Improve automation workflow
Leave a comment