M Codes Introduction
Miscellaneous functions ( M Codes ) that control program processing can be used either to interrupt the processing temporarily (in the middle of a program) or permanently (at the end of a program). Several functions are available for this purpose.
M00 – Program Stop
M00 function is defined as an unconditional or compulsory program stop. Any time CNC system encounters this function during program processing, all automatic operations of the machine tool will stop:
- Motion of all axes
- Rotation of the spindle (Depends parameter settings)
- Coolant function (Depends parameter settings)
- Further program execution
Control settings will not be reset when M00-function is processed. All significant program data currently active are still retained (feedrate, coordinate setting, spindle speed, etc.). Program processing can only be resumed by activating the Cycle Start key. M00 function cancels both spindle rotation and coolant function – either one or both have to be reprogrammed in subsequent blocks.
Miscellaneous function M00 can be programmed as an individual block or in a block containing other commands, usually axis motion. If M00 is programmed together with a motion command, the motion will be completed first, then the program stop will become effective:
M00 programmed after a motion command :
N38 G00 X189.5
M00 programmed with a motion command :
N39 G00 X189.5 M00
In both cases, any motion command will be completed first, before the program stop is executed. Actual difference between the two examples is apparent only in single block processing mode (for example, during a trial cut). There will be no practical difference in auto mode of processing (Single Block switch set to OFF position).
M00 Practical Usage
Program stop function used in a program makes the CNC operator’s job much easier. It is useful for many jobs. One common use is a part inspection at the machine, while the part is still mounted. In program stop mode, the part dimensions or tool condition can be checked. Chips accumulated in a bored or drilled hole can be removed, for example, before another machining operation can start. Blind hole tapping is a good example. Program stop function is also necessary to change the current setup before the program is completed, for example, to reverse a part. Any manual tool change also requires M00 function in the program.
|Program stop function M00 is used only for a manual intervention during program processing.|
All control systems also offer an optional program stop M01, described next. The main rule of using M00 is the need of a manual intervention for every part machined. Manual tool change in a program qualifies for M00, because every part needs it. A dimensional check may not qualify, if is infrequent. In this case, M01 function will be a better choice. Although the difference between both functions is slight, the actual difference in cycle time can be significant for large number of parts.
When using M00 in a program, always inform the operator why the function has been used and what its purpose is. Make your intent known to avoid a confusion. This intent can be made available to the operator in two ways:
- In setup sheet, refer to the block number that contains miscellaneous function M00 and describe any manual operation that has to be performed:
BLOCK N39 ( REMOVE CHIPS )
- In the program itself, issue a comment section with the necessary information. Comment section must be enclosed in parentheses (three versions shown):
[A] N39 M00 (REMOVE CHIPS)
[B] N39 X189.5 M00 (REMOVE CHIPS)
[C] N39 X189.5 M00
Any one of these methods will give the CNC operator all necessary information. From all options, the comment section [A] or [B] in a program is preferable. The built-in instructions can be read at the control panel display screen.
M01 – Optional Program Stop
Miscellaneous function M01 is an optional, conditional program stop. It is similar to M00 function, with one difference. Unlike M00 function, when M01 function is read by the control, program processing will not stop without operator’s interference. The Optional Stop toggle switch or a button key located on the operation panel can be set to either ON or OFF position. When M01 function in the program is processed, current switch setting will determine whether the program will temporarily stop or processing continues without interruption:
|Optional Stop switch setting||Result of M01|
|ON||Processing will stop|
|OFF||Processing will not stop|
In case there is no M01 function programmed, the setting of the Optional Stop switch is not important. Normally, it should be set to OFF position for production work.
When active, M01 function behaves exactly as the M00 function. Motion of all axes, spindle rotation, coolant function and any further program execution will be temporarily interrupted. Feedrate, coordinate settings, spindle speed setting, etc., are retained. Further processing of the program can only be resumed by pressing the Cycle Start key. All programming rules for M00 function also apply to M01 function.
A good idea is to program M01 as the only entry in the last block of each tool, followed by a blank line with no data. If there is no need for program interruption, the Optional Stop switch will be set to OFF position and no production time is lost. If there is a need to stop processing at the end of a tool, the switch will be set to ON position and program processing stops when M01 is processed. Any time loss is usually justified under the circumstances, for example, to change a cutting insert or to inspect important dimensions or surface finish quality.
M02 and M30 – Program End
Every program must include a special function defining the end of active program. For this purpose, there are two M-functions available – the M02 and M30. Both are similar, but each has a distinct purpose. M02 function will terminate the program, but will cause no return to the first block at the program top. Function M30 will terminate the program as well but it will cause a return to the program top. The word ‘return’ is often replaced by the word ‘rewind’. It is a leftover from the times when a reel-to-reel tape reader was common on NC machines. The tape had to be rewound when the program has been completed for each part. M30 function provided this rewind capability.
When control system reads the program end function M02 or M30, it cancels all axis motions, spindle rotation, coolant function and usually resets the system to the default conditions. On some controls the reset may not be automatic and any programmer should be aware of it.
If the program ends with M02 function (usually old programs only), the control remains at the program end, ready for the next Cycle Start. On modern CNC equipment there is no need for M02 at all, except for backward compatibility. This function was used in addition to M30 for those machines (mainly NC lathes) that had tape readers without reels, using a short loop tape. The tape trailer was spliced to the tape leader, creating a closed loop. When the program was finished, the start of tape was next to its end, so no rewind was necessary. Long tapes could not use loops and required reels and M30. So much for the history of M02 – just ignore its existence.
Is M02 the same as M30 ?
On most modern controls, a system parameter can be set to make the M02 function with the same meaning as that of M30. This setting can give it the rewind capabilities, useful in situations where an old program can be used on a machine with a new control without changes.
In a summary, if the end of program is terminated by M30 function, the rewind will be performed; if the M02 function is used, the rewind will not be performed.
When writing a program, make sure the last block in the program contains nothing else but M30 as the preferred end (sequence block is allowed to start the block):
|N65 . . .|
|N66 G91 G28 X0 Y0|
|N67 M30 (END OF PROGRAM)|
On some controls, the M30 function can be used together with the axes motion – definitely NOT recommended!:
|N65 . . .|
|N66 G91 G28 X0 Y0 M30 (END OF PROGRAM)|
Percent Sign : The percent sign (%) after M30 is a special stop code. This symbol terminates the loading of a program from an external device. It is also called the end-of-file marker.
M99 – Subprogram End
The last M-function for a program end is M99. Its primary usage is in subprograms. Typically, the M99 function will terminate a subprogram and return to the processing of the previous program. If M99 is used in a standard program, it creates a program with no end -such a situation is often called an endless program loop. M99 should be used only in subprograms, not in the standard programs.