FP_DIV_MOD

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.

Parameters

Input

s1 (INT, DINT, UINT, UDINT)

Dividend

s2 (INT, DINT, UINT, UDINT)

Divisor

Output

d1_Div (INT, DINT, UINT, UDINT)

Integer quotient

d2_Mod (INT, DINT, UINT, UDINT)

Remainder

Remarks

You can only use the data types UINT and UDINT with FP7 PLCs.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the area specified using the index modifier exceeds the limit.
  • if 0 is specified for s2.
sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the area specified using the index modifier exceeds the limit.
  • if 0 is specified for s2.
Related topics:

Example

POU header

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

LD body

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

ST body

If (bStart) then
    FP_DIV_MOD(s1 := diDividend, s2 := diDivisor, d1_Div => diResult, d2_Mod => diRemainder);
End_if;

Modified on: 2019-04-05Feedback on this pagePanasonic hotline