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 instr
Trang 1DAY 3
SESSION 1
LADDER LOGIC PROGRAMMING –
COMPARISON INSTRUCTIONS
Trang 2After 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)
• Describe the function of mask compare equal to (MEQ)
Trang 3SUB-WINDOW : COMPARE
The comparison instructions let you compare values using an
expression or a specific comparison instruction
Trang 4COMPARE (CMP)
The CMP instruction performs a comparison on the arithmetic
operations you specify in the expression.
Trang 5EQUAL TO (EQU)
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
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)
EQU Equal Source A N7:5
0 Source B N7:10
0 EQU
If the value in N7:5 is equal to the value in N7:10, set output bit O:013/1
Trang 6NOT EQUAL TO (NEQ)
NEQ Not Equal
?
?
NEQ
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
If the value in N7:5 is not equal to the value in N7:10, set output bit O:013/1
Trang 7GREATER THAN OR EQUAL TO
Grtr Than or Eql (A>=B) Source A N7:5
0
Source B N7:10
0
GEQ
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
If the value in N7:5 is greater than or equal to the value in N7:10, set output bit O:013/1
Trang 8GREATER THAN (GRT)
GRT Greater Than (A>B) Source A N7:5
0
Source B N7:10
0
GRT
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
If the value in N7:5 is greater than the value in N7:10, set output bit O:013/1
Trang 9LEQ Less Than or Eql (A<=B) Source A N7:5
0
Source B N7:10
0
LEQ LESS THAN OR EQUAL TO (LEQ)
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
If the value in N7:5 is less than or equal to the value in N7:10, set output bit O:013/1
Trang 10LESS THAN (LES)
LES Less Than (A<B) Source A N7:5
0
Source B N7:10
0
LES
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
If the value in N7:5 is less than the value in N7:10, set output bit O:013/1
Trang 11LIM Limit Test Low Lim N7:10
0<
Test N7:15
0<
High Lim N7:20
0<
LIM LIMIT TEST (LIM)
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.
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
Trang 12COMPARE (CMP)
CMP Comparison Expression ?
CMP
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
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
Trang 13VALID OPERATOR FOR USE IN CMP
EXPRESSION
CMP Comparison Expression ?
CMP
Trang 14CASE STUDY I
Trang 15CASE STUDY II
Trang 16Test 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
Comparison Instruction
Trang 17SESSION 2
FUNCTION BLOCK DIAGRAM (FBD)
PROGRAMMING I