Page 209 - Programmable Logic Controllers, Fifth Edition - Mobile version
P. 209
• When rung 4, containing the JMP instruction, is
The forward jump is similar to an MCR instruction
true, the processor is instructed to jump to the LBL in that both permit an input logic condition to skip over
target in rung 8 and continue to execute the main a block of PLC ladder logic. The main difference be-
program from that point. tween the two is in how the outputs are handled when
• Instructions to the right of the LBL are out of the the instructions are executed. The MCR instruction sets
jump zone and are executed as a normal rung. all nonretentive outputs to the false state and keeps the
• Jumped rungs 5, 6, and 7 are not scanned by the retentive outputs in their last state. The JMP instruction
processor. leaves all outputs in their last state. You should never
• Input conditions for the jumped rungs are not exam- jump into a Master Control Reset zone. If you do, in-
ined and outputs controlled by these rungs remain in structions that are programmed within the MCR zone
their last state. starting at the LBL instruction and ending at the end
MCR instruction will always be evaluated as though the
• Any timers or counters programmed within the MCR zone is true, without consideration to the state of
jump area cease to function and will not update the start MCR instruction.
themselves during this period. For this reason they
are usually programmed outside the jumped section 9.4 Subroutine Functions
in the main program zone.
• This is called a forward jump, as we are jumping In addition to the main ladder logic program, PLC pro-
forward in the program. grams may also contain additional program files known
as subroutines. A subroutine is a short program that is
You can jump to the same label from multiple jump used by the main program to perform a specific func-
locations, as illustrated in the program of Figure 9-8. In tion. Large programs are often broken into subroutine
this example, there are two jump instructions addressed program files, which are called and executed from the
Q2:5. There is a single label instruction addressed main program. In the SLC 500 series PLCs, the main
Q2:5. The scan can then jump from either jump instruc- ladder logic program is in program file two (shown as
tion to label Q2:5, depending on whether input A or LAD 2). Ladder logic programs for subroutines can be
input D is true. placed in file number three (LAD 3) through file number
It is possible to jump backward in the program, but this 255 (LAD 255).
should not be done an excessive number of times. Care Use of subroutines is a valuable tool in PLC program-
must be taken that the scan does not remain in a loop too ming. At times it is better to construct programs that
long. The processor has a watchdog timer that sets the consist of several subroutines than a lengthy single pro-
maximum allowable time for a total program scan. If this gram. When programs are written with subroutines, each
time is exceeded, the processor will indicate a fault and subroutine can be tested individually for functionality.
shut down. These subroutines can then be called from the main pro-
gram as illustrated in Figure 9-9.
Ladder logic program
Input A Q2:5 Main program rungs
JMP
Input B Output A Subroutine area
SBR
Input D Q2:5
JMP
Input E Output C
Jumps
JSR RET
Unconditional return
Q2:5 Input F Output D
LBL Returns to next
instruction after JSR
Figure 9-8 Jump-to-label from two locations. Figure 9-9 Main program with a call from a subroutine.
190 Chapter 9 Program Control Instructions
pet73842_ch09_184-206.indd 190 03/11/15 4:01 PM