ADD

Add

This function adds the input variables IN1 + IN2 +... (up to 28 input contacts) and writes the addition result into the output variable.

Parameters

Input

Unnamed input (INT, DINT, UINT, UDINT, REAL, LREAL)

1st input: augend

Unnamed input (INT, DINT, UINT, UDINT, REAL, LREAL)

2nd input: addend

Output

Unnamed output (INT, DINT, UINT, UDINT, REAL, LREAL)

Output as input: sum

Remarks

  • All operands must be of the same data type.
  • This function can be expanded to a maximum of 28 input contacts, see also modifying elements.

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
		enable: BOOL:=FALSE;
		summand_1: INT:=0;
		summand_2: INT:=0;
		sum: INT:=0;
	END_VAR

In this example the input variables (summand_1, summand_2 and enable) have been declared. Instead, you may enter constants directly into the function (enable input e.g. for tests).

LD body

If enable is set (TRUE), summand_1 is added to summand_2. The result is written into sum.

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,E_ADD-2!,Instance,9,0,15,5,,?DEN?D?D?AENO?C);
B(B_VARIN,,summand_1,7,2,9,4,);
B(B_VARIN,,summand_2,7,3,9,5,);
B(B_VAROUT,,sum,15,2,17,4,);
B(B_CONTACT,,enable,4,1,6,3,);
L(1,2,4,2);
L(6,2,9,2);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

IL body

LD

enable

E_ADD

summand_1, summand_2, sum

NOTE
  • This function can be expanded to a maximum of 28 input contacts, see also modifying elements.
  • If more than two summands are necessary, you should ammend the IL accordingly:

    LD

    summand_1

    E_ADD

    summand_2, summand_3

    ST

    sum

    sum is always in the final position.

Modified on: 2022-08-23Feedback on this pagePanasonic hotline