9 NC Programming Routines
9.7 Subprogram Programming
143
9.7.
SUBPROGRAM PROGRAMMING
Subprograms are used to execute repetitive routines in an NC program. The subprogram is entered in
the NC code only once, but can be called and run any number of times. This is especially useful if the
milling operation you wish to repeat is lengthy or complex.
The NC codes used for sub-programming on the ProMill milling center are listed below.
Info Table: Sub-programming NC Codes
Code
Description
M98
Call to subprogram.
M99
Return from subprogram.
P
The P code is used to reference the first line of the subprogram (which begins with an O code). The P
code immediately follows an M98.
The P code can also be used with an M99 code to specify the line number in the main program to be run
next.
L
The L code is used as a loop counter when used in sub-programming. The computer executes the
subprogram the number of times set by the L code. For instance, if the code is L5, the subprogram is
executed five times. After the fifth cycle, the program will not restart the subprogram but will instead
continue to the next step in the program. (Optional)
O
The O code replaces the N code on the first line of a subprogram.
The general program flow when using a subprogram is illustrated in this table.
Subprogram Flow
No.
Description
1
An M98 and P code located in the main program call the subprogram. The P code specifies which
subprogram to run. Each subprogram is labeled with an O code instead of an N code.
2
The main program is interrupted, and the subprogram begins to run.
3
An M99 code in the subprogram ends the subprogram. The main program recommences from the point
at which it was interrupted.
Subprogram calls can also be nested within other subprogram calls. This means that while a subprogram
is being executed, it can call another subprogram. The default number of levels that subprograms can be
nested is 20 levels deep.
The sample subprogram below makes a series of light chamfered grooves. It is set up for stock with a
0.75" diameter and 2" length so you should use a piece slightly longer than that, say 0.75" X 2.5", if you
plan to test it.
Note that the file uses absolute programming in the main program and incremental programming in the
subprogram. This makes it necessary to use the G90 code after the subprogram is executed to allow
motion back to the start point.
NC Code Example:
G05
M03 S1000
;SUBPROGRAMMING SAMPLE