M-Codes


Home
Company Profile
Resources
Contact Us

Warning and Liability Disclaimer
The information on this and subsequent pages is intended to supplement and reinforce the knowledge of competent machinists and technicians. The authors of this website are in no way lialble for damage or injury resulting from the improper use of the  instructions contained herein.

In the programming language of CNC controllers the M-codes control various miscellaneous functions. Although these can vary widely depending on the type of machine as well as the machine builder there are some basic codes which are common to virtually all machines. These are listed here.

M00 - Program Stop. All movement is stopped. Any device such as the coolant pump , etc that has been started by the program is stopped. Program execution can be resumed by pressing the cycle start pushbutton.

M01 - Conditional Program Stop. Same as M00 except that the m-code is only executed if another condition has been met by the operator. In most cases this condition is manual activation of a maintained push button or toggle switch.  This switch is typically labeled OPTIONAL STOP. If this condition is not met M01 will be read but will have no effect.

M02 - End Of Program. The machining operation is stopped but the program is not rewound or reset.

M03 - Spindle Rotation CW. The spindle will be started and will run in the clockwise direction. The RPM at which the spindle rotates is controlled the speed command (S-Code). If no S-Code is specified with the M03 the spindle runs at the last commanded speed. If the S-Code has been reset, by cycling the NC power, etc the spindle will run in the clockwise direction at 0 RPM (no spindle motion).

M04 - Spindle Rotation CCW. Same as M03 but spindle direction is counter-clockwise.

M05 - Spindle Rotation Stop

M06 - Tool Change Cycle. This command is normally used to start the automatic tool change cycle. When used on a machining center M06 is primarily used to begin execution of a separate program known as a tool change macro. This macro program contains all of the necessary commands (G-codes, M-codes, etc) to remove the current tool from the spindle, place the next tool in the spindle and re-start the main program at the block immediately following the M06 command line. This function can also be carried out completely within the PLC (ladder program) without the need for a macro program. Since a tool change cycle for a  turning center involves simply rotating the turret the tool change is almost always performed as a function of the PLC without a macro program.  

M07 - The function of this m-code will vary by machine. It may be used to turn on either a mist coolant or air/oil mist system. It is also commonly used to turn on a CTS (gun drill) motor.

M08 - Almost always turns on the flood coolant system regardless of machine type.

M09 - Coolant Off. Turns off any coolant system that has been activated my M07 or M08. 

M10 - Clamp. The most common function for M10 is to clamp a workholding device. This device may be the fourth axis (rotary axis) of a machining center, a pallet or even a group of fixtures attached to a table. In the case of a horizontal machining center M10 sometimes will clamp the table itself.

M11 - Unclamp. Same as M10 description but is used to unclamp.

M19 - Spindle Orient. Rotates the spindle to a pre-determined position and locks it in place.  This position is typically defined by parameter.  Spindle orientation can be released either by M05 or by pressing the Reset button depending on  how the parameters are set.

M30 - Program Reset and Rewind. The M30 command is placed at the end of the program. When read the program is reset to the first command line. All machine functions are ceased and the machine is readied to execute the program again. Program execution can be commenced by pressing the cycle start pushbutton. It is possible to configure the parameters such that M30 cause the program to rewind but not reset.

M98 - Sub Program Call. M98 is used to call up and execute another program within the main program. The number of the subprogram is specified in the M98 command line (i.e. M98 P0001). Upon completion of the sub program the main program resumes execution at the command line following the M98 command.

M99 - Return To Main Program. M99 is used to return to the main program once execution of the sub program has been completed. M99 is also use to loop a program. Placing M99 at the end of a program (other than a sub program) will cause the program to automatically reset and execute continually.