Logix5000 CMP instruction

smcmanus

Member
Join Date
Jan 2006
Location
Vancouver
Posts
109
I an trying to use the CMP instruction to compare the value of 4 differnt INT's to see if they are all equall. I am able to compare "tag1 = tag2" but when I put tag3 and tag4 in I get errors.
 
So just do this and be done with it.

al622061.GIF
 
just wanted to do it with a CMP because I will need to use order of operations to other comparisons and it just looks neater.

 
If I try

Tag1=tag2 And Tag1=tag3 And Tag1=tag4

and the value of all the tags are Zero I will not get a match. Seems to work if it is another number besides zero.
 
I agree with Alaric, just use normal compares. The evaluation time is (very slightly) faster with normal compares, IMHO it is neater to look at, as well as more logical to see what is going on, doesn't need to evaluate the entire expression if one is false, and when troubleshooting, will SHOW both values, where the CMP instruction won't.
 
I know nothing about RSL5000

I have played with the demo though. I am not exactly sure of the details but when you do multiple operations you have to enclose it in parentheses, so I think you would need to do (tag1=tag2)(tag1=tag3)(tag1=tag4) or something along those lines. It may be as simple as (tag1=tag2=tag3=tag4), do not have the software to try it.

Description: Define the CMP expression using operators, tags, and immediate values. Use parentheses ( ) to define sections of more complex expressions. The execution of a CMP instruction is slightly slower and uses more memory than the execution of the other comparison instructions. The advantage of the CMP instruction is that it allows you to enter complex expressions in one instruction.

Come to think of it you may have to use INT, DINT, etc instead of a tag i.e. (int1=int2=int3=int4), others can verify this part or not.
 
Last edited:
In this case the AND instruction will not be evaluated as a boolean comparrion but as a bitwise AND, bitwise and-ing Dint_2, Dint_3 and Dint_4 together and then comparing the anded result to Dint_1. This will work when the values are truly equal, but under certain condtions it will evalute true even when all the numbers are not equal.

Suppose that
Dint_1 = 3
Dint_2 = 1
Dint_3 = 2
and Dint_4 = 3.

The expressin will evaluate true even though the values are not equal.
 
smcmanus said:
If I try

Tag1=tag2 And Tag1=tag3 And Tag1=tag4

and the value of all the tags are Zero I will not get a match. Seems to work if it is another number besides zero.

Are any of these floating point tags? Because of the way floating point tags are stored in a computer you might think that a number is zero when in fact it is not but it is very small. But the PLC is litteral, and 0 is not equal to 0.00000000000000000000000000000000000001
 

Similar Topics

RSLogix 5000 I am getting a 'CMP, Operand 0: Invalid expression.' for this. It's been a long week, I can't see the problem. (a = (b + 1)) OR...
Replies
7
Views
2,553
Hi! So my problem is a little funky, I had Studio 5000 v 24 and 30 installed, but forgot to install RSLogix (which I cannot go without). Is there...
Replies
2
Views
128
So I had an odd request from a customer for the above. I have written the logic and tested it all in one PLC with only using 7 outputs and 7...
Replies
15
Views
432
I'm a Siemens person, and this is one of my first AB programs. The customer wants everything programmed in Ladder. I have a lot of data (3...
Replies
14
Views
236
Good day everyone. if you have a logic for 3 pumps (lead/lag/off), would you please email it to me? I really appreciate it!
Replies
7
Views
221
Back
Top Bottom