RS Logix Compare (CMP) instruction syntax

mugged99

Member
Join Date
Feb 2015
Location
MI
Posts
22
Hello, I've been having trouble getting the syntax correct in my expression for a CMP instruction. My expression is:

(VarA > VarB) AND (VarA > VarC) AND (VarA > VarD)

This is giving me an invalid expression error o_O and ive tried different combinations. The VarA, VarB, ... tags are all INTS and my goal is to determine whether or not VarA is larger than the other 3 tags. I've tried separating it all into three CMP instructions and this works but I really want to roll it into one CMP instruction for a cleaner look.

Any help appreciated!
 
A CMP instruction has two fields. How are you trying to jam 4 different variables into two fields?

Do it in Statement List.

Code:
LogicResult := (VarA > VarB) & (VarA > VarC) & (VarA > VarD);

What language are you using?
 
Last edited:
A CMP instruction has two fields. How are you trying to jam 4 different variables into two fields?

What language are you using?

All I see is an 'expression' field. I've put in a picture. Using Rs Logix 5000 is that is what you're asking. If I can't put a bunch of variable in a compare, then what is a good way to do what I'm trying to do? Thank you

Untitled.png
 
CMP only allows one comparison in the expression, but all the math you want.
So you could do something like this to stuff it all in one CMP:
( (VarA - VarB) + (VarA - VarB) + (VarA - VarD) ) > 0
 
( (VarA - VarB) + (VarA - VarC) + (VarA - VarD) ) > 0
I don't think that would work in every case. This statement is true:

( (10 - 6) + (10 -11) + (10 - 12) ) > 0

but it does not prove that A is greater than B, and A > C, and A > D. In fact A is not > C or D in this case.

VarA>VarB and VarC and VarD
Logically, that statement asks is VarA > (VarB Boolean AND VarC Boolean AND VarD).
Unless B, C, or D is 0, then (VarB Boolean AND VarC Boolean AND VarD) will always be 1, so unless A is < 1, it will not prove that A is greater that B, C, and D.

As RET advised, do 3 compares in series.
 
Last edited:
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.
 
Ok thank you everyone, I guess I'll just stick with three instructions. Also @dginbuffalo, I tried the OR expression, it still gives me an error.
 
I'm looking at it again, and no it's not the spacing between '>'. Actually when I hover my mouse over the "OR", it asks me to create a new "OR" tag. When I browse operations upon right click, the OR isn't in the drop down menu. This is strange.
 

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,070
Back
Top Bottom