Program Control Instructions (1)
Program Control Instructions (1)
Chapter Objectives
The program control instructions covered in this After completing this chapter, you will be able to:
chapter are used to alter the program scan from 9.1 State the purpose of program control instructions
its normal sequence. The use of program con-
9.2 Describe the operation of the master control reset
trol instructions can shorten the time required to instruction and develop an elementary program
complete a program scan. Portions of the pro- illustrating its use
gram not being utilized at any particular time can 9.3 Describe the operation of the jump instruction and the
be jumped over, and outputs in specific zones in label instruction
the program can be left in their desired states. 9.4 Explain the function of subroutines
Typical industrial program control applications 9.5 Describe the immediate input and output instructions
are explained. function
9.6 Describe the forcing capability of the PLC
9.7 Describe safety considerations built into PLCs and
programmed into a PLC installation
9.8 Explain the differences between standard and safety
PLCs
9.9 Describe the function of the selectable timed interrupt
and fault routine files
9.10 Explain how the temporary end instruction can be
used to troubleshoot a program
176
L1 L2
Master start
Master stop
MCR
MCR
MCR MCR
CR
CR4 OL
M1
CR1
CR2 M1 OL
M2
MCR
relay. MCR coil instructions are used in pairs and can it has no address. Figure 9-4 shows the programming of
be programmed to control an entire circuit or to control an MCR fenced zone with the zone true. The operation
only selected rungs of a circuit. In the program of Fig- of the program can be summarized as follows:
ure 9-3, the MCR is programmed to control an entire • The MCR zone is enclosed by a start fence, which
circuit. The operation of the program can be summarized is a rung with a conditional MCR, and an end fence,
as follows: which is a rung with an unconditional MCR.
• When the MCR instruction is false, or de-energized, • Input A of the start rung is true so all outputs act
all nonretentive (nonlatched) rungs below the MCR according to their rung logic as if the zone did not
will be de-energized even if the programmed logic exist.
for each rung is true. Figure 9-5 shows the programmed MCR fenced zone
• All retentive rungs will remain in their last state. with the zone false. The operation of the program can be
• The MCR instruction establishes a zone in the user summarized as follows:
program in which all nonretentive outputs can be • When the MCR in the start fence is false, all rungs
turned off simultaneously. within the zone are treated as false. The scan ig-
• Retentive instructions should not normally be placed nores the inputs and de-energizes all nonretentive
within an MCR zone because the MCR zone main- outputs (that is, the output energize instruction, the
tains retentive instructions in the last active state on-delay timer, and the off-delay timer).
when the instruction goes false. • All retentive devices, such as latches, retentive tim-
• An off-delay timer will start timing when in a de- ers, and counters, remain in their last state.
energized MCR zone. • Input A of the start rung is false so output A and
Allen-Bradley SLC 500 controllers use the master T4:1 will be false and output B will remain in its last
control reset instruction to set up single or multiple zones state.
within a program. The MCR instruction is used in pairs • The input conditions in each rung will have no
to disable or enable a zone within a ladder program, and effect on the output conditions.
Input C TON
Input B Output B ON
TIMER ON DELAY
EN
Timer T4:1
Time base 1.0 DN
Preset 10
Input C
Accumulated 0
Input D Latch output B
L
Input D
Input E Unlatch output B
U
Input E
MCR End fence
A common application of an MCR zone control in- If you start instructions such as timers or counters in an
volves examining one or more fault bits as part of the start MCR zone, instruction operation ceases when the zone is
fence and enclosing the portion of the program you want disabled. The TOF timer will activate when placed inside
de-energized in case of a fault in the MCR zone. In case of a false MCR zone. When troubleshooting a program that
a detected fault condition, the outputs in that zone would contains an MCR zone, you need to be aware of which
be de-energized automatically. rungs are within zones in order to correctly edit the circuit.
Output A OFF
Input C TON
Input B
TIMER ON DELAY
EN
Timer T4:1
Time base 1.0 Output B ON
DN
Preset 10
Input C
Accumulated 0
Input D Latch output B
L
Input D
Input E Unlatch output B
U
Input E
MCR End fence
PB1 M PS1
TON M M
2 TIMER ON DELAY Timers should be
EN
Timer T4:6 programmed outside
Time base 1.0 the jumped section.
PB2 DN
Preset 5
Accumulated 0
PL1 PL1
PS1 T4:6 PL1
3
DN
SOL1
LLS1 Q2:1
LLS1
4 JMP Jumped program rungs
are not scanned by the
LS1 processor.
SOL1
LS1
5 SOL2
Input conditions are not
examined, and outputs
LS1 LS2 SOL2 remain in their last state.
LS2
6
PL2 PL2
LS3 PL2
LS3 7
LS4 SOL4
SOL3 LS4 SOL4
9
TS1 TS1 Heater Heater Heater
10
the two is in how the outputs are handled when the in-
9.3 Subroutine Functions
structions are executed. The MCR instruction sets all In addition to the main ladder logic program, PLC pro-
nonretentive outputs to the false state and keeps the reten- grams may also contain additional program files known as
tive outputs in their last state. The JMP instruction leaves subroutines. A subroutine is a short program that is used
all outputs in their last state. You should never jump into by the main program to perform a specific function. Large
a Master Control Reset zone. If you do, instructions that programs are often broken into subroutine program files,
are programmed within the MCR zone starting at the which are called and executed from the main program. In
LBL instruction and ending at the end MCR instruc- the SLC 500 series PLCs, the main ladder logic program
tion will always be evaluated as though the MCR zone is is in program file two (shown as LAD 2). Ladder logic
true, without consideration to the state of the start MCR programs for subroutines can be placed in file number
instruction. three (LAD 3) through file number 255 (LAD 255).
TON RET
Input C
TIMER ON DELAY RETURN
Timer T4:1 EN
Time base 1.0 Figure 9-10 Allen-Bradley subroutine-related instructions.
DN
Preset 10
Accumulated 0
Input D Q2:5
The sequence of rungs could be programmed one time
JMP into a subroutine and just called when needed.
The subroutine concept is the same for all program-
Input E Output C
mable controllers, but the method used to call and return
from a subroutine uses different commands, depending on
Q2:5 Input F Output D the PLC manufacturer. The subroutine-related instructions
LBL used in the Allen-Bradley PLCs shown in Figure 9-10 are
the jump to subroutine (JSR) output instruction, the sub-
routine (SBR) input instruction, and the return (RET) out-
Figure 9-8 Jump-to-label from two locations. put instruction.
The subroutine instructions can be summarized as
Use of subroutines is a valuable tool in PLC program- follows:
ming. At times it is better to construct programs that con- Jump to Subroutine (JSR)—The JSR instruction is
sist of several subroutines than a lengthy single program. an output instruction that causes the scan to jump to
When programs are written with subroutines, each sub- the program file designated in the instruction. It is the
routine can be tested individually for functionality. These only parameter entered in the instruction. When rung
subroutines can then be called from the main program as conditions are true for this output instruction, it causes
illustrated in Figure 9-9. the processor to jump to the targeted subroutine file.
When a subroutine is called from the main program, Each subroutine must have a unique file number
the program is able to escape from the main program (decimal 3–255).
and go to a program subroutine to perform certain func-
Subroutine (SBR)—The SBR instruction is the first
tions and then return to the main program. In situations
input instruction on the first rung in the subroutine
in which a machine has a portion of its cycle that must be
file. It serves as an identifier that the program file is
repeated several times during one machine cycle, the sub-
a subroutine. This file number is used in the JSR in-
routine can save a great deal of duplicate programming.
struction to identify the target to which the program
should jump. It is always true, and although its use is
Main program rungs optional, it is still recommended.
Return (RET)—The RET instruction is an output
Subroutine area
SBR
instruction that marks the end of the subroutine file.
It causes the scan to return to the main program at the
instruction following the JSR instruction where it ex-
ited the program. The scan returns from the end of the
file if there is no RET instruction. The rung containing
the RET instruction may be conditional if this rung
Jumps
RET
precedes the end of the subroutine. In this way, the
JSR
Unconditional return processor omits the balance of a subroutine only if its
rung condition is true.
Returns to next
instruction after JSR The jump to subroutine (JSR), subroutine (SBR), and
return (RET) instructions are used to direct the controller
Figure 9-9 Main program with a call from a subroutine. to execute a subroutine file. Figure 9-11 shows a materials
Solenoid
Weight
sensor
(a)
Main program
Inputs file 2 Outputs
Sensor
JSR
L1 L2
JUMP-TO-SUBROUTINE
SBR file number U:3
T4:1/EN
Stop PL1 PL1
Stop Start Motor
Start
Motor SOL
Sensor
OFF/ON Sensor SOL
Subroutine
file 3
T4:1/DN TON
SBR TIMER ON DELAY
SUBROUTINE Timer T4:0 EN
Time base 1.0 DN
Preset 1
Accumulated 0
T4:0/DN TON
TIMER ON DELAY
Timer T4:1 EN
Time base 1.0 DN
Preset 1
Accumulated 0
RET
RETURN
(b)
Figure 9-11 Flashing pilot light subroutine. (a) Process. (b) Program.
Input A JSR
JUMP-TO-SUBROUTINE
Program file 4 Input parameter passed to the
Input parameter N7:30 SBR instruction when execution
jumps to the subroutine file.
Return parameter N7:60
Execution resumes
Subroutine
file 4
SBR
SUBROUTINE
Input parameter N7:40
RET
RETURN ( )
Return parameter returned to the Return parameter N7:50
address that you specified in the
JSR instruction when execution
returns to the main ladder program.
Main program
file 2
JSR
JUMP-TO-SUBROUTINE
SBR file 3
Level 1 Level 2 Level 3
file 3 file 4 file 5
SBR SBR SBR
SUBROUTINE SUBROUTINE SUBROUTINE
JSR JSR
JUMP-TO-SUBROUTINE JUMP-TO-SUBROUTINE
SBR file 4 SBR file 5
I/O scan
12
Program scan IIN
I:012 O:013
Rack 1
the PLC-5. The SLC 500’s instructions, which are called Input/Output Compare Compute/Math Move/Logic
immediate input with mask (IIM) and immediate out-
put with mask (IOM), allow the programmer to specify IOM
which of the 16 bits are to be copied from an input mod- Immediate Output w/ Mask
ule to the input image data table (or from the output Slot O:4.0
image table to an output module). The other bits in the Mask 0FFFh
input image table or output module are not affected by Length 2
O:2/5 O:2/6
O:2/6 M
ON
off state. Figure 9-19 illustrates how an input is forced bit of the output instruction at the address is usually not
on. The operation of the program can be summarized as affected. Figure 9-20 illustrates how an output is forced
follows: on. The operation of the program can be summarized as
• The processor ignores the actual state of input limit follows:
switch I:1/3. • The processor ignores the actual state of solenoid
• Although limit switch I:1/3 is off (0 or false) the output O:2/5.
processor considers it as being in the on (1 or true) • The programming device sets the force state in the
state. output force data file and the PLC implements the
• The program scan records this, and the program is force to turn solenoid output O:2/5 on even though
executed with this forced status. the output image table file indicates that the user
• In other words, the program is executed as if the logic is setting the point to off.
limit switch were actually closed. • M output O:2/6 remains off because the status
Forcing outputs affects only the addressed output ter- bit of output O:2/5 is not affected by the force
minal. Therefore, since the output image table file bits are instruction.
unaffected, your program will be unaffected. The forcing • Not all brands of PLCs operate this way. For ex-
of outputs is done just before the output image table file is ample, forcing an output with a GE Fanuc controller
updated. When we force an output address, we are forcing will cause the contacts that have the same address as
only the output terminal to an on or off state. The status the output to also change to the appropriate state.
0 0 OFF
O:2/6
M
Field output
devices
Ladder
ONLINE Forces Exist logic
Forces Enabled program
Overriding of physical inputs on conventional relay Data File I1 (bin) . . INPUT Forces
control systems can be accomplished by installing
Offset 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
hardwire jumpers. With PLC control hardwire jumpers I:1.0 . . . . . . . . . . . . 1 . . .
are not necessary because the input data table values I:2.0
. . . .
Step-down
isolation transformer
L1 Fuse L2
120
VAC PLC Control Panel
Machine Master
start/stop control
Emergency stop switches
buttons relay
MCR
Emergency Overtravel Stop Start
stop limit
switch
MCR
MCR
PLC input module
L1 1 2 3 4 5 6 7 8 L2
controller power supply so that any diagnostic electromechanical component must not be dependent on
indicators on the processor module can still be electronic components (hardware or software). Any part
observed. can fail, including the switches in a master control relay
• Note that the master control relay is not a substitute circuit. The failure of one of these switches would most
for a disconnect switch. When you are replacing likely cause an open circuit, which would be a safe power-
any module, replacing output fuses, or working on off failure. However, if one of these switches shorts out, it
equipment, the main disconnect switch should be no longer provides any safety protection. These switches
pulled and locked out. should be tested periodically to ensure that they will stop
machine motion when needed. Never alter these circuits
The master control relay must be able to inhibit all to defeat their function. Serious injury or machine dam-
machine motion by removing power to the machine I/O age could result.
devices when the relay is de-energized. This hardwired
Number Feature
1 Module status indicators
2 Alphanumeric display
3 Node address switches
4 Baud rate switches
8 5 USB port
6 DeviceNet communication connector
10
7 Terminal connectors
5 8 Input status indicators
9 Output status indicators
9 10 IP address desplay switch
11 Ethernet connector
12 Service switch
11
6 4 12 7
Safety PLCs, such as the one shown in Figure 9-24, • Safety PLCs use power supplies designed specifi-
are now available for applications that require more ad- cally for use in safety control systems and redun-
vanced safety functionality. A safety PLC is typically dant backplane circuitry between the controller and
certified by third parties to meet rigid safety and reliabil- I/O modules.
ity requirements of international standards. Both stan-
dard and safety PLCs have the ability to perform control Safety considerations should be developed as part
functions but a standard PLC was not initially designed of the PLC program. A PLC program for any applica-
to be fault tolerant and fail-safe. That is the fundamental tion will be only as safe as the time and thought spent
difference. on both personnel and hardware considerations make
Some of the differences between standard and safety it. One such consideration involves the use of a motor
PLCs include the following: starter auxiliary seal-in contact, shown in Figure 9-25,
in place of the programmed contact referenced to the
• A standard PLC has one microprocessor that output coil instruction. The use of the field-generated
executes the program, Flash memory area that starter auxiliary contact status in the program is more
stores the program, RAM for making calcula- costly in terms of field wiring and hardware, but it is
tions, ports for communications, and I/O for safer because it provides positive feedback to the pro-
detection and control of the machine. In contrast, cessor about the exact status of the motor. Assume,
a safety PLC has redundant microprocessors, for example, that the OL contact of the starter opens
Flash and RAM that are continuously moni- under an overload condition. The motor, of course,
tored by a watchdog circuit, and a synchronous would stop operating because power would be lost to
detection circuit. Redundancy is duplication. The the starter coil. If the program was written using an
probability of hazards arising from one malfunc- examine-on contact instruction referenced to the out-
tion in an electrical circuit can be minimized put coil instruction as the seal-in for the circuit, the
by creating partial or complete redundancy processor would never know that power had been lost
(duplication). to the motor. When the OL was reset, the motor would
• Standard PLC inputs provide no internal means for restart instantly, creating a potentially unsafe operating
testing the functionality of the input circuitry. By condition.
contrast, safety PLCs have an internal output circuit Another safety consideration concerns the wiring
associated with each input for the purpose of testing of stop buttons. A stop button is generally considered
the input circuitry. Inputs are driven both high and a safety function as well as an operating function. As
low for very short cycles during runtime to verify such, all stop buttons should be wired using a nor-
their functionality. mally closed contact programmed to examine for an on
OL
Stop
M M
Start Starter
auxiliary Main power
contact contact
Starter
auxiliary
contact
Auxiliary
contact
Figure 9-25 Motor starter programmed using the starter auxiliary seal-in contact.
Source: Image Used with Permission of Rockwell Automation, Inc.
Start
Figure 9-28 Temporary end (TND) instruction. Figure 9-29 Suspend (SUS) instruction.
1. a. Two MCR output instructions are to be pro- 8. a. What does the forcing capability of a PLC allow
grammed to control a section of a program. the user to do?
Explain the programming procedure to be b. Outline two practical uses for forcing functions.
followed. c. Why should extreme care be exercised when
b. State how the status of the output devices within using forcing functions?
the fenced zone will be affected when the MCR 9. Why should emergency stop circuits be hardwired
instruction makes a false-to-true transition. instead of programmed?
c. State how the status of the output devices within
10. State the function of each of the following in the
the fenced zone will be affected when the MCR
basic safety wiring for a PLC installation:
instruction makes a true-to-false transition.
a. Main disconnect switch
2. What is the main advantage of the jump b. Isolation transformer
instruction? c. Emergency stops
3. What types of instructions are not normally in- d. Master control relay
cluded inside the jumped section of a program? 11. Compare standard and safety PLCs with regard to:
Why? a. Processors
4. a. What is the purpose of the label instruction in b. Input circuitry
the jump-to-label instruction pair? c. Output circuitry
b. When the jump-to-label instruction is executed, d. Power supplies
in what way are the jumped rungs affected? 12. When programming a motor starter circuit, why is
5. a. Explain what the jump-to-subroutine instruction it safer to use the starter seal-in auxiliary contact
allows the program to do. in place of a programmed contact referenced to the
b. In what type of machine operation can this output coil instruction?
instruction save a great deal of duplicate 13. When programming stop buttons, why is it safer
programming? to use an NC pushbutton programmed to examine
6. What advantage is there to the nesting of for an on condition than an NO pushbutton pro-
subroutines? grammed to examine for an off condition?
7. a. When are the immediate input and immediate 14. Explain the selectable timed interrupt function.
output instructions used? 15. Explain the function of the fault routine file.
b. Why is it of little benefit to program an immedi-
16. How is the temporary end instruction used to trou-
ate input or immediate output instruction near
bleshoot a program?
the beginning of a program?
CHAPTER 9 PROBLEMS
1. Answer the questions, in sequence, for the MCR c. With switches S2 and S3 still on, switch S1 is
program in Figure 9-30, assuming the program has turned off. Will both outputs PL1 and PL2 de-
just been entered and the PLC is placed in the RUN energize? Why?
mode with all switches turned off. d. With all other switches off, switch S6 is turned
a. Switches S2 and S3 are turned on. Will outputs on. Will the timer time? Why?
PL1 and PL2 come on? Why? e. With switch S6 still on, switch S5 is turned on.
b. With switches S2 and S3 still on, switch S1 is Will the timer time? Why?
turned on. Will output PL1 or PL2 or both come f. With switch S6 still on, switch S5 is turned off.
on? Why? What happens to the timer? If the timer was an
S3 S3 PL2
3 L
S4
S4 PL2
4 U
S5
S6 5 MCR
S5
6 MCR
S6 TON
TIMER ON DELAY EN
7
Timer T4:1
Time base 1:0 DN
Preset 10
Accumulated 0
8 MCR
Subroutine file 3
S4 PL3
SBR
SUBROUTINE
RET
RETURN
S1 PL1 L2
L1
1
PL1
S1
S2 JSR
S2 JUMP-TO-SUBROUTINE PL2
2
SBR file number U:3
S3 S3 20
3 JMP PL3
S4
S4 PL6
4 PL4
S5
S9 20
S6 5 JMP
PL5
S8 PL2
S7
6
PL6
S8 S10 20
7 JMP
S9
S11 PL4
8
S10
RTO
20 S7 RETENTIVE TIMER ON EN
S11 Timer T4:3
9 LBL Time base (sec) 1.0 DN
Preset 50
S12 Accumulated 0
T4:3/DN
T4:3
S13 10 RES
Subroutine file 3
S13 PL3
SBR
11 SUBROUTINE
S12 12
12 JMP
S5 PL5
13
12 S6
TON
14 LBL TIMER ON DELAY EN
Timer T4:6
Time base 1.0
Preset 5 DN
Accumulated 0
RET
15 RETURN