M-codes

What are M-codes?

M-codes, also known as machine control codes, are commands used in CNC programming that control the auxiliary and switching functions of a machine. Unlike G-codes, which define tool paths and movements, M-codes focus on managing different machine operations such as cooling, tool changes, and spindle rotation. M-codes are essential in both turning and milling operations, but their specifics may vary between machines from different manufacturers, which is why it’s important to consult the machine’s own manual for details.

Common M-codes and Their Functions

M-codes are widely used across various CNC machines, but below is a list of commonly used codes and their basic functions:

  • M00 – Program Stop: Pauses the program until the user gives the command to continue.
  • M01 – Optional Stop: Works like M00, but is optional and depends on the machine settings.
  • M02 – Program End: Ends the program execution and returns to the beginning.
  • M03 – Spindle On (Clockwise): Starts spindle rotation clockwise.
  • M04 – Spindle On (Counterclockwise): Starts spindle rotation counterclockwise.
  • M05 – Spindle Stop: Stops spindle rotation.
  • M06 – Tool Change: Executes a tool change operation.
  • M07 – Mist Coolant On: Activates mist cooling.
  • M08 – Flood Coolant On: Turns on flood coolant.
  • M09 – Coolant Off: Turns off all cooling systems.
  • M30 – Program End and Reset: Ends the program and resets it for the next execution.
  • M98 – Subprogram Call: Calls a subprogram attached to the main program.
  • M99 – Subprogram End: Ends the subprogram and returns to the main program.

Machine-Specific Differences in M-codes

Unlike G-codes, which are generally standardized, M-codes can vary significantly between different CNC machines and manufacturers. The machine builder or accessory supplier may implement their own user-defined M-codes, which is why it is absolutely essential to check the operating manual for each machine to verify the available M-codes and their functions.

Using M-codes in CNC Programming

M-codes usually follow the format Mxx, where "xx" is a two-digit number (e.g., M03). In CNC programming, typically only one M-code is allowed per line, and it is activated at the end of that line’s execution. Since M-codes do not directly control the movement of cutting axes, they are used to manage various auxiliary systems and machine functions, making them an integral part of CNC programming.

Summary

M-codes are machine control commands in CNC programming that manage the machine’s auxiliary and switching functions, such as spindle rotation, cooling, and tool changes. Unlike G-codes, M-codes can differ significantly between machines, so it is important to familiarize yourself with machine-specific instructions. Using the right M-code ensures the program runs smoothly and safely, which is essential for machining and machine tool operation.