CPT Compute an expression (CPT)
Also called: compute, expression, formula, math expression
OUT := an expression written as text (+ − * / MOD, parentheses).
What it does
The CPT block computes a whole expression and writes the result into OUT when the rung is 1.
When to use it
For a formula with several operations: scaling, average, unit conversion.
Operands
| European mnemonic | American mnemonic | Name | Data type | Direction | Required | Meaning |
|---|---|---|---|---|---|---|
| EN | EN | Enable | BOOL | Input | Yes | Rung condition: the computation runs only when power flow is 1. |
| Expression | Expression | Expression | ANY_MAGNITUDE | Input | Yes | Expression, for example (V1 + V2) * 2. |
| OUT | OUT | Destination | INT, DINT, REAL, TIME / DINT | Output | Yes | Destination: its type sets the type of the computation. |
| ENO | ENO | Enable out | BOOL | Output | No | 0 on division by zero. |
| Mnemonic | Name | Data type | Direction | Required | Meaning |
|---|---|---|---|---|---|
| EN | Enable | BOOL | Input | Yes | Rung condition: the computation runs only when power flow is 1. |
| Expression | Expression | ANY_MAGNITUDE | Input | Yes | Expression, for example (V1 + V2) * 2. |
| OUT | Destination | INT, DINT, REAL, TIME | Output | Yes | Destination: its type sets the type of the computation. |
| ENO | Enable out | BOOL | Output | No | 0 on division by zero. |
| Mnemonic | Name | Data type | Direction | Required | Meaning |
|---|---|---|---|---|---|
| EN | Enable | BOOL | Input | Yes | Rung condition: the computation runs only when power flow is 1. |
| Expression | Expression | ANY_MAGNITUDE | Input | Yes | Expression, for example (V1 + V2) * 2. |
| OUT | Destination | INT, DINT, REAL | Output | Yes | Destination: its type sets the type of the computation. |
| ENO | Enable out | BOOL | Output | No | 0 on division by zero. |
Example
When S1 is 1, V3 := (V1 + V2) × 2.
Try it in the simulatorThe example opens in the free simulator; your own program stays as it was.
Behaviour in detail
- Operators: + − * / MOD and parentheses; variables and instance members (T1.ET or T1.ACC).
- The computation uses the destination's type (INT, DINT, REAL or TIME).
- Division by zero anywhere in the expression: ENO = 0 and OUT is not changed.
European (IEC) and American styles
CPT (compute) comes from the American style. In the European style you would rather write a chain of ADD, MUL… blocks or structured text; here CPT is offered in both styles.