CNC Tool Change Crashes: Why M06 Is the Riskiest Moment in Your Program

In the CAM simulation, the tool change is instant.

One tool disappears. Another appears. The program continues.

On the machine, the tool change is a sequence of seven or eight distinct mechanical events, each one dependent on the previous, each one capable of producing a crash if the program, the setup, or the machine state is wrong at that specific moment. The CAM simulation shows none of this sequence. It shows the outcome — the new tool in position — and assumes everything in between went correctly.

This assumption is wrong often enough that tool change crashes are one of the most frequent and most expensive events in CNC production. They are frequent because the conditions that cause them are invisible in the tools most programmers use to verify their work. They are expensive because the spindle is involved — and spindle damage is the most costly mechanical consequence of a CNC crash, in both repair cost and lead time.

This article explains exactly what happens during a tool change, where each phase can fail, and why simulation is the only verification method that shows the full sequence before the machine executes it.


What Actually Happens During M06

When the controller encounters M06, it does not simply swap tools. It executes a machine builder-defined macro — a sequence of coordinated axis moves, pneumatic or hydraulic actuations, and spindle functions that together constitute the automatic tool change. The exact sequence varies by machine, but the structure is consistent:

Phase 1 — Safe Z retract. The Z axis moves to the tool change position. On most machines this is machine Z home (Z0 in machine coordinates), reached either by G91 G28 Z0 in the program or by a move generated internally by the M06 macro. The tool must clear the part, all fixtures, all clamps, and any other obstruction in the work envelope before the ATC arm can reach the spindle.

Phase 2 — Spindle orientation (M19). The spindle rotates to a defined angular position — the orientation required for the drive key in the spindle taper to align with the slot in the tool holder. On machines with a fixed key, the spindle must reach this exact orientation before the ATC arm engages. On some machines, M19 is called explicitly in the program. On others, it is embedded in the M06 macro.

Phase 3 — ATC arm engagement. The tool changer arm moves from its home position to the spindle and simultaneously picks the next tool from the magazine. The arm grips both the current tool in the spindle and the incoming tool in the magazine.

Phase 4 — Tool unclamp and extraction. The spindle drawbar releases the current tool. The ATC arm extracts the tool from the spindle taper by moving downward (on a vertical machining center) or in the appropriate direction for the machine's ATC geometry.

Phase 5 — Arm rotation. The ATC arm rotates — typically 180 degrees — to position the incoming tool below the spindle and the outgoing tool below the magazine pocket.

Phase 6 — Tool insertion and clamp. The ATC arm inserts the incoming tool into the spindle taper. The drawbar clamps the tool. A clamping confirmation signal is sent to the controller.

Phase 7 — Arm retract. The ATC arm returns to its home position, clear of the spindle and magazine.

Phase 8 — First move of the new tool. The program continues with the first G-code block after M06 — typically a G43 activation and a move to the first position of the new operation.

A crash can occur at Phase 1 (insufficient retract), Phase 2 (spindle orientation failure), Phase 5 (arm rotation with insufficient clearance), Phase 8 (first move without active compensation), or in the transition between any two phases due to incorrect program structure. The CAM simulation skips Phases 1 through 7 entirely and shows only the result of Phase 8 — the new tool, in position, cutting correctly.


The Four Failure Modes That Actually Crash Machines at Tool Change

1. Insufficient Safe Z Before M06

The single most common tool change crash. The program calls M06 while the tool is still within the work envelope — too close to the part, the fixture, or a clamp to allow the ATC arm to engage the spindle without collision.

This happens more often than it should because "safe Z" is not an absolute value. It is a relationship between the Z position of the tool, the height of everything in the machine envelope, and the geometry of the ATC arm as it moves.

G00 Z100 is not always safe. In work coordinates (G54), Z100 means 100mm above the work zero. If the work zero is set at the top of a tall fixture, Z100 in G54 may be inside the fixture — or even below the machine table, if the work zero was set incorrectly. G53 Z0 (machine coordinate retract to Z home) is the only retract that is always machine-safe regardless of the active work offset, because machine coordinates are fixed to the machine structure.

