Math (output instruction)
CPT: Compute
Evaluates a whole arithmetic expression in one instruction.
Also called: compute, expression, calculate.
CPT(number, expr, real)Arguments
| Name | What it is | Accepts | Default |
|---|---|---|---|
| destination | What the instruction acts on | a register | required |
| expr | Expression | an expression | none |
| real | Floating point | true or false | false |
Arguments are positional and this table is generated from the simulator's own instruction registry, so it always matches what the engine accepts.
What it does
CPT takes a formula rather than two operands, so a calculation that would be three instructions writing into two scratch registers becomes one instruction and one destination. Scaling written as Raw times 100 divided by full scale is the obvious candidate.
The gain is real: fewer intermediate tags, less to keep in step, and a rung that reads like the equation in the instrument's manual.
The cost is that the middle of the calculation is no longer visible. Three separate instructions leave three values you can watch while the machine runs, and when the answer is wrong one of them tells you where it went wrong. A CPT gives you one answer and no working out.
The order of operations is ordinary arithmetic, brackets included, and integer truncation still applies at every step. Putting the multiply before the divide matters here exactly as much as it does in separate instructions.
A rung you can run
Scaling in one instruction, in the right order
XIC(Scale_Enable)CPT(Level_Percent,"Level_Raw * 100 / 27648")
GEQ(Level_Percent,90)OTE(High_Level_Alarm)Turn on Scale_Enable and set Level_Raw to 24884: the level reads 90 percent and the alarm comes on. The multiply sits before the divide inside the expression for the same reason it would in two separate instructions. Swap them round in the text and every reading below full scale becomes 0.
Run this rung in the simulatorWhat it is called on other controllers
| Platform | Equivalent |
|---|---|
| Rockwell (Studio 5000) | CPT |
| Siemens (TIA Portal) | CALCULATE |
| Mitsubishi (GX Works) | No single expression instruction: chained arithmetic instructions |
| CODESYS and IEC 61131-3 | An assignment in structured text |
Common mistakes
- Believing it protects you from integer maths. It does not. Divide before you multiply inside a CPT and the resolution is gone just the same, and now it is hidden inside a string rather than visible as a rung.
- Using it for the whole calculation when the middle values are worth watching. If commissioning is going to involve asking what the scaled value was before the offset, keep the steps apart.
Practise it
Interactive exercises that use CPT. Each one checks your ladder against a real scan.
