Subtract SUB
Dest = A − B.
SUB
AGlobal.Target10BGlobal.Done4DestGlobal.Left6
| Tag | After two scans |
|---|---|
| Done | 4 |
| Left | 6 |
| Target | 10 |
How it works
While the rung is true, writes Source A - Source B to the destination each scan. A fault, such as a divide by zero, leaves the destination unchanged.
How it's used
Use SUB to find what is left or how far apart two values are.
SUB
AGlobal.Target50BGlobal.Made46DestGlobal.Left4
LEQ
AGlobal.Left4B5
Global.NearlyDoneOTE
| Tag | Value |
|---|---|
| Target | 50 |
| Made | 46 |
| Left | 4 |
| NearlyDone | 1 |
4 are left, so NearlyDone is on.
Operands
| Operand | Data type | Read or write |
|---|---|---|
| A | DINT, REAL or a number | Reads |
| B | DINT, REAL or a number | Reads |
| Dest | DINT, REAL | Writes |
Common mistakes
- Reversing the sourcesSubtract computes A minus B.
Learn it in a lesson
- Moving and calculating dataIntermediate · 25 min