2012-08-04 20:26:10 (CET)

Input M Codes

M codes of the RS274/NGC language are shown in Table 3-6  


Table 3-6 M Codes 


M Code
















































program stop


optional program stop


program end


turn spindle clockwise


turn spindle counterclockwise


stop spindle turning


tool change


mist coolant on


flood coolant on


mist and flood coolant off


program end, spindle and coolants off and rewind.

enable speed and feed overrides


disable speed and feed overrides


program stop, use this with nesting in stead of M60, so that the spindle/coolants remain on during transition from one to the next run.


set general purpose output for Advantronix USB IO card (support is depricated)

clear general purpose output for Advantronix USB IO card (support is depricated)

read general purpose input for Advantronix USB IO card (support is depricated)


set general purpose output for CPU5B

clear general purpose output for CPU5B

read general purpose input for CPU5B


Standard spindle


Alternate spindle 1


Alternate spindle 2



Program Stopping and Ending - M0, M1, M2, M30, M60


To stop a running program temporarily (regardless of the setting of the optional stop switch), program M0 or M1. If a program is stopped by an M0, M1, or M60, pressing the cycle start button will restart the program at the following line, so the program will continue.

To end a program, program M2.

program M30 for next effects:

  • Selected plane is set to CANON_PLANE_XY (like G17).

  • Distance mode is set to MODE_ABSOLUTE (like G90).

  • Feed rate mode is set to UNITS_PER_MINUTE (like G94).

  • Feed and speed overrides are set to ON (like M48).

  • Cutter compensation is turned off (like G40).

  • The spindle is stopped (like M5).

  • The current motion mode is set to G_1 (like G1).

  • Coolant is turned off (like M9).

  • Note that the coordinate system are no longer reset, I modified this behavior because I have broken a lot of bits due to this so I modified it.


No more lines of code in an RS274/NGC file will be executed after the M2 or M30 command is executed. Pressing cycle start will start the program back at the beginning of the file.

Spindle Control - M3, M4, M5

To start the spindle turning clockwise at the currently programmed speed, program M3.

To start the spindle turning counterclockwise at the currently programmed speed, program M4.

To stop the spindle from turning, program M5.

It is OK to use M3 or M4 if the spindle speed is set to zero. If this is done (or if the speed override switch is enabled and set to zero), the spindle will not start turning. If, later, the spindle speed is set above zero (or the override switch is turned up), the spindle will start turning. It is OK to use M3 or M4 when the spindle is already turning or to use M5 when the spindle is already stopped.



Spindle Selection - M90, M91, M92

If there are more than one spindle in your machine, you can select the spindle you want

  • M90 standard spindle

  • M91 alternate spindle 1

  • M92 alternate spindle 2


Each spindle is connected to different set of outputs and has different parameters.

Alternate spindle 1 and 2 may have defined offsets for x,y,z.

Because this option is rarely used by customers, you have to perform the settings yourself by editing the cnc.ini file.


There are 3 sets of parameters for each spindle configuration. For the 2nd (SPINDLE_1) and 3rd (SPINDLE_2) pindle configuration you can set the axis offsets with respect to the 1nd spindle (SPINDLE_0).



Tool Change - M6

To change a tool in the spindle from the tool currently in the spindle to the tool most

recently selected (using a T word - see Section 3.7.3), program M6. When the tool change is complete:

  • The spindle will be stopped.

  • The tool that was selected (by a T word on the same line or on any line after the previous tool change) will be in the spindle. The T number is an integer giving the changer slot of the tool (not its id).

  • If the selected tool was not in the spindle before the tool change, the tool that was in the spindle (if there was one) will be in its changer slot.

  • The coordinate axes will be stopped in the same absolute position they were in before the tool change (but the spindle may be re-oriented).

  • No other changes will be made. For example, coolant will continue to flow during the tool change unless it has been turned off by an M9.


The tool change may include axis motion while it is in progress. It is OK (but not useful) to program a change to the tool already in the spindle. It is OK if there is no tool in the selected slot; in that case, the spindle will be empty after the tool change. If slot zero was last selected, there will definitely be no tool in the spindle after a tool change.


The tool change command will call the change_tool subroutine inside macro.cnc.

You can adapt the behavior for your own needs in this function e.g:

  • Perform automatic tool-length measurement

  • Perform tool change with an automatic tool changer.


For a (non functional) example of how to implement automatic tool change for a 16-tool changer. It checks whether current tool is already in the spindle. It check that the tool number is in range of 1-4. Then it first drops current tool and picks the new tool:



Coolant Control - M7, M8, M9

To turn mist coolant on, program M7. To turn flood coolant on, program M8. To turn all coolant off, program M9. It is always OK to use any of these commands, regardless of what coolant is on or off.



Override Control - M48 and M49

To enable the speed and feed override switches, program M48. To disable both

switches, program M49. See Section 2.2.1 for more details. It is OK to enable or disable the switches when they are already enabled or disabled.



Spindle select - M90..M92

M90 select spindle configuration 0.

M91 select spindle configuration 1.

M92 select spindle configuration 2.

Each spindle can have different control outputs.

Spindle 1,2 can have coordinate offsets to spindle 0.

Contact Eding CNC id you are planning to use different spindles selection.



Standard CNC IO - M3..M9, M80..M87


To control the outputs, these functions have been added besides the standard M-Functions.


Standard, according to [NIST]

M3 PWM according S value, TOOLDIR = on

M4 PWM according S value, TOOLDIR = off

M5 PWM off, TOOLDIR off.

M7 Mist on

M8 Flood on

M9 Mist/Flood off


Additional, to support the features of the USBCNC CPU’s

M80 drive enable on

M81 drive enable off

M82/M61 Aux1 on

M83/M62 Aux1 off



M86 PWM according S value (s/s-max from setup * 100%)

M87 PWM off



General purpose IO of CPU5B - M54, M55 and M56


M54 Px

Set output x.


M54 Ex Qy

Set PWM output x to % value y (0


M55 Px

Clear output x.


M56 Px

Read input x.


M56 Px Ly Qx.xx

Read digital input and specify wait mode

Px: x is input number

L0: do not wait

L1: Wait for High

L2: Wait for Low

Qx: x is timeout


M56 Ex Ly Qx.xx


Read analogue input and specify wait mode

Ex: x is input number

L0: do not wait

L1: Wait for High

L2: Wait for Low

Qx: x is timeout


For all M56 variants, the input value is stored into #5399


For the general purpose I/O of CPU5, use M54, M55, M56 in stead of M64, M65, M66.