DAY 3
SESSION 1
9-1
LADDER LOGIC PROGRAMMING –
COMPARISON INSTRUCTIONS
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
OBJECTIVES
After completing this module, you will be able to
• Describe the function of equal (EQ) and not equal (NEQ)
instructions
• Describe the function of less than (LES) and greater than
(GRT) instructions
• Describe the function of less than or equal to (LEQ) and
greater than or equal to (GEQ) instructions
• Describe the function of limit test (LIM)
9-2
• Describe the function of mask compare equal to (MEQ)
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
SUB-WINDOW : COMPARE
9-3
The comparison instructions let you compare values using an
expression or a specific comparison instruction
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
COMPARE (CMP)
9-4
The CMP instruction performs a comparison on the arithmetic
operations you specify in the expression.
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
EQUAL TO (EQU)
EQU
Equal
Source A
Source B
N7:5
0
N7:10
0
Use the EQU instruction to test whether two values are equal
Source A and source B can either be immediate values or tag name that
contain values
If the value in N7:5 is equal to the value in N7:10,
set output bit O:013/1
9-5
Floating point values are rarely absolutely equal. If you need to
determine the equality of floating point values, use the LIM instruction
(instead of the EQU)
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
NOT EQUAL TO (NEQ)
NEQ
Not Equal
Source A
Source B
?
?
?
?
Use the NEQ instruction to test whether two values are not equal
Source A and source B can either be immediate values or tag name
that contain values
9-6
If the value in N7:5 is not equal to the value in
N7:10, set output bit O:013/1
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
GREATER THAN OR EQUAL TO
(GEQ)
GEQ
Grtr Than or Eql (A>=B)
Source A
N7:5
0
Source B
N7:10
0
Use the GEQ instruction to test whether one value (Source A) is greater
than or equal to another value (Source B)
Source A and source B can either be immediate values or tag name that
contain values
9-7
If the value in N7:5 is greater than or equal to the
value in N7:10, set output bit O:013/1
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
GREATER THAN (GRT)
GRT
Greater Than (A>B)
Source A
N7:5
0
Source B
N7:10
0
Use the GRT instruction to test whether one value (Source A) is greater
than another value (Source B)
Source A and source B can either be immediate values or tag name that
contain values
9-8
If the value in N7:5 is greater than the value in
N7:10, set output bit O:013/1
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
LESS THAN OR EQUAL TO (LEQ)
LEQ
Less Than or Eql (A<=B)
Source A
N7:5
0
Source B
N7:10
0
Use the LEQ instruction to test whether one value (Source A) is less than
or equal to another value (Source B)
Source A and source B can either be immediate values or tag name that
contain values
9-9
If the value in N7:5 is less than or equal to the
value in N7:10, set output bit O:013/1
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
LESS THAN (LES)
LES
Less Than (A
Source A
N7:5
0
Source B
N7:10
0
Use the LEQ instruction to test whether one value (Source A) is less than
another value (Source B)
Source A and source B can either be immediate values or tag name that
contain values
9-10
If the value in N7:5 is less than the value in N7:10,
set output bit O:013/1
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
LIMIT TEST (LIM)
LIM
Limit Test
Low Lim
Test
High Lim
N7:10
0<
N7:15
0<
N7:20
0<
Use the LIM instruction to test for a value inside of or outside of a
specified range
The instruction is false until it detects that the test value is within certain
limit. Then the instruction goes true.
9-11
If the value in N7:15 is greater than or equal to the
value in N7:10 and less than or equal to the value
in N7:20, set output bit O:013/1
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
COMPARE (CMP)
CMP
Comparison
Expression
?
The CMP instruction compares value and performs logical expressions
The CMP instruction is an input instruction that performs a comparison on
arithmetic operation you specify in the expression
The expression defines the operation you want to perform. Define the
expression with operators and addresses or program constant
9-12
If the sum of the value in N7:0 and N7:1 is greater than the sum of the
value in N7:2 and N7:3, set output bit O:013/1
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
VALID OPERATOR FOR USE IN CMP
EXPRESSION
?
9-13
CMP
Comparison
Expression
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
9-14
CASE STUDY I
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
9-15
CASE STUDY II
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
CONCLUSION
If you want to:
Use the instruction:
Test whether two values are equal
EQU
Test whether one value is greater than or equal to a second value
GEQ
Test whether one value is greater than a second value
GRT
Test whether one value is less than or equal to a second value
LEQ
Test whether one value is less than a second value
LES
Test whether one value is between two other values
LIM
Pass two values through a mask and test whether they are equal
MEQ
Test whether one value is not equal to a second value
NEQ
Compare values based on an expression
CMP
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010
9-16
Comparison Instruction
NEXT
SESSION 2
9-17
FUNCTION BLOCK DIAGRAM (FBD)
PROGRAMMING I
Ladder Logic Programming – Comparison Instructions
6 – 10 December 2010