Compare (CMP)

The CMP instruction performs a comparison on the arithmetic operations you specify in the expression.

Available Languages
-    Ladder Diagram





Operands
-    Ladder Diagram

Operand
Type
Format
Description
Expression
SINT
INT
DINT
REAL
string
Immediate
tag
an expression consisting of tags and/or immediate values separated by operators.

A SINT or INT tag converts to a DINT value by sign-extension.

-    Structured Text
Structured text does not have a CMP instruction, but you can achieve the same results using an IF...THEN construct and expression.

IF BOOL_expression THEN
 <statement>;
END_IF;

Determining the order of operation
The operations you write into the expression are performed by the instruction in a prescribed order, not necessarily the order you write them. You can override the order of operation by grouping terms within parentheses, forcing the instruction to perform an operation within the parentheses ahead of other operations.

Operations of equal order are performed from left to right.

Order
Operation
1
( )
2
ABS, ACS, ASN, ATN, COS, DEG, FRD, LN, LOG, RAD, SIN, SQR, TAN, TOD, TRN
3
**
4
- (negate), NOT
5
*, /, MOD
6
<, <=, >, >=, =, <>
7
- (subtract), +
8
AND
9
XOR
10
OR

Using strings in an expression
To use strings of ASCII characters in an expression, follow these guidelines:

-    An expression lets you compare two string tags.
-    You cannot enter ASCII characters directly into the expression.
-    Only the following operands are permitted:

Operator
Description
=
equal
< 
less than
<=
less than or equal
> 
greater than
>=
greater than or equal
<> 
not equal

Example



If the CMP instruction finds the expression true, the rung-condition-out is set to true.







If you enter an expression without a comparison operator, such as value_1 + value_2, or value_1, the instruction evaluates the expression as:


If the expression is:
The rung-condition-out is set to:
non zero
zero
true
false


- Download to PDF

0 comments :