Add
This function adds the input variables IN1 + IN2 +... (up to 28 input contacts) and writes the addition result into the output variable.
Input
1st input: augend
2nd input: addend
Output
Output as input: sum
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).
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
LD |
enable |
E_ADD |
summand_1, summand_2, sum |
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.