Sinumerik 840D M-codes: reference table
Sinumerik 840D and 840D sl M functions: the predefined M codes, spindle numbers as address extension, block rules, output timing and machine-builder M functions.
M functions are auxiliary functions. The NC passes them to the PLC, and the PLC program switches the machine function. On a Sinumerik control only a small set of M functions is fixed by the control itself. All other numbers are free for the machine builder.
Coolant, clamping, doors, chip conveyor and similar functions are defined by the machine builder. The same number can switch different functions on two machines. When in doubt, the documentation of your machine applies.
Predefined M functions
| Code | Function |
|---|---|
| M0 | Program stop |
| M1 | Conditional stop, only with the optional stop switched on |
| M2 | End of main program, same effect as M30 |
| M3 | Spindle on, clockwise |
| M4 | Spindle on, counterclockwise |
| M5 | Spindle stop |
| M6 | Tool change (delivery setting, can be configured differently) |
| M17 | End of subprogram |
| M19 | Spindle positioning |
| M30 | End of main program, same effect as M2 |
| M40 | Gear stage selected automatically |
| M41 | Gear stage 1 |
| M42 | Gear stage 2 |
| M43 | Gear stage 3 |
| M44 | Gear stage 4 |
| M45 | Gear stage 5 |
| M70 | Spindle switched to axis mode |
Syntax and spindle number
M<value>
M<spindle number>=<value>M3, M4, M5, M19 and M70 accept the spindle number as address extension. Without a spindle number, the function acts on the master spindle. The same applies to the speed address S.
M3 S2000 (Master spindle clockwise, 2000 rpm)
M2=4 S2=800 (Spindle 2 counterclockwise, 800 rpm)
M2=5 (Spindle 2 stop)M2=5 stops spindle 2. M2 without an equals sign is the end of program. M0, M1, M2, M17 and M30 never take an address extension.
M19 turns the spindle to a position stored in the setting data. A programmed angle is set with SPOS, for example SPOS=90.
Rules in the block
Up to five M functions can share a block. The total number of auxiliary function outputs (M, S, H, T, D, F) per block is limited to ten.
M0, M1, M2, M17 and M30 are always output after the axis motion of the block. For all other M functions, the machine builder sets in machine data whether they are output before, during or after the motion. On many machines, M3 in a block with an axis move starts the spindle before the axes move.
An M function that is output before or after the motion interrupts continuous-path mode (G64, G641 and so on). The control then makes an exact stop at the block transition. Waiting for the PLC to acknowledge an M function can also slow down short blocks.
M=QU(
G64 G1 X50 Y20 F2000
X80 Y40 M=QU(8) (Coolant on as high-speed output, no stop at the corner)Program end and subprograms
M2, M17 and M30 all end a program. When a main program is called from another program, M2 and M30 act like M17 and return to the caller. In the other direction, M17 ends a main program in the same way as M30.
The keyword RET also ends a subprogram. In ISO dialect mode (G291), subprograms are called with M98 and ended with M99, as on Fanuc controls.
M functions defined by the machine builder
Numbers outside the predefined set are free. Their meaning comes from the PLC program. The following assignments are common, but no rule.
| Code | Usual function |
|---|---|
| M7 | Second coolant (mist or through-tool) |
| M8 | Coolant on |
| M9 | Coolant off |
Example
G17 G90 G54 G71
T="DRILL_8" M6 (Tool change with tool name)
D1
S2400 M3 F180 (Spindle clockwise, feed per minute)
M8
G0 X30 Y20 Z5
G1 Z-12
G0 Z50
M9
M5
M30