SUB (Subtraction)
Subtracts second input from first input, outputs the difference.
The SUB function block subtracts the second input from the first input and outputs the difference. It is used for calculating deviations, error signals (setpoint minus process value), position differences, and remaining quantities in PLC programs.
Parameters
Inputs
| Name | Type | Description |
|---|---|---|
| IN1 | ANY_NUM | Minuend (value to subtract from) |
| IN2 | ANY_NUM | Subtrahend (value to subtract) |
Outputs
| Name | Type | Description |
|---|---|---|
| OUT | ANY_NUM | Difference (IN1 - IN2) |
Ladder Logic Example
// Ladder Logic - SUB (Error Calculation) // // |----[SUB]----| // | IN1: Setpoint | // | IN2: Process_Value | // | OUT: Error_Signal |
Structured Text Example
Error_Signal := Setpoint - Process_Value; Remaining := Total_Qty - Consumed_Qty;
Free · no signup to try
Run this block in your browser
Try the instruction on a live rung before you copy it into a project — nothing to install.
Try it in your browser — no signupOpens plcsimulationsoftware.com — same team
Prefer ready-made code? Ladder Logic Pack — $29 on Gumroad
Platform-Specific Implementation
Siemens (TIA Portal)
Use SUB instruction in TIA Portal.
Allen-Bradley (Studio 5000)
Use SUB instruction in Studio 5000.
CODESYS
Use - operator in ST or SUB function block.
Common Applications
- PID error calculation
- Position deviation
- Remaining quantity
- Differential pressure
- Time difference
Frequently Asked Questions
What is SUB (Subtraction) in PLC programming?
Subtracts second input from first input, outputs the difference. The SUB function block subtracts the second input from the first input and outputs the difference. It is used for calculating deviations, error signals (setpoint minus process value), position differences, and remaining quantities in PLC programs.
What are common applications of SUB (Subtraction)?
SUB (Subtraction) is commonly used for: PID error calculation, Position deviation, Remaining quantity, Differential pressure, Time difference.
How do I use SUB (Subtraction) in different PLC platforms?
Siemens: Use SUB instruction in TIA Portal. Allen-Bradley: Use SUB instruction in Studio 5000. CODESYS: Use - operator in ST or SUB function block.
Related Function Blocks
ADD (Addition)
Adds two or more numeric values and outputs the sum.
View Reference →MUL (Multiplication)
Multiplies two numeric values and outputs the product.
View Reference →ABS (Absolute Value)
Returns the absolute (non-negative) value of the input.
View Reference →DIV (Division)
Divides first input by second input, outputs the quotient.
View Reference →MOD (Modulo)
Returns the remainder after integer division of two values.
View Reference →Free · no signup to try
Wire this block up and run it
Drop the instruction into a rung, press Run and watch it execute in your browser — then adapt it to your vendor tool.
Try it in your browser — no signupOpens plcsimulationsoftware.com — same team
Prefer ready-made code? Ladder Logic Pack — $29 on Gumroad