Modulo (MOD)
When enabled, the MOD instruction and the operator divides Source A by Source B and places the remainder in Dest. This is done using the algorithm:
Dest = Source A – (truncate ( Source A / Source B) * Source B)
Available Languages
Ladder Diagram
Operands
IMPORTANT:
Unexpected operation may occur if:
- Output tag operands are overwritten
- Members of a structure operand are overwritten
- Except when specified, structure operands are shared by multiple instructions.
There are data conversion rules for mixing numeric data types within an instruction. See Data conversions.
Ladder Diagram
These are the operands for Ladder Diagram.
Operand | Data Type | Format | Description |
---|---|---|---|
Source A | SINT INT DINT LINT USINT UINT UDINT ULINT REAL LREAL | immediate tag | Value of the dividend. |
Source B | SINT INT DINT LINT USINT UINT UDINT ULINT REAL LREAL | immediate tag | Value of the divisor. |
Dest | SINT INT DINT LINT USINT UINT UDINT ULINT REAL LREAL | tag | Tag to store result of the instruction. |
Affects Math Status Flags
See Math status flags.
Major/Minor Faults
A minor fault will occur if: | Fault Type | Fault Code |
---|---|---|
Source B = 0 | 4 | 4 |
See Index through arrays for array-indexing faults.
Execution
Ladder Diagram
Condition/State | Action Taken |
---|---|
Prescan | N/A |
Rung-condition-in is false | Set Rung-condition-out to Rung-condition-in |
Rung-condition-in is true | Set Rung-condition-out to Rung-condition-in Dest is set (to the remainder) as described in the Description section. |
Postscan | N/A |
Examples
Ladder Diagram
Divide dividend by divisor and place the remainder in remainder. In this example, 3 goes into 10, three times, with a remainder of 1.
Provide Feedback