Block that calculates the remainder of the values of Value1 and Value2, storing the result in Result.
Ladder Representation

Block Structure
Variable Type |
Name |
Data Type |
Description |
VAR_INPUT |
EN |
BOOL |
Block enabling |
Value1 |
BYTE USINT SINT WORD UINT INT DWORD UDINT DINT |
Dividend of the operation |
|
Value2 |
BYTE USINT SINT WORD UINT INT DWORD UDINT DINT |
Divisor of the operation |
|
VAR_OUTPUT |
Done |
BOOL |
End of operation |
Result |
BYTE USINT SINT WORD UINT INT DWORD UDINT DINT |
Variable that stores the result of the operation |
Operation
When this block has a TRUE value in EN, it sends to the Result output the remainder of Value1 and Value2 variables. If no errors, the Done variable is set. If there is any error in the operation, Done is not set, staying in FALSE status, while Result remains with its value unchanged.
When EN has FALSE value, Result remains unchanged and Done remains in FALSE.
Block Flowchart

Example

The above example calculates the remainder of VALUE 1 and VALUE2 variables, storing the final result in RESULT.

The above example calculates the remainder of VALUE 1 and VALUE2 variables, storing the final result in RESULT. Notice that the block accepts arguments of both signs.

The above example calculates the remainder of VALUE 1 and VALUE2 variables, storing the final result in RESULT. Since VALUE2 is zero, the block generates a runtime error, RESULT remains unchanged and the output is disabled.
Example in ST
The example below displays the instructions for applying the example above in the ST language.
VAR VALUE1 : SINT := 70; VALUE2 : SINT := -8; RESULT : SINT; END_VAR
RESULT := FB_MOD( EN:=DI1, Value1:=VALUE1, Value2:=VALUE2, Done=>DO1);
|
|---|