Compare (CMP)

Define the CMP expression using operators, tags, and immediate values. Use parentheses ( ) to define sections of more complex expressions.
The advantage of the CMP instruction is that it allows complex expressions in one instruction.
When evaluating the expression all non-REAL operands will be converted to REAL before the calculations are performed if any of the following conditions is true.
  • Any operand in the expression is REAL.
  • The expression contains SIN, COS, TAN, ASN, ACS, ATN, LN, LOG, DEG or RAD.
There are rules for allowable operators in safety applications. See Valid Operators
.
Available Languages
Ladder Diagram
Ladder Diagram_Compare (CMP)_v1
Operands
These are the operands for the CMP instruction.
IMPORTANT: Unexpected operation may occur if:
  • Output tag operands are overwritten
  • Members of a structure operand are overwritten
  • Except when specified, structure operands are shared by multiple instructions.
Here are data conversion rules for mixing numeric data types within an instruction. See Data conversions.
Ladder Diagram
The following is the Ladder Diagram operand.
Operand
Data Type
Data Type
Format
Description
Expression
SINT
INT
DINT
REAL
String type
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
BOOL
String type
immediate tag
An expression consisting of tags and/or immediate values separated by operators
Formatting expressions
For each operator used in an expression, one or two operands (tags or immediate values) must be provided. Use the following table to format operators and operands within an expression.
For operators that operate on:
Use this format:
Example
One operand
operator(operand)
ABS(tag)
Two operands
operand_a operator operand_b
tag_b + 5
tag_c AND tag_d
(tag_e**2) MOD (tag_f / tag_g)
Determine the order of operation
The operations in the expression are performed by the instruction in a prescribed order, not necessarily the order they appear. The order of operation can be specified by grouping terms within parentheses, forcing the instruction to perform an operation within the parentheses ahead of their operations.
Operations of equal order are performed from left to right.
Order
Operation
1
( )
2
ABS, ACS, ASN, ATN, COS, DEG, FRD, IsINF, IsNAN, LN, LOG, RAD, SIN, SQR, TAN, TOD, TRN
3
**
4
- (negate), NOT, !
5
*, /, MOD
6
- (subtract), +
7
AND
8
XOR
9
OR
10
<, <=, >, >=, =, <>
11
&&
12
^^
13
||
Using strings in an expression
To use strings of ASCII characters in an expression, follow these guidelines:
  • An expression can compare two string tags.
  • ASCII characters cannot be entered directly into the expression.
  • The following operands are permitted:
    Operator
    Description
    =
    Equal
    <
    Less than
    <=
    Less than or equal
    >
    Greater than
    >=
    Greater than or equal
    <>
    Not equal
  • Strings are equal if their characters match.
  • ASCII characters are case-sensitive. Uppercase A ($41) is not equal to lowercase a ($61).
  • The hexadecimal values of the characters determine if one string is less than or greater than another string.
  • When the two strings are sorted as in a telephone directory, the order of the strings determine which one is greater.
RSL5K_CMP strings
Affects Math Status Flags
No
Major/Minor Faults
None specific to this instruction. See Index through arrays for array-indexing faults.
Execution
Ladder Diagram
Condition/State
Action Taken
Prescan
N/A.
Rung-condition-in is false
Set Rung-condition-out to Rung-condition-in
Rung-condition-in is true
Set Rung-condition-out to Rung-condition-in if expression evaluates to false
Rung-condition-out is cleared to false
Postscan
N/A
Example
Ladder Diagram
FTStudio-CMP-LD-EX-V1
If value_1 is equal to value_2, light_a is set to true. If value_1 is not equal to value_2, light_a is cleared to false.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.