The post-processor's safe height assumption may not match your setup. CAM systems configure a clearance height for tool changes — a Z value that the post-processor outputs before M06. This value is set in the CAM job setup, typically in work coordinates, and is constant for all tool changes in the program. If your setup includes a tall fixture, a tombstone, a vise with extended jaws, or any workholding that reaches above the configured clearance height, the post-generated retract is insufficient and the M06 call executes with the tool too close to an obstruction.

The insufficient retract is invisible in the CAM simulation because the CAM simulation does not model the ATC arm geometry or the actual travel path of the Z axis to the tool change position. It shows the tool at the machining position before M06 and at the new machining position after M06. The retract move and the tool change mechanics are invisible.

In an offline G-code simulation with the full machine model — including the fixture and workholding geometry — the retract move is visible. A Z100 retract that leaves the tool inside a 150mm-tall vise jaw is immediately apparent as a collision before the M06 executes.

2. Spindle Orientation Failure (M19 Problems)

Spindle orientation positions the spindle at a fixed angular position before the ATC arm engages. On most modern machining centers, this is handled internally by the M06 macro — the programmer does not need to call M19 explicitly. On older machines, on machines where M19 behavior has been modified by the machine builder, or on machines where the spindle orientation is handled by a separate M-code in the program, incorrect or missing orientation causes the ATC arm to attempt engagement with a misaligned drive key.

What happens when orientation fails: The ATC arm descends to grip the tool. The drive key in the spindle is not aligned with the slot in the tool holder. The arm cannot fully seat against the tool holder flange. Depending on the machine design and the severity of the misalignment, the result ranges from an ATC alarm (the arm detects insufficient seating and stops) to mechanical damage to the tool holder, the arm, or the spindle face.

Post-processor generated M19 vs. macro-embedded M19. Some post-processors output an explicit M19 block before M06. On machines where M19 is already embedded in the M06 macro, this produces a double orientation — which is usually harmless but occasionally produces an alarm on machines that interpret the second M19 as an unexpected command. On machines where M06 does not include M19, omitting the explicit M19 call before M06 produces a tool change attempt with random spindle orientation.

Machine-specific M19 variants. Some machines use M19 for basic spindle orientation and a separate command (M19 P or M19 Rxxx) for orientation to a specific angle. A post-processor that outputs M19 without the required angle parameter on a machine that needs it will orient the spindle to a default angle that may not match the ATC arm's engagement geometry.

None of these scenarios is visible in the CAM simulation, which treats M06 as an instantaneous tool change with no mechanical preconditions.

3. Post-Processor Generated Positioning Moves After Tool Change

After M06 completes, the program must activate G43 for the new tool and move to the starting position of the next operation. The order of these events — which work offset is active, whether G43 is called before or after the first XY move, what Z position is commanded in the G43 block — determines whether the first move of the new tool is safe.

The tool change position and the first machining position are different. After M06, the machine is at the tool change position — Z home in machine coordinates, XY at whatever position the program reached before the retract. The first operation of the new tool may start at a completely different XY location. The sequence of moves from tool change position to first machining position passes through the work envelope at intermediate positions that are never explicitly shown in the CAM simulation.

Post-generated moves may pass through the fixture. A post-processor that generates a rapid XY move before the Z descent to machining height may route the tool — whose length is now different from the previous tool — through a fixture component at an intermediate position. The CAM simulation shows the endpoint of the XY move and the Z descent separately, both correct. The intermediate path through the fixture geometry is invisible.

G43 called after the first XY move. As covered in the G43 article: if the post-processor generates an XY move before the G43 activation for the new tool, that XY move executes without length compensation for the new tool. The spindle is at Z home, which is typically safe for XY motion regardless of compensation state. But if the XY move is followed by a Z descent before G43 is called, the Z descent uses the wrong reference — the gauge line rather than the tool tip — and crashes at the depth of the tool length below the intended position.

