142
5-15
Data Comparison
This section describes the instructions used for comparing data. CMP(20) is
used to compare the contents of two words; BCMP(68) is used to determine
within which of several preset ranges the content of one word lies; and
TCMP(85) is used to determine which of several preset values the content of
one word equals.
5-15-1
COMPARE – CMP(20)
Cp1
: First compare word
IR, SR, AR, DM, HR, TC, TR, #
Cp2
: Second compare word
IR, SR, AR, DM, HR, TC, LR, #
Ladder Symbols
Operand Data Areas
CMP(20)
Cp1
Cp2
When comparing a value to the PV of a timer or counter, the value must be in
BCD.
When the execution condition is OFF, CMP(20) is not executed. When the
execution condition is ON, CMP(20) compares Cp1 and Cp2 and outputs the
result to the GR, EQ, and LE flags in the SR area.
Placing other instructions between CMP(20) and the operation which ac-
cesses the EQ, LE, and GR flags may change the status of these flags. Be
sure to access them before the desired status is changed.
ER:
Indirectly addressed DM word is non-existent. (Content of
*
DM word
is not BCD, or the DM area boundary has been exceeded.)
EQ
:
ON if Cp1 equals Cp2.
LE
:
ON if Cp1 is less than Cp2.
GR
:
ON if Cp1 is greater than Cp2.
The following example shows how to save the comparison result immedi-
ately. If the content of 010 is greater than that of HR 09, 00200 is turned ON;
if the two contents are equal, 00201 is turned ON; if content of 010 is less
than that of HR 09, 00202 is turned ON. In some applications, only one of the
three OUTs would be necessary, making the use of TR 0 unnecessary. With
Limitations
Description
Precautions
Flags
Example 1:
Saving CMP(20) Results
Data Comparison
Section 5-15