Math (output instruction)

CPT: Compute

Evaluates a whole arithmetic expression in one instruction.

Also called: compute, expression, calculate.

CPT(number, expr, real)

Arguments

NameWhat it isAcceptsDefault
destinationWhat the instruction acts ona registerrequired
exprExpressionan expressionnone
realFloating pointtrue or falsefalse

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

RUNG 1Scale_EnableCPT Level_PercentLevel_Raw * 100 / RUNG 2Level_Percent≥ 90High_Level_Alarm
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 simulator

What it is called on other controllers

PlatformEquivalent
Rockwell (Studio 5000)CPT
Siemens (TIA Portal)CALCULATE
Mitsubishi (GX Works)No single expression instruction: chained arithmetic instructions
CODESYS and IEC 61131-3An 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.

Related instructions

All ladder logic instructions