Modulo (MOD)

This information applies to the CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, GuardLogix 5570, Compact GuardLogix 5380, CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, and GuardLogix 5580 controllers. Controller differences are noted where applicable.
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
MOD_LD_avail_v31
Function Block Diagram
Function Block Diagram supports these elements:
FBD Block
MOD_FBD_avail_v31
FBD Function
TIP:
FBD Function is applicable to CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers only.
MOD_FBD Func_avail lang
Structured Text
This instruction is not available in structured text.
TIP:
Use MOD as an operator in an expression to compute the same result. Refer to Structured Text Syntax for more information on the syntax of expressions and assignments within structured text.
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
CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers
Data Type
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Format
Description
Source A
SINT
INT
DINT
REAL
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
immediate
tag
Value of the dividend.
Source B
SINT
INT
DINT
REAL
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
immediate
tag
Value of the divisor.
Dest
SINT
INT
DINT
REAL
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
tag
Tag to store result of the instruction.
Function Block Diagram
FBD Block
Operand
Data Type
Format
Description
MOD
FBD_MATH
tag
MOD structure
FBD_MATH Structure
Input Members
Data Type
Description
EnableIn
BOOL
Enable input. If false, the instruction does not execute and outputs are not updated.
Default is true.
SourceA
REAL
Value of the dividend.
SourceB
REAL
Value of the divisor.
Output Members
Data Type
Description
EnableOut
BOOL
Indicates if the instruction executed without fault when it was enabled.
Dest
REAL
Result of the instruction.
FBD Function
TIP:
FBD Function is applicable to CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers only.
Input Operands (Left Pins)
Data Type
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Description
SourceA (top)
SINT
USINT
INT
UINT
DINT
UDINT
LINT
ULINT
REAL
LREAL
Value of the dividend.
SourceB (bottom)
SINT
USINT
INT
UINT
DINT
UDINT
LINT
ULINT
REAL
LREAL
Value of the divisor
Output Operand (Right Pin)
Data Type
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Description
Dest
DINT
UDINT
LINT
ULINT
REAL
LREAL
Result of the function.
Affects Math Status Flags
Controllers
Affects Math Status Flags
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Conditional
CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers
Yes
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
Function Block Diagram
FBD Block
Condition/State
Action Taken
Prescan
N/A
EnableIn is false
Set EnableOut to EnableIn
EnableIn is true
Dest is set (to the remainder) as described in the Description section.
If an overflow occurs
Clear EnableOut to false
else
Set EnableOut to true
Instruction first run
N/A
Instruction first scan
N/A
Postscan
N/A
FBD Function
TIP:
FBD Function is applicable to CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers only.
Condition/State
Action Taken
Prescan
N/A
Normal Scan
Dest is set (to the remainder) as described in the Description section.
Instruction first run
N/A
Instruction first scan
N/A
Postscan
N/A
TIP:
If Source B is 0, the result is 0 and a minor fault is generated.
Examples
Ladder Diagram
MOD_LD_ex_V31
Divide dividend by divisor and place the remainder in remainder. In this example, 3 goes into 10, three times, with a remainder of 1.
Function Block Diagram
FBD Block
L5K_MOD_FBD_ex_v31
FBD Function
MOD_fbd fun_ex_v32
Structured Text
remainder := dividend MOD divisor;
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.