SUB Subtract
Also called: subtraction, difference, minus, −
OUT := IN1 − IN2 when the rung is 1.
What it does
The SUB block subtracts the second value from the first and writes the result into OUT.
When to use it
To compute a deviation, a remaining quantity, a time difference.
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. |
| IN1 | IN1 | Source A | INT, DINT, REAL, TIME / DINT | Input | Yes | First operand. |
| IN2 | IN2 | Source B | INT, DINT, REAL, TIME / DINT | Input | Yes | Second operand. |
| OUT | OUT | Destination | INT, DINT, REAL, TIME / DINT | Output | No | Result (variable). Not changed while the rung is 0. |
| ENO | ENO | Enable out | BOOL | Output | No | 1 when the computation ran without error. |
| Mnemonic | Name | Data type | Direction | Required | Meaning |
|---|---|---|---|---|---|
| EN | Enable | BOOL | Input | Yes | Rung condition: the computation runs only when power flow is 1. |
| IN1 | Source A | INT, DINT, REAL, TIME | Input | Yes | First operand. |
| IN2 | Source B | INT, DINT, REAL, TIME | Input | Yes | Second operand. |
| OUT | Destination | INT, DINT, REAL, TIME | Output | No | Result (variable). Not changed while the rung is 0. |
| ENO | Enable out | BOOL | Output | No | 1 when the computation ran without error. |
| Mnemonic | Name | Data type | Direction | Required | Meaning |
|---|---|---|---|---|---|
| EN | Enable | BOOL | Input | Yes | Rung condition: the computation runs only when power flow is 1. |
| IN1 | Source A | INT, DINT, REAL | Input | Yes | First operand. |
| IN2 | Source B | INT, DINT, REAL | Input | Yes | Second operand. |
| OUT | Destination | INT, DINT, REAL | Output | No | Result (variable). Not changed while the rung is 0. |
| ENO | Enable out | BOOL | Output | No | 1 when the computation ran without error. |
Example
When S1 is 1, V3 := V1 − V2.
Try it in the simulatorThe example opens in the free simulator; your own program stays as it was.
Behaviour in detail
- Runs on every scan where the rung is 1.
- Overflow: an INT goes from −32,768 to 32,767 (the result wraps around), a DINT likewise on 32 bits.
- Types: INT, DINT, REAL, TIME.