Programming instructions
96
CALL – Call Subroutine
SRET – Subroutine Return
FEND – Main Routine Program End
The call subroutine command allows the execution of a section of code only
when activated. Unlike the jump command, execution of the main program
resumes from the point where the subroutine was called. By removing code from
the main ladder, scan times can be improved, since the subroutine code is only
processed when the subroutine is active.
Subroutines are coded at the end of a PLC program. Main program execution is
stopped at the FEND instruction, and the subroutines are created between this
instruction and the END instruction. Subroutines are referenced by their pointer
number for a starting point, and the next SRET command is considered the end
of that subroutine. When the logic in front of it is active, the CALL instruction
executes the code for that subroutine until the SRET subroutine return command
is reached. Once the SRET is reached, program execution returns to the main
ladder program and continues from the location of the CJ instruction.