FP_DIV_MOD_BCD

BCD data division with remainder

This FP instruction divides the BCD 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 (WORD, DWORD)

Dividend

s2 (WORD, DWORD)

Divisor

Output

d1_Div (WORD, DWORD)

Integer quotient

d2_Mod (WORD, DWORD)

Remainder

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.
  • if data other than BCD data is specified.
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.
  • if data other than BCD data is specified.

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*)
		dwDividend: DWORD:=16#442201;
			(*dividend*)
		dwDivisor: DWORD:=16#2;
			(*divisor*)
		dwResult: DWORD:=0;
			(*result after a 0->1 leading
edge from start: 16#221100*)
		dwRemainder: DWORD:=0;
			(*remainder: 16#1*)
	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 := 7 ;
        NETWORK_BODY
B(B_CONTACT,,bStart,4,2,6,4,);
B(B_VAROUT,,dwDividend,9,4,11,6,);
B(B_VARIN,,dwDivisor,6,4,8,6,);
B(B_VAROUT,,dwResult,18,3,20,5,);
B(B_F,FP_DIV_MOD_BCD!,,8,1,18,6,,?DEN?D@'s1'?Ds2?AENO?Cd1_Div?Cd2_Mod);
B(B_VAROUT,,dwRemainder,18,4,20,6,);
B(B_VARIN,,dwDividend,6,3,8,5,);
L(1,3,4,3);
L(6,3,8,3);
L(1,0,1,7);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF (bStart) then
    FP_DIV_MOD_BCD(s1 := dwDividend, 
                   s2 := dwDivisor, 
                   d1_Div => dwResult, 
                   d2_Mod => dwRemainder);
END_IF;

Modified on: 2019-01-15Feedback on this pagePanasonic hotline