MacroMill CNC Automation Software

Common FANUC macro mistakes that crash machines, and how to catch them first

MacroMill VMC simulator for FANUC 0i-MF Plus style controls

Most FANUC macro mistakes are not exotic. They are small slips — a vacant variable, a leftover G91, a depth with the wrong sign — and they only show up when the machine moves. The way to catch them first is to know what they look like, put checks in the macro, and test the program in a simulator before you prove it out on the machine.

The software is for training and simulation only. Yes, programs and macros you write and test in a MacroMill simulator can be saved or exported and run on a real CNC machine. As with any new program, prove it out first with single block, reduced rapids and a dry run before you cut.

This is a practical list of common Custom Macro B mistakes, with a short wrong and right example for each. The language itself is covered in the practical guide to FANUC Custom Macro B. For a worked program that already uses input checks and loop clamps, see Write a FANUC macro, test it in MacroMill, then run it on your machine. For what parametric programming can do in a shop, and for a career, see The black art of CNC macro programming, and what it can do for your career.

1. Using a vacant variable in a calculation

A G65 argument that was not passed is vacant, not zero. #0 is the vacant value. If you use a vacant variable in arithmetic, the control alarms. If you test EQ 0 instead of EQ #0, a missing X and a real X0. look the same, so a centre at X0 can be rejected, or a missing depth can be treated as Z0 and the tool can be sent to the wrong height.

