RS Logix Compare (CMP) instruction syntax

Oops- should have been:

VarA>VarB or VarC or VarD

This should do the trick if he wants to know if VarA is larger than the other 3 tags i would think.


Be very careful with that one. It won't do a Boolean compare. It will bitwise OR VarB, VarC, and VarD into a single result and them compare if VarA is greater than that result. See AB knowledgebase technote 52939.

If Var B=5, Var B=4 and VarC=3 then they will be bitwise OR-ed and the result will be 7. If VarA=6 then the test will fail. VarA is greater than all the others, but it is not greater than the bitwise OR-ed result of 7, so the comparison will be incorrect.

It is better to use three comparisons in series. This way you are sure of exactly what you are instructing the processor to do. Ambiguity in software is not worth it when expensive processes, safety, plant uptime, and 3:00 am phone calls from Bubba are on the line.
 
Last edited:
Be very careful with that one. It won't do a Boolean compare. It will bitwise OR VarB, VarC, and VarD into a single result and them compare if VarA is greater than that result. See AB knowledgebase technote 52939.

If Var B=5, Var B=4 and VarC=3 then they will be bitwise OR-ed and the result will be 7. If VarA=6 then the test will fail. VarA is greater than all the others, but it is not greater than the bitwise OR-ed result of 7, so the comparison will be incorrect.

It is better to use three comparisons in series. This way you are sure of exactly what you are instructing the processor to do. Ambiguity in software is not worth it when expensive processes, safety, plant uptime, and 3:00 am phone calls from Bubba are on the line.

Thanks for the heads up. I can't say I've ever used this but it seems like it would work but now I'm slightly confused from the technote! Here it is for reference.

cmp3.JPG
 
There isn't anything to be confused about.

OR, AND, XOR, and NOT cannot be be used as comparison operators in a CMP expression, but they may be used as expression operators.

Put another way, you may use only =, >, <, >=, <=, and <> for the comparison. Everything else will evaluate as an expression to produce a result against which the comparison is made.

As I said before though, it is better to use three comparison instructions (in this case GRT instructions) in series so that there in absolutely no ambiguity in what you are instructing the processor to do rather than guess how the compiler will interpret the expression.
 
Last edited:
For anyone finding this in 2021, I found this thread misleading. At least in version 33.00.00, it is definitely possible to do multiple expressions in a CMP instruction! The operators you're looking for are '&&' and '||'.

Here's an example of a working CMP expression:
((SomeVar > LoLimit) && (SomeVar < HiLimit)) || IgnoreLimits
 
For anyone finding this in 2021, I found this thread misleading. At least in version 33.00.00, it is definitely possible to do multiple expressions in a CMP instruction! The operators you're looking for are '&&' and '||'.

Here's an example of a working CMP expression:
((SomeVar > LoLimit) && (SomeVar < HiLimit)) || IgnoreLimits

Not available in V30, the latest version I can check.
 

Similar Topics

Hi everyone! Accidentally closed it and it wont appear again. Checked and unchecked the option and seem to make no difference. Running v7.10.00...
Replies
16
Views
1,905
Howdy Everyone, We are working on a project in rslogix 5000 where we are using an rfid reader to read the barcodes then if they are on a list of...
Replies
10
Views
2,534
Hi While running the compare tool for two Projects, I am getting the attached difference in Program and Run. See attached. The difference seems...
Replies
3
Views
1,559
The font size and row height after doing a compare function are so small I can barely read it. I am using version 6.30.01 on a Win 10 Pro...
Replies
2
Views
1,372
is there a way to open a compact logix plc program and then compare that to the program that is actually running in the plc Thanks
Replies
1
Views
1,068
Back
Top Bottom