MOD (Modulo)
Returns the remainder after integer division of two values.
The MOD (Modulo) function returns the remainder after integer division of the first input by the second input. MOD is useful for creating cyclic patterns, detecting even/odd values, implementing circular buffers, and distributing items across lanes. For example, MOD(Count, 4) cycles through 0, 1, 2, 3, 0, 1, 2, 3... as Count increments.
Parameters
Inputs
| Name | Type | Description |
|---|---|---|
| IN1 | ANY_INT | Dividend |
| IN2 | ANY_INT | Divisor (must not be zero) |
Outputs
| Name | Type | Description |
|---|---|---|
| OUT | ANY_INT | Remainder (IN1 MOD IN2) |
Ladder Logic Example
// Ladder Logic - MOD (Lane Distribution) // // |----[MOD]----| // | IN1: Part_Count | // | IN2: 4 | // | OUT: Lane_Number |
Structured Text Example
Lane_Number := Part_Count MOD 4; // 0, 1, 2, 3, 0, 1, 2, 3... Is_Even := (Value MOD 2) = 0;
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 MOD instruction in TIA Portal SCL. In LAD/FBD, use DIV and MUL to calculate remainder.
Allen-Bradley (Studio 5000)
No native MOD; calculate using: Remainder = IN1 - (IN1/IN2)*IN2.
CODESYS
Use MOD operator in ST. Available as function block in some libraries.
Common Applications
- Cyclic lane distribution
- Even/odd detection
- Circular buffer indexing
- Periodic event triggering
- Time-of-day calculations
Frequently Asked Questions
What is MOD (Modulo) in PLC programming?
Returns the remainder after integer division of two values. The MOD (Modulo) function returns the remainder after integer division of the first input by the second input. MOD is useful for creating cyclic patterns, detecting even/odd values, implementing circular buffers, and distributing items across lanes.
What are common applications of MOD (Modulo)?
MOD (Modulo) is commonly used for: Cyclic lane distribution, Even/odd detection, Circular buffer indexing, Periodic event triggering, Time-of-day calculations.
How do I use MOD (Modulo) in different PLC platforms?
Siemens: Use MOD instruction in TIA Portal SCL. In LAD/FBD, use DIV and MUL to calculate remainder. Allen-Bradley: No native MOD; calculate using: Remainder = IN1 - (IN1/IN2)*IN2. CODESYS: Use MOD operator in ST. Available as function block in some libraries.
Related Function Blocks
DIV (Division)
Divides first input by second input, outputs the quotient.
View Reference →MUL (Multiplication)
Multiplies two numeric values and outputs the product.
View Reference →ADD (Addition)
Adds two or more numeric values and outputs the sum.
View Reference →SUB (Subtraction)
Subtracts second input from first input, outputs the difference.
View Reference →ABS (Absolute Value)
Returns the absolute (non-negative) value of the input.
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