4. ATC Errors from Wrong Program Structure

Beyond the mechanical phases of the tool change itself, certain programming patterns reliably produce ATC errors or leave the machine in a state where the next tool change will fail.

Canned cycle not canceled before M06. G80 must cancel active drilling or tapping canned cycles before a tool change. If G80 is missing and M06 is called while a canned cycle is active, the controller behavior depends on the implementation — some controllers automatically cancel the cycle, others generate an alarm, others attempt to execute the tool change within the active cycle mode and produce unpredictable results.

Cutter radius compensation active at tool change. G41/G42 (cutter radius compensation) should be canceled with G40 before M06. Compensation active during a tool change confuses the compensation offset calculations for the new tool and may produce an alarm or unexpected first move.

Interrupted tool change — modal state corruption. If the program is stopped mid-tool-change — by an E-stop, a feed hold, or an operator intervention — the ATC arm may be left in an intermediate position. Restarting the program from the M06 block re-initiates the tool change from the beginning while the arm is not at home, producing a mechanical collision between the arm and the spindle or magazine. This is not a programming error in the original program, but it is a failure mode that offline simulation of the restart sequence can reveal.

T-word called at M06 instead of earlier. On machines that use a T-word to select the next tool and M06 to execute the change (the majority of machining centers), the T-word should typically be called one tool change in advance — during the previous operation — so the magazine has time to index to the next tool position while machining continues. A program that calls T and M06 in the same block, or calls T immediately before M06 with no machining operation in between, forces the magazine to index during the tool change itself, extending the tool change time and on some machines producing a timing conflict that generates an ATC alarm.


What the CAM Simulation Shows — and What It Doesn't

A CAM simulation of a tool change shows:

  • The toolpath of the last operation with the outgoing tool
  • An instantaneous transition marked as a tool change
  • The toolpath of the first operation with the incoming tool

It does not show:

  • The Z retract path to the tool change position, or whether that path clears the fixture
  • The spindle orientation sequence and whether M19 is called correctly
  • The ATC arm motion and whether the arm has clearance to reach the spindle
  • The XY repositioning moves from the tool change position to the first operation, and whether those moves pass through fixture geometry
  • The G43 activation sequence and whether it occurs before or after the first Z move
  • The state of canned cycles, cutter compensation, or other modal codes at the moment of M06

This is a complete blind spot. The most mechanically complex and mechanically dangerous phase of any CNC program is entirely invisible in the tool most programmers use to verify their work.


Verifying Tool Change Sequences with Offline Simulation

A G-code simulator that executes the posted file against a complete machine model — including the ATC geometry, the fixture and workholding, and the full program state at each block — makes the tool change sequence visible in exactly the way the CAM simulation does not.

The retract move is simulated against the actual fixture geometry. A G00 Z100 retract that leaves the tool inside a tall vise jaw appears as a collision at the actual Z position of the tool holder body relative to the jaw height — before M06 executes.

The first move of the new tool is simulated with the new tool's geometry. The incoming tool may be significantly longer or shorter than the outgoing tool. The first XY positioning move, the G43 activation sequence, and the Z descent to the first machining position are all simulated with the new tool's holder body dimensions and cutting length — showing any collision that the different tool geometry introduces.

Modal state at M06 is visible. An active canned cycle, an active cutter compensation mode, or a missing G80 before M06 is flagged in the simulation at the point where it occurs, not at the point where it causes a downstream failure.

The sequence is inspectable block by block. Because the simulation executes the actual G-code, the programmer can step through the tool change sequence block by block — retract, M06, G43, first move — and verify each step against the machine model before it runs on the machine.


Eureka 3X Pro: Tool Change Simulation with the Full Machine Model

Eureka 3X Pro simulates the complete posted G-code against a digital twin of your 3-axis CNC machine, including the workholding, tooling geometry, and machine envelope.

