In CNC machining, setting the Z-axis zero point with precision is crucial—it ensures accurate depths, prevents tool crashes, and saves time and material. For Mach3 users with a probing setup, automating this process can significantly improve consistency and efficiency. In this blog post, we’ll introduce a custom Mach3 macro, M881.m1s, designed to automate Z-axis zeroing using a 19mm probe plate. This macro supports variable workpiece thicknesses and offers reliability even when IsActive(PROBE) isn’t behaving as expected.


The Z Touch-Off Problem

Z-axis zeroing is often done at the top of the workpiece (for milling) or the machine table. While a Mach3-compatible probe can automate this, common issues include:

  • Fixed probe plate thickness vs. variable workpiece thicknesses
  • Unreliable trigger detection with IsActive(PROBE)
  • Need for manual recalculations when workpiece dimensions change

The Solution: A Custom Macro

The M881.m1s macro solves these problems by:

  • Using a fixed 19mm probe plate on the machine table
  • Automatically compensating for the workpiece thickness
  • Accepting thickness as a command parameter (e.g., M881 3 for 3mm) or prompting the user
  • Avoiding reliance on IsActive(PROBE) for the probe move, while retaining it for safety checks

How It Works

This macro streamlines the Z-axis probing process with these steps:

  1. Input: Accepts or prompts for workpiece thickness.
  2. Probe Check: Verifies the probe isn’t already triggered.
  3. Probing Move: Executes a G31 Z move down to the probe plate.
  4. Validation: Confirms the probe triggered within a safe distance (<30mm).
  5. DRO Setting: Adjusts the Z-axis DRO to compensate for the plate and workpiece thickness.
  6. Retract & Complete: Moves up to a safe height and displays a success message.

Key Features

  • Flexible: Works with any workpiece thickness up to the probe plate height.
  • Reliable: Avoids probe detection issues by using G31’s built-in behavior.
  • Safe: Includes fail-safes for pre-triggered probes and excessive Z movement.
  • User-Friendly: Offers clear messages and prompts for easy interaction.

Macro Assumptions

  • Probe is on Port 3, Pin 4, connected to Mach3’s Digitize input
  • Probe plate is 19mm thick
  • Z zero is set at the top of the workpiece
  • Tool is conductive and part of the probe circuit

The Macro Code

' M881.m1s - Z Touch-Off Macro (19mm Probe, Variable Workpiece Thickness)
Dim ZClearance, ProbeFeed, PlateThickness, WorkpieceThickness, ZPos

ZClearance = 5.0
ProbeFeed = 50.0
PlateThickness = 19.0

' Get workpiece thickness from parameter (e.g., M881 3)
WorkpieceThickness = GetParam(1)

If WorkpieceThickness <= 0 Or WorkpieceThickness >= PlateThickness Then
    WorkpieceThickness = Question("Enter workpiece thickness (mm):")
    If WorkpieceThickness <= 0 Or WorkpieceThickness >= PlateThickness Then
        MsgBox("ERROR: Invalid workpiece thickness. Must be > 0 and < 19mm.")
        End
    End If
End If

If IsActive(PROBE) Then
    MsgBox("ERROR: Probe already active. Check wiring.")
    End
End If

Code "G91"
Code "G31 Z-50 F" & ProbeFeed
While IsMoving()
    Sleep(50)
Wend

ZPos = GetDro(2)
If Abs(ZPos) > 30 Then
    MsgBox("ERROR: Probe did not trigger within 30mm.")
    Code "G0 Z" & ZClearance
    Code "G90"
    End
End If

Call SetDro(2, PlateThickness - WorkpieceThickness)
Code "G0 Z" & ZClearance
While IsMoving()
    Sleep(50)
Wend

Code "G90"
MsgBox("Z-axis zeroed at top of " & WorkpieceThickness & "mm workpiece using 19mm probe.")

Setup Instructions

1. Hardware Setup

  • Probe Input: Connect probe to Port 3, Pin 4. Use Normally Open (NO) configuration, Active Low unchecked.
  • Probe Plate: Use a flat, 19mm thick conductive plate (aluminum or steel).
  • Tool: Ensure the tool is part of the probe circuit and conductive.

2. Mach3 Configuration

  • Input Settings:
    • Config > Ports and Pins > Input Signals
    • Enable Digitize, Port 3, Pin 4, Active Low unchecked
  • Diagnostics: Test probe behavior using the LED in Diagnostics tab
  • Debounce: Set Debounce Interval to 200 (20ms) in General Config

3. Installing the Macro

  • Save the macro as M881.m1s in your Mach3 profile’s macro folder (e.g., Mach3/macros/YourProfile/)
  • Restart Mach3 to ensure it loads
  • Run it by typing M881 (with optional thickness parameter) in the MDI tab

Testing the Macro

Test 1: With Parameter

Command: M881 3
Expected Result:

  • Z probes down, stops on plate
  • Sets Z DRO to 16mm (19 – 3)
  • Retracts to Z=21mm (clearance)
  • Message confirms Z zeroing

Test 2: Without Parameter

Command: M881
Expected Result:

  • Prompts for thickness
  • Proceeds with same behavior as Test 1

Final Thoughts

If you’re a Mach3 user looking to make Z-axis touch-off faster, more accurate, and more reliable, this macro is for you. It simplifies setup, supports varied materials, and avoids common probe detection issues. Best of all, it saves time—and expensive mistakes—by ensuring Z=0 is exactly where you need it.

If your probe setup differs (e.g., Z zero at the table, probe plate on the workpiece), the macro can be adjusted to fit. Reach out in the comments or on forums for help customizing it for your rig.

Happy machining!

Similar Posts

Leave a Reply