Comparison Instructions
Description
240
BCMP2(502) compares the source data (S) to the ranges defined by pairs of
lower and upper limit values in the comparison block. If S is within any of
these ranges (inclusive of the upper and lower limits), the corresponding bits
in the result words (R to R+15 max.) are turned ON. The rest of the bits in R
will be turned OFF.
The number of ranges is determined by the value N set in the lower byte of B.
N can be between 0 and 255. The upper byte of B must be 00 hex.
Comparison block
15
8
7
Last range
B
00 hex
"N"
Comparison ranges
B+1
Range 0 value A
B+3
Range 1 value A
Source data
B+5
Range 2 value A
S
B+31
Range 15 value A
B+33
Range 16 value A
B+35
Range 17 value A
B+37
Range 18 value A
B+2N+1
Range N value A
Ranges
Number of Ranges
The number of ranges in the comparison block is set in the first word of the
block. Up to 256 ranges can be set.
Setting Ranges
The values A and B for each range will determine how the comparison oper-
ates depending on which value is larger, as shown below.
· If Value A
Value B
Then, Value A
Comparison range
Comparison range
Value A
Value B
· If Value A
Value B
Then, Comparison range
Value B and Value A
Comparison
range
Value B
Value A
Example
When B+1
B+2
If B+1
S
B+2, then bit 0 of R will turn ON,
If B+3
S
B+4, then bit 1 of R will turn ON,
If S < B+5 and B+6 < S, then bit 2 of R will turn OFF, and
If S < B+7 and B+8 < S, then bit 3 of R will turn OFF.
0
N: 00 to FF hex (0 to 255)
Result words
R
Bit
B+2
0
Range 0 value B
B+4
Range 1 value B
1
Range 2 value B
B+6
2
:
:
B+32
15
Range 15 value B
R+1
Bit
B+34
0
Range 16 value B
1
Range 17 value B
B+36
2
B+38
Range 18 value B
:
:
B+2N+2
Range N value B
In range: ON
Not in range: OFF
Value B
Comparison range
Comparison
range
Section 3-6
Need help?
Do you have a question about the CP - PROGRAMMING MANUAL 05-2007 and is the answer not in the manual?
Questions and answers