M-Code M97, M98 and M99 Subprogramming M-Codes
M97 Local Sub-Program Call (P, L):
M97 is
the M-code Used to call a Subprogram with the reference of the line number N
within the same program. Pxxxx code is used as a line number to be repeated.
Xxxx is the line number in the same program. This is used for the simple
program within the program and does not require complication of creating a sub
program. A local sub-program must end with an M99. If there is a repetition of
the loop of subprogram L count on the M97 line, the sub-program will be
repeated L number of times.
M97 Program Format:
M97 Pxxxx
Lnn
Whereas, xxxx
is the line number
nn is the number of
repetitions
Example:
Main
program:
O01234
(Program number and Start of main program)
N0001
T02 M06;
N0002
T03
N0003
G54 G90 G00 Z50
...
...
... (Part program)
...
M97 P0015
L3 (Jumps to line N0015, after the M30, to execute a local sub-program for 3
times)
... (The M99 at the end of the sub-program
will cause it to jump back here.)
...
...
...
(Finish part program)
...
M30
(End of main program)
N0015
(Identifies the start of the Local Sub-Program called up by M97 P0015)
...
...
(Local sub-program portion of Main program)
...
M99
(Jumps back to the line after local sub-program call in the main program)
M98 Sub-Program Call (P, L):
M98 is the M-code Used to call a Subprogram
with the reference to the separate program created and loaded on the controller.
The Pxxxx code is the sub-program number being called; it must be in the same
block as the M98. A sub-program must end with an M99 to enter to main program
after the subprogram. If there is a repetition of the loop of subprogram L count
on the M98 line, the sub-program will be repeated L number of times before
continuing to the next block.
M98 Program Format:
M98 Pxxxx
Lnn
Whereas, xxxx
is the line number
nn is the number of
repetitions
Example:
Main program:
O01234 (Program
number and Start of main program)
N0001
T02 M06;
N0002
T03
N0003
G54 G90 G00 Z50
...
...
... (Part program)
...
...
M98 P111 (Jumps to program O00111 to
execute sub-program)
... (The M99 at the end of the sub-program
will jump back here)
...
... (Finish part program)
...
M30 (End of main program)
Sub-program:
O00111 (Identifies the start of a separate
sub-program)
...
... (Sub-program portion of part)
...
M99 (Jumps back to the line after the
sub-program call in the main program).
M99
End Sub-Program or Return or Loop :
This M-code is used
to end the sub-program. If M99 is used in
the main program, it will cause the program to loop back to the beginning and
repeat over and over again without stopping.
Example:
Main program:
O01234
...
...
(Complete part program)
...
...
M99
(This will cause the program to jump back to the beginning and repeat itself)
An M99
without a P code at the end of a sub-program will return to the main Program.)
Main program:
O01234
...
...
(Part program)
...
M98 P111
(Jumps to program O00111 to run)
…
...
(The M99 at the end of the sub-program will jump back here)
...
...
(Finish part)
...
M30
(End of main program)
Sub-program:
O00111
(sub-program number)
...
...
(Sub-program portion of part)
...
M99
(Jumps back to the line after the sub-program call)