What is the point of the Rockwell CMP Instructions?

theColonel26

Lifetime Supporting Member
Join Date
Feb 2014
Location
West Michigan
Posts
782
What is the point of the Rockwell CMP Instructions?


I would expect the power to lie in the ability to do nested conditions such as


(TagA > TagB) XOR (TagC > TagD) but you can't do nested conditions as far as I can tell. You are only allowed to use one comparison operator.


Can anyone fill me in on what this can do that a EQU, NEQ, GRT, LES Etc can't do?
 
The power is in the more complex expression. But it still evaluates to one basic comparison.

(Tag1 * Tag2) + (Tag3 / Tag 4) > Tag5

The downside in part is that you don't see the current values or these tags, and you can't see the intermediate results, like what is Tag1 * Tag2? You can hover a cursor over each to see their current value but that gets tedious.

Another benefit is reduced memory usage. The expression above would have taken four dedicated instructions as opposed to one CMP. The scan time would be roughly equivalent, but the logic memory usage would be reduced.

That's my take. I've never really been a fan of the instruction.

OG
 
The downside in part is that you don't see the current values or these tags, and you can't see the intermediate results, like what is Tag1 * Tag2? You can hover a cursor over each to see their current value but that gets tedious.... OG

There have been time I split a CPT into multiple CPT's just to see the intermediate result written to a temp tag.
 
My most common usage would be something like

ABS( SP - PV ) > AlarmSP

pretty handy to do in one instruction.
 
I use it occasionally for deviation, e.g. if you're trying to see if something is within a tolerance window.

PV > Setpoint + Tolerance
PV < Setpoint - Tolerance

Otherwise you have to create additional tags to determine the upper and lower bounds of your tolerance window. Sometimes this is handy, but sometimes it seems pointless to create two new tags and four instructions, when I can just throw a CMP at it and call it a day.
 
In reality it’s in place to avoid a rather large rung of ladder for an equation that can be evaluated with one instruction.

Also don’t forget within a CMP order of operations really matter, regardless of what country and when you learned math.
 
Another benefit is reduced memory usage.

There will be a trade-off for the additional memory usage as the instructions CMP and CPT execute, for it to hold intermediate values during the computation of the expressions. More parentheses, more memory usage. However, this memory usage is reclaimed after each instruction completes.


The scan time would be roughly equivalent.

Scan times for CMP and CPT are always longer than doing the equivalent math(s) in cascaded simple math(s) instructions. The reason being that the expressions are "parsed" before evaluation, to decide on the evalution order, even if there are no parentheses in the expressions.

Breaking the expressions into simple comparison and math(s) instructions will dictate the order of evaluation.
 
There will be a trade-off for the additional memory usage as the instructions CMP and CPT execute, for it to hold intermediate values during the computation of the expressions. More parentheses, more memory usage. However, this memory usage is reclaimed after each instruction completes.
Scan times for CMP and CPT are always longer than doing the equivalent math(s) in cascaded simple math(s) instructions. The reason being that the expressions are "parsed" before evaluation, to decide on the evalution order, even if there are no parentheses in the expressions.

Breaking the expressions into simple comparison and math(s) instructions will dictate the order of evaluation.

So, I just did an unscientific test. I created a new project and added one line of code with four math instructions. ADD, MUL, DIV, ABS. Each using the result from the previous instruction. I then copied and pasted until I had 1024 identical rungs. This "long" method program scan time was approximately 240-280 microseconds and used 948k of RAM.

I then created a whole new project where I used a CPT to perform those same four functions. Again, copy and paste to get 1024 rungs. The "short" method used 495k of RAM with a scan time of 80-90 microseconds.

In both cases I am measuring the program scan time, not the task scan time. There is no other logic or tasks.

Interestingly, the offline memory estimate for both was the same. The memory usage mentioned was online.

Like you said, the factors, including the math that you perform, the data type used, and the complexity of the expression all make a difference. I suspect I could generate another example where the results are closer or even flipped. But I have long held the belief that the CPT saves memory, but not scan time. In fact, I believed there might be a slight scan time penalty that would just about even out as the expression got more complex.

Again, totally unscientific. Just a workbench result.

OG

EDIT: Just did another example and the scan time results went the other way. However, memory usage was still nearly 1/2 using the compute.
 
Last edited:
This is from the "Help" on the CPT instruction ...

RockwellAutomation said:
Description

The CPT instruction performs the arithmetic operations you define in the expression. When enabled, the CPT instruction evaluates the expression and places the result in the Destination.
The execution of a CPT instruction is slightly slower and uses more memory than the execution of the other compute/math instructions. The advantage of the CPT instruction is that it allows you to enter complex expressions in one instruction.
Tip: There is no limit to the length of an expression.
 
I once worked on a brewery job where the boiling of the Wort is controlled by a liquor balance equation.

It was quite complex, so I entered it into a CPT instruction, the expression copy/pasted from the functional specification.

The first Wort Boiling was a failure, and they immediately pointed the finger at the programmer, me. I showed them the rung in the code, and took a screen-shot of it, printed it and gave it to the brewer to compare against what was in the FS.

Ten minutes later he returned to say the equation perfectly matched the FS, but then admitted the FS was wrong !
 

Similar Topics

I have an additiona 5pcs 4-Channel AI (1734-IE4C) and 5pcs 4-channel AO (1734-OE4C) in an already working system 1756-L83E controller with bunch...
Replies
3
Views
469
Hi I have removed at IO card from a 1734-AENTR Point IO, from a slot in the middle, and moved the remaining cards together. Now the Point IO...
Replies
3
Views
658
Good Morning , I'm doing a few projects around the plant that are standalone because we do not have a plantwide network in place yet. For...
Replies
4
Views
2,045
Hi I´m using Rockwell Controllogix and Point IO. Regarding analogue input card and RTD - how can I configure the raw count to go to zero with...
Replies
5
Views
4,171
Hi there, Long time lurker posting for the first time. TLDR: Trying to configure a small Point IO drop into an existing system, the point IO...
Replies
23
Views
27,088
Back
Top Bottom