(WRONG - X WAS NOT PASSED, #24 IS VACANT)
G65 P8011 Y50. Z-8.
#30=#24+#25
IF[#24 EQ 0]GOTO900

(RIGHT)
IF[#24 EQ #0]GOTO900
IF[#25 EQ #0]GOTO900
IF[#26 EQ #0]GOTO900
#30=#24+#25

Catch it by watching the variables in a MacroMill simulator after the G65 call. If a required argument is vacant, add the #0 test and an alarm before any calculation.

2. Mixing up local and common variables

Local variables #1 to #33 belong to that macro call and nesting level. They do not remember values for the next G65 call. Common variables #100 to #199 stay until they are changed or the control is powered down, and #500 to #999 stay after power down. If you count parts in #1, the count vanishes on the next call. If you use #100 as scratch and never set it, the previous program’s value is still there.

(WRONG - #1 DOES NOT PERSIST, #100 IS NOT RESET)
#1=#1+1
#100=#100+1

(RIGHT - START FROM A KNOWN VALUE, OR KEEP IT LOCAL)
#100=0
#100=#100+1
#31=0
#31=#31+1

Catch it in the simulator by looking at #100 before the program starts. If it is not the value you expect, you are carrying data from a previous run.

3. Leaving G90 or G91 changed after the macro

A macro that switches to G91 for a loop and then returns with M99 leaves the main program in incremental. The next X or Z move is a step, not a position, and that is a common way to run into a fixture or the workpiece. The same risk applies to other modal codes you change and do not restore, such as plane or feed mode.

(WRONG - RETURNS IN G91)
G91
WHILE[#31 LT #4]DO1
G01 X#23
#31=#31+1
END1
M99

(RIGHT - RESTORE THE CALLER'S G90 OR G91)
#3=#4003
G91
WHILE[#31 LT #4]DO1
G01 X#23
#31=#31+1
END1
G#3
M99

Catch it by running the caller and the macro together in the simulator, then watching the move after M99 and the modal G codes. Restore group 03 from #4003 rather than forcing G90, in case the caller was already in G91.

4. Missing decimal points

On many FANUC controls, a number without a decimal point is read as a count of the least input increment, not as millimetres or inches. X10 is then not the same as X10. That can turn a planned 10 mm move into a tiny creep, or, on another setting, a short value into a long one. Always write the decimal point in coordinates, feeds and macro arguments.

(WRONG)
G00 X50 Y0 Z2
G65 P8011 X50 Y0 Z-8

(RIGHT)
G00 X50. Y0. Z2.
G65 P8011 X50. Y0. Z-8.

Catch it on the 2D and 3D toolpath graphs. If the path is far too short, or far too long, look for missing decimals first.

5. Getting the sign wrong on Z depth

Milling depth is usually a negative Z in G90. If the call passes Z8. and the macro does G01 Z#26, the tool goes to plus 8, not into the pocket. The other way is worse: a macro that flips the sign, or a clearance entered as a negative, can send the tool below the part.

(WRONG - POSITIVE DEPTH USED AS AN ABSOLUTE Z)
G65 P8011 X0. Y0. Z8. I80. J50.
G01 Z#26 F#9

(RIGHT - REQUIRE A NEGATIVE DEPTH)
IF[#26 EQ #0]GOTO900
IF[#26 GE 0]GOTO900
G01 Z#26 F#9

Catch it by watching Absolute Z and the 3D toolpath in the simulator. If the tool climbs, or only cuts in the air, check the sign of Z and of the clearance R before you change anything else.

6. Off-by-one and infinite WHILE loops

If the counter never changes, WHILE never ends. If you use LT when you meant LE, the last pass is skipped and stock is left. If you add a step after the end test, the tool can walk past the edge. For the loop rules, see How a FANUC macro WHILE loop works.

(WRONG - COUNTER NEVER CHANGES, LOOP NEVER ENDS)
#31=0
WHILE[#31 LT 10]DO1
G01 X#24
END1

(RIGHT)
#31=0
WHILE[#31 LT 10]DO1
G01 X#24
#31=#31+1
END1

When you step to an end position, clamp the last pass so you do not skip it or overshoot it, as in the rectangular pocket example. Catch loop errors in the simulator with single block: watch the counter, and compare the toolpath with the size you wanted. If the same block repeats and the counter does not change, reset there, not on the machine.

7. Mapping G65 argument letters to the wrong variables

Each letter fills a fixed local variable. X is #24, not #1. I is #4, D is #7, R is #18 and F is #9. P is the program number and L is the repeat count; they are not data arguments. If you read the wrong number, the macro can move to a vacant value, to argument A, or to a leftover local.

(WRONG - #1 IS A, #9 IS F, NOT I)
G65 P8011 X50. Y25. Z-8. I80. D12. F200.
G00 X#1 Y#2
#31=#9

(RIGHT)
G65 P8011 X50. Y25. Z-8. I80. D12. F200.
G00 X#24 Y#25
#31=#4

The usual letter map is 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 and Z=#26. Catch a mapping error by opening the variable page in the simulator after the call and confirming those numbers hold the values you passed.

8. Cancelling a tool length offset and not restoring it

If a macro cancels tool length with G49, or moves in Z after that cancel, the next motion can be in a different Z than the main program expects. The tool may already be near the part. Leave G43 and the same H active unless you have a clear reason to cancel. If you must cancel, get to a safe Z first, and let the caller apply G43 again before any cutting move.

(WRONG - CANCELS TOOL LENGTH BEFORE RETURNING)
G00 Z50.
G49
M99

(RIGHT - LEAVE G43 ACTIVE)
G00 Z50.
M99

Catch it in the simulator by watching Machine Z and the tool length offset on the moves after the macro returns. If Z drops or jumps, the offset was cancelled or changed.

9. Accepting bad inputs without a #3000 alarm

A GOTO to M99 hides a bad input. The macro just returns, and the main program continues as if the call worked. #3000 raises an alarm and stops the program, with a short message you can read. Check that required arguments were passed, then check that the values make sense: a milling depth should be negative, a tool diameter should be greater than zero, and a stepover should be smaller than the tool.

(WRONG - BAD INPUT RETURNS SILENTLY)
IF[#26 EQ #0]GOTO900
...
N900
M99

(RIGHT)
IF[#26 EQ #0]GOTO900
IF[#26 GE 0]GOTO900
IF[#7 LE 0]GOTO900
...
N900
#3000=101(BAD MACRO INPUT)

Catch it by forcing a bad call in the simulator — omit Z, pass a positive depth, pass a zero tool diameter — and confirm you get the alarm instead of a path.

10. Division by zero, FIX, ROUND and system variables

A tool diameter or stepover of zero will fault a division. FIX truncates toward zero, ROUND goes to the nearest integer, and FUP rounds away from zero. The wrong one changes how many passes you take: FIX can leave leftover stock, and an extra unclamped pass can overshoot the edge. System variables are a separate trap. Addresses in the #2000 and #5200 ranges are tool offsets and work offsets on many FANUC controls. They are not scratch variables. A write there can shift an offset table and move the next tool to the wrong place.

(WRONG)
#10=#4/#7
#31=FIX[#4/#23]
#2001=0

(RIGHT - CHECK THE DIVISOR, CLAMP THE STEP, USE #100 AS SCRATCH)
IF[#7 EQ #0]GOTO900
IF[#7 LE 0]GOTO900
IF[#23 EQ #0]GOTO900
#10=#4/#7
#100=0
#31=0
WHILE[#31 LT #4]DO1
#31=#31+#23
IF[#31 LE #4]GOTO10
#31=#4
N10
END1

Use local variables or #100 to #199 for scratch, and treat system variables as read-only unless writing to them is the purpose of the macro and you have tested that write. Catch a pass-count error on the 3D toolpath: leftover stock or a path past the edge means the loop maths, not the cutter, needs to change first.

How to catch them before the machine

Put the checks in the macro first. Test for vacant arguments with EQ #0, reject values that cannot be right, and stop on a #3000 alarm. Then run the caller and the macro in a MacroMill simulator. Use single block so you can see each assignment, each test and each move. Watch the variable page as the loops count, and check the 2D and 3D toolpath graphs against the size you had in mind.

Change one input at a time — omit an argument, flip the sign of Z, halve the tool diameter, leave a #100 value from a previous run — and confirm the macro either alarms or still produces a sensible path. That is the same habit described in Practise FANUC G-code on your PC first, applied here to macro logic.

The FANUC VMC Advanced Control Suite is the milling simulator with a FANUC 0i-MF Plus style control, and it is a solid place to practise this kind of check. For turning macros, use the FANUC 0i-TF Plus lathe simulator. The A-axis VMC simulator is a separate product for 4th-axis training, and VMC Pro is a separate product that adds a probing suite. Do not treat one as a substitute for another.

Yes, you can run it on your machine

Yes, you can run a macro you tested in a MacroMill simulator on a real CNC machine. Save or export the programs from the simulator, load them onto your FANUC control the way you normally would, and prove them out with single block, reduced rapids and a dry run before you cut.

The simulator is for training and simulation. It does not replace a check of your own tooling, offsets, clearances, spindle speeds and feeds, and it does not replace the Custom Macro B manual for your control. Addresses and features can vary between FANUC series, so confirm the program on your own machine before you cut metal.

How else MacroMill can help

If you already have a CAM program with a lot of repeated motion, MacroFusion is CNC macro automation software that helps turn suitable repetitive CAM-generated G-code into compact, variable-driven macro logic. It does not replace CAM, it does not convert every program, and it is not a machine simulator. Review the result, then test it and prove it out in the same way as any other macro.

For a structured path from these checks into fuller cycles and family-of-parts work, use CNC Automation Pro 2026. It is MacroMill’s training platform for CNC macro programming, with structured lessons, pre-written macros, video tutorials and a certification pathway. It starts with the fundamentals and builds toward reusable macro logic. MacroFusion is a separate product and is not included in CNC Automation Pro.

For more on what macros are for, see What problems do CNC macros solve?, Unlock CNC macros productivity on the shop floor, From hard-coded G-code to a parametric program, G-code is not a programming language, Why CNC macro programming is a rare skill, and The black art of CNC macro programming, and what it can do for your career. For reference material, start with the free CNC macro resources page. When you want complete programs to study, open the CNC macro program library.

You can find the FANUC VMC Advanced Control Suite on macromillcnc.com. For tips and updates, join the MacroMill WhatsApp group: chat.whatsapp.com/Htae97asBiD14QiwMXjGJA.

The software is for training and simulation only. Yes, programs and macros you write and test in a MacroMill simulator can be saved or exported and run on a real CNC machine. As with any new program, prove it out first with single block, reduced rapids and a dry run before you cut. The code in this post is for learning and simulation. Addresses, tool offsets, clearances, spindle speeds and feeds must be confirmed against your machine, your tooling and your control’s Custom Macro B manual.

MacroMill

Get free CNC macro tips & simulator updates

New tutorials and MacroMill simulator deals, straight to your inbox.

We don’t spam! Read our privacy policy for more info.

Responses

  1. […] That is also why the work is not trapped in the software. Save or export the program from the MacroMill simulator, load it on your FANUC control the way you normally would, then prove it out before you cut. For a worked path from writing a macro to that hand-off, see Write a FANUC macro, test it in MacroMill, then run it on your machine. For the slips that most often show up at the control, see common FANUC macro mistakes that crash machines. […]

  2. […] a centre, and a write to #5221. For the macro slips that most often show up at the control, see common FANUC macro mistakes that crash machines. For a wider path from writing a macro to running it on the machine, see Write a FANUC macro, test […]

Leave a Reply