Subroutine Program - Mitsubishi Electric MELSEC iQ-R Series User Manual

Process cpu module
Hide thumbs Also See for MELSEC iQ-R Series:
Table of Contents

Advertisement

8.6

Subroutine Program

Subroutine program is a program that is executed from a pointer (P) through the RET instruction. It is executed only when
called by a subroutine call instruction (such as the CALL instruction or the ECALL instruction). A pointer type label can also be
used instead of a pointer (P). The subroutine program is used for the following purposes.
• By grouping programs executed multiple times in a single scan into a single subroutine program, the total number of steps
in a single program can be decreased.
• By making a program which is only executed in a certain condition a subroutine program, the scan time can be shortened
for that program execution.
Main routine program
Subroutine program 1
Subroutine program 2
Subroutine program 3
*1 The pointers are not required to be defined in an ascending order.
• Making a program a standby type allows it to be managed as a separate program. ( Page 111 Standby
type program) Use the ECALL instruction and other similar instructions to call program files.
• For details on nesting (nesting structure) of subroutine programs, refer to the nesting (N). ( Page 483
Nesting (N))
Precautions
The following lists the precautions when using the subroutine program.
• When using a local device, setting of SM776 (Local device setting at CALL) allows for using a local device of a program file
at the storage location of the subroutine program.
• Do not use the timer (T, ST). However, the timer can be used if the timer coil (the OUT T instruction) is executed only
once per scan.
• If the RET instruction is not used to return to the calling program and then the program is terminated, an error will occur.
• If a pointer (P) or pointer type global label exists within FB or FUN, an error will occur.
8 RUNNING A PROGRAM
114
8.6 Subroutine Program
Program A
(1)
FEND
P0
RET
P8
RET
P1
RET
END
*1
Pointer
(1) The end of the main routine program

Advertisement

Table of Contents
loading

Table of Contents