F52_BDIV

4-digit BCD division, destination can be specified

The 4-digit BCD equivalent constant or the 16-bit area for 4-digit BCD data specified by s1 is divided by the 4-digit BCD equivalent constant or the 16-bit area for 4-digit BCD data specified by s2 if the trigger EN is in the ON-state.

Parameters

Input

s1 (WORD)

Dividend, 16-bit area for BCD data or 4-digit BCD equivalent constant

s2 (WORD)

Divisor, 16-bit area for BCD data or 4-digit BCD equivalent constant

Output

d (WORD)

Quotient, 16-bit area for BCD data (remainder stored in the system variable sys_iDivRemainder

Example

  1.  (1) Example value 16#0037 (BCD)
  2.  (2) Example value 16#0015 (BCD)
  3.  (3) Result value 16#0002
  4.  (4) Remainder 16#0007
  5.  (5) Trigger: ON

Remarks

The quotient is stored in the area specified by d and the remainder is stored in the system variable sys_iDivRemainder.

Error flags

sys_bIsEqual (turns to TRUE for one scan)

if the calculated result is 0.

Related topics:

BCD data

Instead of using this F instruction, we recommend using the corresponding FP7 instruction: FP_MOD_BCD, FP_DIV_MOD_BCD, FP_DIV_BCD

System instructions

Instructions pane

Memory areas

Data types

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
		start: BOOL:=FALSE;
			(*activates the fuction*)
		dividend: WORD:=16#0037;
			(*dividend*)
		divisor: WORD:=16#0015;
			(*divisor*)
		output_value: WORD:=0;
			(*result after 0->1 leading edge
from start: 16#0002*)
	END_VAR

LD body

When the variable start 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_CONTACT,,start,5,1,7,3,);
B(B_VARIN,,dividend,7,2,9,4,);
B(B_VARIN,,divisor,7,3,9,5,);
B(B_VAROUT,,output_value,15,2,17,4,);
B(B_F,F52_BDIV!,Instance,9,0,15,5,,?DEN?D@'s1'?Ds2?AENO?Cd);
L(1,2,5,2);
L(7,2,9,2);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 6 ;
        NETWORK_BODY
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 6 ;
        NETWORK_BODY
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF start then
    F52_BDIV(dividend, divisor, output_value);
END_IF;

IL body

LD

start

(* EN = start; Starting signal for the F52_BDIV function. *)

F52_BDIV

dividend, divisor, output_value

(* s1 = dividend (source1) *)

(* s2 = divisor (source2) *)

(* d = output_value (destination) *)

(* s1 / s2 = d *)

ST

out

(* option *)

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