Professional Documents
Culture Documents
CMP Less or Equal
CMP Less or Equal
Description
You can use the "Less or equal" instruction to determine if a first comparison value (<Oper-
and1>) is less than or equal to a second comparison value (<Operand2>). Both values to
be compared must be of the same data type.
If the condition of the comparison is fulfilled, the instruction returns the result of logic opera-
tion (RLO) "1". If the comparison condition is not fulfilled, the instruction returns RLO "0".
The RLO of the instruction is logically combined with the RLO of the entire rung as follows:
• By AND, when the comparison instruction is connected in series.
• By OR, when the comparison instruction is connected in parallel.
Specify the first comparison value (<Operand1>) at the operand placeholder above the in-
struction. Specify the second comparison value (<Operand2>) at the operand placeholder
below the instruction.
'AA' 'aa' 1
'AAA' 'a' 1
'Hello World' 'Hello World' 1
'HelloWorld' 'Hello World' 0
'BB' 'AA' 0
'AAA' 'AA' 0
You can also compare individual characters of a string. The number of the character to be
compared is specified in square brackets next to the operand name. "MyString[2]", for ex-
ample, compares the second character of the "MyString" string.
Note
Status still displayed despite "inactive" instruction
Under the following requirements:
• Prior to the instruction "CMP <=: Less or equal" (with data type STRING, WSTRING or
VARIANT), a condition (e.g. of a NO contact) is queried in the network.
• "Monitoring on" is switched on.
• A new result of the condition resets the network to FALSE. The instruction "CMP <=:
Less or equal" will become inactive.
Result:
-1-
CMP <=: Less or equal (S7-1200, S7-1500)
For the instruction "CMP <=: Less or equal" (data type STRING, WSTRING or VAR-
IANT), the previous status is still shown in the network.
When you switch "Monitoring on" off and on again or scroll to a different network, the
correct status of the instruction "CMP <=: Less or equal" (data type STRING, WSTRING
or VARIANT) is displayed. The instruction "CMP <=: Less or equal" is shown as grayed
out in the network in the inactive status.
Comparing tags of WORD data type to tags of the S5TIME data type
Both tags are converted to the TIME data type when comparing a tag of WORD data type
to a tag of S5TIME data type. The WORD tag is interpreted as an S5TIME value. If one of
the two tags cannot be converted, the comparison is not performed and the result is
FALSE. If the conversion is successful the comparison is performed based on the selected
comparison instruction.
Parameters
The following table shows the parameters of the "Less or equal" instruction:
Example
The following example shows how the instruction works:
-2-
CMP <=: Less or equal (S7-1200, S7-1500)
The "TagOut" output is set when the following conditions are fulfilled:
• The operands "TagIn_1" and "TagIn_2" have signal state "1".
• The condition of the comparison instruction is fulfilled if "Tag_Value1" <= "Tag_Value2".
For more information and the program code to the above named example, refer to: Sam-
ple Library for Instructions
See also
Overview of the valid data types
Memory areas (S7-1500)
Basic information on LAD
Memory areas (S7-1200)
-3-