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;
20 Production-Ready Ladder Logic Templates
Stop writing the same rungs from scratch. Get copy-paste-ready templates for motor control, PID loops, safety interlocks, conveyors, and more.
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 →Stop Writing Ladder Logic From Scratch
Get 20 production-ready ladder logic templates for $29 -- download instantly and use them on your next project today.
Instant download - 30-day money-back guarantee - Use on unlimited projects