Every tool change in the program is simulated with the actual tool and holder dimensions for both the outgoing and incoming tool. The retract path, the transition between tool change position and the first machining position, and the G43 activation sequence are all visible in the simulation before the machine executes them.

This means:

  • An insufficient Z retract before M06 appears as a collision between the tool holder and the fixture in the simulation, at the exact block where the retract is commanded
  • A post-generated XY move that passes through fixture geometry with the new tool's longer holder body appears as a collision on the repositioning move, not on the first machining move
  • A missing G43 after tool change is visible as the wrong Z reference on the first descent — the tool tip at the depth of the gauge line rather than the programmed depth
  • A missing G80 before M06 is flagged at the M06 block as an active canned cycle modal conflict

When the simulation identifies a tool change problem, the programmer pauses, edits the NC file in the integrated editor — corrects the retract height, moves the G43 call before the first Z move, adds the missing G80 — and resumes from the same point. The corrected tool change sequence is verified in the same session.

Try Eureka 3X Pro free for 30 days — no credit card required. Start your free trial at eureka3x.com →


Frequently Asked Questions

My CAM system has a clearance height setting for tool changes. Why isn't that enough? The CAM clearance height is a fixed value in work coordinates, configured once in the job setup. It assumes that all tool changes in the program happen above the same clearance height, relative to the same work zero. If your setup includes workholding that varies in height across the machine table, or if a specific operation's work zero places the clearance height lower than the tallest fixture component, the configured clearance is insufficient for that specific tool change. Simulation shows the actual retract path against the actual fixture geometry for each tool change individually.

What is the difference between G91 G28 Z0 and G53 Z0 for tool change retract? G91 G28 Z0 commands an incremental move of zero in Z, then a return to the reference point (machine Z home) from the current position. It is a two-step sequence that moves through an intermediate point. G53 Z0 commands a direct move to machine Z home in machine coordinates, bypassing the intermediate point. For tool change retracts, G53 Z0 is generally more predictable because it moves directly to the machine reference without the incremental step. G91 G28 Z0 is correct and standard on most Fanuc machines but requires that the incremental zero move is interpreted correctly by the controller — some configurations behave differently.

How do I know if my post-processor is generating the correct tool change sequence? Post-processor tool change output can be verified by examining the NC file around each M06 block — checking for the retract command, M19 (if required by the machine), G80, G40, the G43 call for the new tool, and the first XY and Z moves after the change. The sequence should follow: retract to safe Z → cancel active cycles and compensation → M06 → G43 Hxx with Z move to safe height → XY move to first position → Z descent to machining depth. Any deviation from this sequence is a potential crash source.

My tool change works correctly on 99% of programs. Why does it fail on specific ones? Tool change failures that occur on specific programs typically indicate a fixture-height dependency (the failing program has taller workholding), a tool-length dependency (the failing program uses a longer tool that doesn't clear the fixture on the repositioning move), or a modal state dependency (the failing program leaves a specific modal code active at the tool change that others don't). Simulation of the specific failing program reveals which condition applies.

Can offline simulation catch ATC mechanical failures? Simulation catches programming errors that cause ATC failures — insufficient retract, wrong M19 call, incorrect G-code structure around M06. It does not catch mechanical failures of the ATC hardware itself — worn cam mechanisms, insufficient air pressure, damaged grippers. Mechanical ATC failures require maintenance diagnosis, not programming correction.

After a tool change crash, how do I recover safely? After any tool change crash that leaves the ATC arm in an intermediate position: do not attempt to restart the program from the M06 block. Power down the machine, clear the alarm, and step through the tool change macro manually in MDI mode — M19 for spindle orientation, then the individual ATC step commands in the sequence documented in the machine builder's maintenance manual. Attempting an automatic restart from an intermediate ATC state is one of the most reliable ways to convert a recoverable situation into spindle damage.