You are on page 1of 4

12.

PROGRAM CONFIGURATION PROGRAMMING B–64124EN/01

12.3 If a program contains a fixed sequence or frequently repeated pattern, such


a sequence or pattern can be stored as a subprogram in memory to simplify
SUBPROGRAM the program.
(M98, M99) A subprogram can be called from the main program.
A called subprogram can also call another subprogram.

Format

 Subprogram
configuration
One subprogram

O  ; Subprogram number


(or the colon (:) optionally in the case of ISO)

M99 ; Program end

M99 need not constitute a separate block as indicated below.


Example) X100.0 Y100.0 M99 ;

 Subprogram call
M98 P   ;
↑ ↑
Number of times Subprogram number
the subprogram is
called repeatedly

When no repetition data is specified, the subprogram is called just once.

Explanations When the main program calls a subprogram, it is regarded as a one–level


subprogram call. Thus, subprogram calls can be nested up to four levels
as shown below.
Main program Subprogram Subprogram Subprogram Subprogram
O0001 ; O1000 ; O2000 ; O3000 ; O4000 ;

M98P1000 ; M98P2000 ; M98P3000 ; M98P4000 ;

M30 ; M99 ; M99 ; M99 ; M99 ;


(One–level nesting) (Two–level nesting) (Three–level nesting) (Four–level nesting)

A single call command can repeatedly call a subprogram up to 999 times.


For compatibility with automatic programming systems, in the first
block, Nxxxx can be used instead of a subprogram number that follows
O (or :). A sequence number after N is registered as a subprogram number.

 Reference See III–10 for the method of registering a subprogram.

136
B–64124EN/01 PROGRAMMING 12. PROGRAM CONFIGURATION

NOTE
1 The M98 and M99 code signal and strobe signal are not
output to the machine tool.
2 If the subprogram number specified by address P cannot be
found, an alarm (No. 078) is output.

Examples
 M98 P51002 ;
This command specifies “Call the subprogram (number 1002) five times in
succession.” A subprogram call command (M98P_) can be specified in the
same block as a move command.

 X1000.0 M98 P1200 ;


This example calls the subprogram (number 1200) after an X movement.

 Execution sequence of subprograms called from a main program


Main program Subprogram
1 2 3
N0010 0 ; O1010 0 ;
N0020 0 ; N1020 0 ;
N0030 M98 P21010 ; N1030 0 ;
N0040 0 ; N1040 0 ;
N0050 M98 P1010 ; N1050 0 ;
N0060 0 ; N1060 0 M99 ;
A subprogram can call another subprogram in the same way as a main pro-
gram calls a subprogram.

137
12. PROGRAM CONFIGURATION PROGRAMMING B–64124EN/01

Special Usage
 Specifying the sequence If P is used to specify a sequence number when a subprogram is
number for the return terminated, control does not return to the block after the calling block, but
destination in the main returns to the block with the sequence number specified by P. Note,
program however, that P is ignored if the main program is operating in a mode other
than memory operation mode.
This method consumes a much longer time than the normal return method
to return to the main program.

Main program Subprogram


N0010 … ; O0010 … ;
N0020 … ; N1020 … ;
N0030 M98 P1010 ; N1030 … ;
N0040 … ; N1040 … ;
N0050 … ; N1050 … ;
N0060 … ; N1060 M99 P0060 ;

 Using M99 in the main If M99 is executed in a main program, control returns to the start of the
program main program. For example, M99 can be executed by placing /M99 ; at
an appropriate location of the main program and setting the optional block
skip function to off when executing the main program. When M99 is
executed, control returns to the start of the main program, then execution
is repeated starting at the head of the main program.
Execution is repeated while the optional block skip function is set to off.
If the optional block skip function is set to on, the /M99 ; block is skipped
; control is passed to the next block for continued execution.
If/M99Pn ; is specified, control returns not to the start of the main
program, but to sequence number n. In this case, a longer time is required
to return to sequence number n.

N0010 … ;
N0020 … ;
N0030 … ;
Optional block skip N0040 … ;
OFF
N0050 … ;
/ N0060 M99 P0030 ; Optional block skip
ON
N0070 … ;
N0080 M02 ;

138
B–64124EN/01 PROGRAMMING 12. PROGRAM CONFIGURATION

 Using a subprogram only A subprogram can be executed just like a main program by searching for
the start of the subprogram with the MDI.
(See III–9.3 for information about search operation.)
In this case, if a block containing M99 is executed, control returns to the
start of the subprogram for repeated execution. If a block containing
M99Pn is executed, control returns to the block with sequence number n
in the subprogram for repeated execution. To terminate this program, a
block containing /M02 ; or /M30 ; must be placed at an appropriate
location, and the optional block switch must be set to off ; this switch is
to be set to on first.

N1010 … ;
N1020 … ;
N1030 … ;
Optional block skip
/ N1040 M02 ;
ON
N1050 M99 P1020 ;

139

You might also like