Chapter 11 PLC Compare, Jump, and MCR Instructions
Chapter 11 PLC Compare, Jump, and MCR Instructions
Chapter 11 PLC Compare, Jump, and MCR Instructions
p Technical Terms
compare instructions greater than (GRT) jump (JMP) instruction
equal to (EQU) less than or equal to (LEQ) master control reset (MCR)
not equal to (NEQ) greater than or equal to (GEQ) instruction
less than (LES)
Learning Objectives
After completing this chapter, you will be able to:
Use a compare instruction to energize a coil.
Program compare instructions in series to set upper and lower
limits in a control system.
Use the jump (JMP) instruction to skip over rungs in a PLC
ladder logic diagram.
Use multiple jump (JMP) instructions with multiple label (LBL)
instructions in a PLC ladder logic diagram.
Use compare instructions to energize the jump (JMP)
instructions.
Use a master control reset (MCR) instruction to halt the
operation of a section of a PLC ladder logic diagram.
11.1 Introduction
In control systems, sometimes certain conditions must be tested
to perform appropriate action. Compare instructions are used to test
these conditions.
243
244 Programmable Logic Controllers: Hardware and Programming
Equal to (EQU) A =B
Not equ a l to (NEQ) A 式 B
Less th a n (LES) A<B
G reater th a n (GRT) A>B
Less tha n or e qu a l to (LEQ) A<B
G reater th a n or equal to (GEQ) A>B
Pilot light
EQU-
0000 Equal O
Source A N7 :0
0<
Source B N7 :1
0<
nnm
Pilot light
NEQ-
0000 Not equal O
Source A N7 :0
0<
Source B N7 :1
0<
0001 c >
Figure 11-3. The not equal to (NEQ) compare instruction.
246 Programmable Logic Controllers: Hardware and Programming
the content of Source B, current will pass through the NEQ instruction
block. Therefore, in Figure 11-3, when the content of register N7:0 is not
equal to the content of register N7:l, the pilot light (0:0/0) turns on.
Less than (LES): Figure 11-4 displays the less than (LES) compare instruction.
Instruction that lets Source A must be a register. Source B can be either a register or a
current pass through
when Source A is less number. With the less than instruction, when the content of Source A
than Source B. is less than the content of Source B, current will pass through the LES
instruction block. Therefore, in Figure 11-4, when the content of regis
ter N7:0 is less than the content of register N7:l, the pilot light (0:0/0)
turns on.
Greater than (GRT): Figure 11-5 displays the greater than (GRT) compare instruction,
Instruction that lets which does the opposite of the less than instruction. Source A must
current pass through
when Source A is greater be a register. Source B can be either a register or a number. When the
than Source B. content of Source A is greater than the content of Source B, current
will pass through the GRT instruction block. Therefore, in Figure 11-5,
when content of register N7:0 is greater than the content of register
Less than or equal N7:l, the pilot light (0:0/0) turns on.
to(LEQ): Figure 11-6 displays the less than or equal to (LEQ) compare
Instruction that lets
instruction. Source A must be a register. Source B can be either a
current pass through
when Source A is less register or a number. When the content of Source A is less than or
than or equal to Source B. equal to the content of Source B, current will pass through the LEQ
Pilot light
LES
0000 Less than (A<B) O
Source A N7:0
0<
Source B N7:l
0<
0001 End
Pilot light
0001
< End.
Figure 11-5. The greater than (GRT) compare instruction.
Chapter 11 PLC Compare, Jump, and MCR Instructions 247
Example 11-1
In this example, the content of a counter-accumulated register is
tested. If the content is less than five, all pilot lights are off. If the con
tent is between five and ten, the white pilot light (White_PLT) turns
Pilot light
LEQ ■
0000 Less than or equal (A<=B)
Source A N7 :0
o
0<
Source B N7:1
0<
0001 ( >
Pilot light
GEQ ■
0000 Greater than or equal (A>=B)
Source A N7:0
o
0<
Source B N7:1
0<
0001 ( >
on. If the content is equal to ten, the green pilot light (Green_PLT)
turns on. If the content is greater than ten, the red pilot light
(Red_PLT) turns on. Figure 11-8 displays the PLC ladder logic dia
gram for this example.
Looking at rung 0001,a GEQ instruction is in series with an LES
instruction. The GEQ instruction requires a number greater than or
equal to five to allow the white pilot light (White一PLT) to trigger. The
LES instruction requires a number less than 10. Thus, in rung 0000,
White_PLT
-------GEQ------- ----- LES---------
0001 Grtr than or eql(A>=B) Less than (A<B)
Source A C5:0.ACC Source A C5:0.ACC
o
3< 3<
Source B 5 Source B 10
5< 10く
Green PLT
------ EQU-------
0002 Equal
Source A C5:0.ACC O
3<
Source B 10
10く
Red_PLT
-------GRT-------
0003 Greater than (A>B)
Source A C5:0.ACC O
3<
Source B 10
10く
C5:0 C5:0
0004 — (^RES^)-
Switch
0
0005 < End>
if the pushbutton (1:0/1) is pressed between five and nine times, the
condition for the compare instructions in series in rung 0001 is met
and the white pilot light (White一PLT) turns on.
The compare instructions in rungs 0002 and 0003 test the condi
tions for equal to (EQU) and greater than (GRT). When the pusnbut-
ton is pressed 20 times, the reset (RES) instruction in rung 0004 is
energized and the counter resets to zero. Closing the switch (1:0/0)
can also reset the counter.
0000 ヨ O
Switch
-E
0 001
0002 ヨ O
Q 2:l B3:0
0003 [ lbl} < >
0004 End
activated when the switch (1:0/0) is closed. When the switch (1:0/0) is
open, pressing the pushbutton (1:0/1) turns both pilot lights on. How
ever, if the switch is closed, the jump (JMP) instruction will activate.
In Figure 11-9, the jump and label instructions are assigned to have
address number one (Q2:l).
When the switch is closed, the JMP instruction is energized.
Now, pressing the pushbutton only turns on the green pilot light
(Green_PLT). Rung 0002 is skipped over during the PLC program
scan. Notice that the label instruction (LBL) must always be connected
in series with an output or internal coil bit. This is because every rung
in a ladder logic diagram must have an output or internal coil for the
last instruction. In rung 0003, you can see that the LBL instruction is
connected in series with internal coil bit B3:0/0.
The jump instruction is a very useful tool. The jump instruction
in PLC ladder logic diagrams is used to formulate the if-then-else pro
gramming code capability.
Example 11-2
In this example, the content of a counter-accumulated register
(C5:0.ACC) is tested. If the content is less than five, closing switch
(1:0/0) turns on both pilot lights. If the content is equal to five, then
closing the switch will only turn on the red pilot light (Red_PLT). If
the content is greater than seven, then closing the switch will only
turn on the green pilot light (Green_PLT). Figure 11-10 displays the
PLC ladder logic diagram for Example 11-2.
Pressing the green pushbutton increments the content of the
accumulator register for counter zero (C5:0.ACC). When the content
of the accumulated register is equal to five, closing the switch will
not turn on the green pilot light. When the content of the accumu
lated register is greater than seven, closing the switch will not turn
on the red pilot light. Pressing the red pushbutton (Red_PB) resets
the counter.
Example -2
Green_PB
0000
------- EQU--------
0001 Equal
Source A C5:0.ACC
2<
Source B 5
5<
Switch
1:0
0002
0
Q2:l B3:0
0003 _ £ lb l] -------------------
-------GRT------- Q2 ::
0004 Greater than (A>B)
Source A C5:0.ACC
2<
Source B 7
7<
Switch Red
oフ
oc
ェ:〇
0005
0
B3:0
0006 £ lbl> <>
1
Red一PB
1:0 C5:0
0007 〈 RES>
2
0008 End
When the packaging machine counts out 12 bottles, the bottles need to
be placed in a cardboard container. So, after a count of 12, the machine
does a conditional jump to a packaging routine.
252 Programmable Logic Controllers: Hardware and Programming
Example 11-3
Figure 11-11 displays the PLC ladder logic diagram for the Exam
ple 11-3. Closing the normally open switch turns on both pilot lights.
If you press the normally closed red pushbutton (Red_PB), the MCR
instruction activates. Then, both pilot lights turn off.
1:0
0001 B-
0
Switch
1:0
0002 -9 E-
0
0003 (MCR>
Example 11-4
The ladder logic diagram in Figure 11-12 shows various compare
functions. The content of the accumulated register for the counter
address at C5:0 is tested in the various compare function blocks against
the content of the accumulated register for the counter address at C5:l.
The function blocks are in rungs 002 through 009. If a compare function's
condition is correct, its output is energized. Rungs 010 and 011 demon
strate how compare function blocks can be placed in parallel or series to
further specify the criteria and limit inputs that will energize an output.
Example 11-4
PLC Compare Functions (chapter 11)
1/0 CTU •
Count Up
-PB Counter C5:0
Preset 1000
Accum 0
1/1 CTU •
Count Up
-P B Counter C5:l
Preset 1000
Accum 0
EQU--------
Equal
Source C5:0.ACC E q u a l To
7
Source B 3
(Continued)
Figure 11-12. PLC ladder logic diagram for Example 11-4. Programming compare functions in
LogixPro the simulator.
254 Programmable Logic Controllers: Hardware and Programming
NEQ-------- 0 :2/1
003 Not Equal
Source C5:0.ACC Not Equal To
?
Source B 4
?
■LES 0 :2/2
004 Less Than (A<B)
Source C5:0.ACC Less Than
?
Source B 6
■GRT _ 0:2/3
005 Greater Than (A>B)
Source C5:0.ACC Greater Than
?
Source B ?
?
■LEQ ■ 0:2/4
006 Less Than or Eql
Source C5:0.ACC Less Than or Equal To
?
Source B 9
•GEQ ■ 0:2/5
007 GTR Than or Eql
Source C5:0.ACC Greater Than or Equal To
?
Source B 12
■LIM - 0 :2/6
008 Limit Test
Low L 14 Between Upper and Lower Limit
7>
Test C5:0 ACC
?
High Ijim 16
-MEQ _ 0:2/7
009 Masked Equal
Source C5 :0 ACC Equal To with Mask
?
Mask 3
?
Compare 3
EQU _ 0 :2/8
010 Equal
Source C5:0.ACC Corrpare Functions in Parallel
7
Source B 20
•p
■EQU •
Equal
Source C5:1.ACC
Source B 10
C5:0
-a e -(res )-
Reset
C5:l
-(RES)-
Example 11-5
The ladder logic diagram in Figure 11-13 shows jump and master
control relay functions. Jump functions have addresses Q2:0 through
Q2:255. Each jump function must have a corresponding label function
with a matching address. This is illustrated twice in Figure 11-13, one two
jump function and its label sharing address Q2:0 in rungs 003 and 005
and a second jump function and label with corresponding address Q2:l
in rungs 006 and 008. The ladder rungs between a jump function and its
label are skipped when the jump function is energized. When an output
is jumped, it retains its last state. For example, when the jump function
Q2:0 is energized, rung 004 is skipped. In this case, output Y-LT at address
0:2/0 will retain its last state. If it is energized, it will remain energized.
The master control relay (MCR) function is used to turn off the
outputs in a ladder logic diagram or a section of ladder logic diagram.
While an MCR function is energized, it is activated, and the rungs
between its two functions operate normally. However, if an MCR func
tion is de-energized, the rungs between the two MCR functions are all
256 Programmable Logic Controllers: Hardware and Programming
You must de-energize the MCR to turn OFF the rungs between the two MCR functions.
1:1/4
002 VMCR^
MCR—SW
You must energize the JMP function to activate it. Jump Q2:0 has the Label Q2:0.
1 :1/2 Q2:0
003 -Q mp)-
SW1
GRT • 0 :2/0
004 Greater Than (A>B)
Source C5:0.ACC Y-LT
7
Source B 3
2
0
: B3:0/0
^ >
005 L
B
You mast energize the JMP function to activate it. Jump Q2:l has the Label Q2:l.
1:1/3 Q2:l
006 -]E - <JMP>
SW2
2
0 : /1
y
>
GEQ----------
007 Grtr Than or Eql
G
Source C5:1.ACC LT
-
L
?
Source B 5
?
(Continued)
Figure 11-13. PLC ladder logic diagram for Example 11-5. Programming jum p and master control relay
functions in the LogixPro simulator.
Chapter 11 PLC Compare, Jump, and MCR Instructions 257
008
009
010
Oil
■ Summary
• There are six basic compare instructions: equal to (EQU), not
equal to (NEQ), less than (LES), greater than (GRT), less than or
equal to (LEQ), and greater than or equal to (GEQ).
• There are two program control instructions: jump (JMP) and
master control reset (MCR).
• Compare instructions can be programmed in series to set upper
and lower limits in a control system.
• For the equal to (EQU), not equal to (NEQ), less than (LES),
greater than (GRT), less than or equal to (LEQ), and greater than
or equal to (GEQ) instructions, Source A must be a register, but
Source B can be either a register or a number.
30. You must energize a JMP coil to activate the JMP instruction.
3 1 . You must energize a MCR coil to activate the MCR instruction.
32. The states of the instructions that are jumped over remain the
same.
33. When the MCR instruction is de-energized, the state of the
instructions that are between the MCR instructions remain the
same.
34. In a GEQ instruction, when Source A is equal to Source B, the
current can flow through the GEQ instruction block.
35. In a GEQ instruction, when Source A is greater than Source B,
the current can flow through the GEQ instruction block.
36. Two compare instructions can be connected in series.
37. In a GRT instruction, Source A and Source B can both be registers.
38. In a GRT instruction, Source A and Source B can both be numbers.
Using the JM P and M C R instructions, draw the PLC ladder logic diagram
fo r the following problems.
39. Draw the PLC ladder logic diagram that calculates the sum of
two counter-accumulator registers. Place the sum in the preset
register of the third counter. If the sum is equal to 15 or 20, turn
the red pilot light (Red_PLT) ON. If the accumulator register for
counter number two is equal to 13, turn the light OFF. Make sure
to include a reset switch for the counters.
40. Draw the PLC ladder logic diagram that calculates the difference
of two counter-accumulator registers. Place the difference in a
temporary integer register. If the difference is greater than 10 but
not equal to 13, turn the green pilot light (Green_PLT) ON. If the
accumulator register for counter number two is equal to 4,
turn the light OFF. Make sure to include a reset switch for the
counters.
Programmable Logic Controllers: Hardware and Programming
R i 一 尺 2
where, ァ1 一'
Ri is the resistance value for temperature ta.
R2 is the resistance value for temperature t2.
T\ is temperature in degree Kelvin, 7^ = h + 273.
T2 is temperature in degree Kelvin, T2 = t2 + 273.
Assume that three counters provide the variables labeled Rv tx,
and t2. Your PLC program should calculate R2.
If R2 is greater than 100 ohms, turn the red light on. If R2 is less
than or equal to 100 ohms, turn the green light on.
42. Write a PLC program to implement the following equation.
R = px(L/A)
where,
R represents the resistance value of a wire,
p represents the resistance constant value of the wire
material.
L is the length of the wire.
A is the cross-sectional area of the wire.
Assume that the variables p, L, and A are in registers N7:0, N7:l,
and N7:2 respectively.
Your PLC program should calculate R. If R is greater than 47
ohms, turn the red pilot light on. If R is equal to 47 ohms, turn
the green pilot light on. If R is less than 47 ohms, turn the yellow
pilot light on.