Data division with remainder
This FP instruction divides the data specified by s1 by s2 if the trigger EN is TRUE. The integer quotient is stored in d1_Div and the remainder in d2_Mod.
Input
Dividend
Divisor
Output
Integer quotient
Remainder
You can only use the data types UINT and UDINT with FP7 PLCs.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
bStart: BOOL:=FALSE;
(*activates the fuction*)
diDividend: DINT:=16908416;
(*dividend*)
diDivisor: DINT:=58973;
(*divisor*)
diResult: DINT:=0;
(*result after a 0->1 leading
edge from start: 286*)
diRemainder: DINT:=0;
(*remainder*)
END_VAR
When the variable bStart is set to TRUE, the function is carried out.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_F,FP_DIV_MOD!,,13,1,21,6,,?DEN?D@'s1'?Ds2?AENO?Cd1_Div?Cd2_Mod);
B(B_CONTACT,,bStart,8,2,10,4,);
B(B_VARIN,,diDividend,11,3,13,5,);
B(B_VARIN,,diDivisor,11,4,13,6,);
B(B_VAROUT,,diResult,21,3,23,5,);
B(B_VAROUT,,diRemainder,21,4,23,6,);
L(1,3,8,3);
L(10,3,13,3);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
If (bStart) then
FP_DIV_MOD(s1 := diDividend, s2 := diDivisor, d1_Div => diResult, d2_Mod => diRemainder);
End_if;