How to Call CNC Subprograms

December 23, 2020 3:51 pm

 

A quick explanation of how to use M98 and G65 codes to call CNC subprograms within a G-code program.

When programming in G-code, it is not uncommon to reuse the same blocks of code across multiple programs. These snippets of code, the subprograms, are often stored in the machine tool memory, allowing CNC programmers to quickly “call” them when they need to run that specific task within the main program.

There are two ways to call subprograms within a CNC program: M98 and G65. The M-code M98 is used to call a subprogram followed by the program number and the number of times that we wish to repeat running that subprogram. A typical M98 block may look like this :

M98 P0002 L5;

M98 calls the subprogram and the P-value will call the program number O0002 stored in the memory of the machine. The L-value will then tell the machine how many times to run the subprogram before going back to the main program. At the end of the subprogram, the M-Code M99 is used to return to the previous program.

The G-code G65 is typically used to call and pass information in variables down to a subprogram.
A typical G65 block may look like this :

G65 P8001 A100.0 B0,5;

In this case, G65 calls the subprogram, and P8001 indicates the program number. Each of the following letters corresponds to a variable number, so in this case, A100 will pass the value 100 into variable 1 and B0.5 will pass the value 0.5 into variable 2 within the subprograms.

To learn more about subprograms, visit Gcodetutor.com.

Recommended Videos

Leave a Reply