M98 and M99 G-Code subprogram call
We can call upon subprograms within our main CNC program to run tasks. This saves time by running a task that is often repeated by storing it in memory.
M98 Subprogram Call
The M98 command is used to call a subprogram followed by the program number and the amount of times that we wish to repeat running that subprogram.
A typical M98 block may look like this :
M98 P52000;
At the end of the subprogram, the M-Code M99 is used to return to the previous program.
Note: the previous program may be a subprogram.
Up to 4 subprograms can be nested, this means we can call upon a subprogram inside another subprogram up to 4 times
M99 Subprogram end
The M-Code M99 will tell the machine that the subprogram that it is currently running has come to an end, if the subprogram has run the number of times specified by the initial program call using M98 P____; It will stop running the subprogram and return from to the previous program and continue to run from the line below the M98 line.
M99 will always return to the program that it came from, even if it is a subprogram. We can not jump back to the main program without returning to the program that called the subprogram.
M30 - Program Stop
Once we have used the M-Code M99 to return to the main program we would use M30 to tell the machine that the program has finished and to stop the machine.
An example:
M98 P52000;
The 'M98 P L' way
Some versions of FANUC approach this subject slightly differently, If your machine does not accept the code above, then try this:
M98 P2000 L5;
To learn more about subprograms, check out the online course CNC Macro programming
Share this article
To learn advanced G Code programming, check out my Macro B course
The quickest way to learn CNC Programming