Compute CPT
Dest = the result of an expression, like (A − B) / 2.
COMPUTE
DestGlobal.Result3
| Tag | After two scans |
|---|---|
| A | 10 |
| B | 3 |
| Result | 3 |
How it works
While the rung is true, works out the expression and writes it to Dest. Use + - * / % and brackets. * / % come before + -. If any value is a REAL the result is a REAL, and an integer Dest is rounded. A fault, such as dividing by 0, leaves Dest unchanged.
How it's used
Use CPT when a formula has several steps.
COMPUTE
DestGlobal.AvgTemp73
| Tag | Value |
|---|---|
| Temp1 | 70 |
| Temp2 | 76 |
| AvgTemp | 73 |
AvgTemp = (Temp1 + Temp2) / 2 = 73.
Operands
| Operand | Data type | Read or write |
|---|---|---|
| Dest | SINT, INT, DINT, LINT, REAL | Writes |
Common mistakes
- Expecting a later step to fix an overflowEach step is checked, so (2147483647 + 1) - 2 faults at the +.