F40_BADD

4-digit BCD addition

The 4-digit BCD equivalent constant or 16-bit area for 4-digit BCD data specified by s and the 16-bit area for 4-digit BCD data specified by d are added together if the trigger EN is in the ON-state. The result is stored in d.

Parameters

Input

s (WORD)

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

Output

d (WORD)

Augend and result, 16-bit area for 4-digit BCD data

Example

  1.  (1) Example value 16#2111 (BCD)
  2.  (2) Example value 16#0011 (BCD)
  3.  (3) Result value 16#2122 (BCD) if trigger is ON

Remarks

Instead of using this F instruction, we recommend using the corresponding FP7 instruction: FP_ADD_BCD

NOTE

When this instruction is used, the area for the augend d is overwritten by the added result. If you want to avoid the overwrite, we recommend using the instruction F41_DBADD.

Error flags

sys_bIsEqual (turns to TRUE for one scan)

if the calculated result is 0.

sys_bIsCarry (turns to TRUE for one scan)

if the result exceeds the range of 4-digit

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 function*)
		summand: WORD:=16#2111;
			(*this value will be added
to the output_value*)
		output_value: WORD:=16#0011;
			(*result after 0->1 leading
edge from start: 16#2122*)
	END_VAR

LD body

When the variable start changes from FALSE 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,3,2,5,4,R);
B(B_F,F40_BADD!,Instance,9,1,15,5,,?DEN?D@'s'?AENO?Cd);
B(B_VARIN,,summand,7,3,9,5,);
B(B_VAROUT,,output_value,15,3,17,5,);
L(1,0,1,6);
L(1,3,3,3);
L(5,3,9,3);
        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
    F40_BADD(summand, output_value);
END_IF;

IL body

LD

start

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

F40_BADD

summand, output_value

(* s = summand (source) *)

(* d = output_value (destination) *)

(* s + d = d *)

ST

out

(* option *)

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