Skip to main content

Mach4 Advanced M-code Reference

Chapter 1 : Advanced Macros

M Code Descriptions

M200 – M219: Control Default Outputs:

Turn outputs 0-9 on/off.

Parameters:

            --none

Example:

M200 (Output 0 On)

M201 (Output 0 Off)

M202 (Output 1 On)

...

M219 (Output 9 Off)

 

M220 – Turn on Output:

General macro for turning on any outputs from parameters passed into the Mcode

This allows you to control any of the signals in Mach.

Parameters:

--A - Any Output Signal

--S - Output Signal Starting from Output#0

--D - Delay (Optional) ms

Example:

M220 S2 D2000 (will turn on output signal #2 then wait 2000 ms)

M220 A2 (will turn on output signal #2 “X- lim”)

 

M221 – Turn off Output:

General macro for turning off any outputs from parameters passed into the Mcode

This allows you to control any of the signals in Mach.

Parameters:

--A - Any Output Signal

--S - Output Signal Starting from Output#0

--D - Delay (Optional) ms

Example:

M221 S2 D2000 (will turn off output signal #2 then wait 2000 ms)

M221 A2 (will turn off output signal #2 “X- lim”)

 

M222 – Wait for input:

This can be used to wait for clamps, doors closed or coolant up to pressure

Parameters:

--A - Any Input Signal (This is typically not used and the "S" value is used instead. The "A" is based on the inputs listed in the configuration, starting at the beginning and counting all the way through.)

--S - Input Signal Starting from Input#0

--T - Time-out (Optional) seconds

--I - Invert Logic (Optional) (High Active = 0, Low Active = 1)

Example:

M222 S2 T5 (will wait up to 5 sec for Input#2 to go high.)

M222 A2 I1 (will wait indefinitely for Input Signal #2 to go low. Note, this is not Input#2, but the second input listed in the list of inputs.)

 

M223 – Pass Input to pound var:

This can be used along with macro B commands (macro B commands require industrial license to run) to set up logical switch cases or programed safety based on an input on the machine. i.e for running lights out you could have the first line of gcode check for a material verification input and do a M00 stop and wait for an operator if no material present.

Parameters:

            --A - Any Input Signal

            --S - Input Signal Starting from Input#0

            --V - Mach Memory Address

            --I - Invert Logic (Optional)

Example:

M223 S2 V500 (Will set #500 to the state of input#2)

IF [#500 EQ 1] GOTO 5 (check for material)

M00 (Stop)

N5

(Run Job)

M30

%

 

M224 – Pass Output to pound var:

Parameters:

--A - Any Input Signal

--S - InputOutput Signal Starting from Input#0Output#0

--V - Mach Memory Address

--I - Invert Logic (Optional)

Example:

M223 S2 V500 (Will set #500 to the state of output signal #2)

M223 A2 V500 (Will set #500 to the inverse of the state of output #2 “x-“)

 

M225 – Call PLC Sequence:

By calling M225 in a gcode file you can start a block of user ladder logic in your PLC system. This is used for automation and custom setups

Parameters:

--D = Data to send

--V = Data index

--L = Debugging (logging) default 0

--S = Seq number

--M = Device number (modbus) default 0

Example:

M225 S5 (Start Seq 5 in PLC)

 

M226 – Wait for PLC Sequence:

Used in conjunction with M225 this allows you to wait for the user ladder logic to signal completion.

Parameters:

--L = Debugging (logging) default 0

--S = Seq number

--M = Device number (modbus) default 0

Example:

M226 S5 (Waits for Seq 5 in PLC to finish)

 

M228 – GoTo Park Positions:

Easy setup to command the machine to user defined positions. This allows you to use the same code in all your files for tool setter position and then change that position once in one place when you need to move your tool setter.

Parameters:

--P - Position

Example:

M228 P1 (GoTo Tool Change position)

 

P1 - Tool Change

P2 - Tool Setter

P3 - Part Zero

P4 - Machine Zero

P5 - Park Position

P6–P14 -Park Position 1- 9

 

M230 – Map motor to axis:

            --A - AxisID

            --M - MotorID

 

M231 – Un-Map motor from axis:

            --A - AxisID

            --M – MotorID

 

M232 – Save Delete Restore motor mapping

            --S1 Saves the current mapping config

            --R1 Restore the last saved motor mapping

            --D1 Delete current motor mapping.

 

M900 - Auto Tool Setter

            --Examples

                       --M900 (Data: "1, 5")

                       --M900 (Data: "2-5")

                       --M900 (Data: "6")

 

Custom M Codes:

Every machine is a little different and has different functions and options. Custom M codes allow the user to create simple programming calls for complex processes, activating or deactivating outputs, reading inputs, performing math, or whatever else the user and machine could require. These M codes are programmed in Lua and placed in the macros folder under each profile. Every profile can have its own unique set of M codes.  The file name must be the macro to be called.