Calculate total and mean numbers in data table of DINT numbers
This FP instruction calculates the sum and the arithmetic mean of positive and negative DINT numbers in the data table specified by s1_Start and s2_End. The sum of all elements in the data table is returned at output d1_Sum and the arithmetic mean of all elements in the data table is returned at output d2_Mean. The arithmetic mean is rounded off if it is not a whole number.
Input
Beginning of data table
End of data table
Output
Sum of all elements in data table area specified
Mean of all elements in data table area specified
if the area specified using the index modifier exceeds the limit.
if s1_Start>s2_End
if s1_Start and s2_End belong to different data areas.
if the area specified using the index modifier exceeds the limit.
if s1_Start>s2_End
if s1_Start and s2_End belong to different data areas.
Corresponding F instructions: F275_MEAN, F276_DMEAN, F352_FMEAN
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
diMean: DINT:=0;
(*the arithmetic mean of all elements of data_array; here: 2*)
adiSum: ARRAY [0..1] OF DINT:=[2(0)];
(*the sum of all elements of data_array; here: 6*)
adiDataField: ARRAY [0..2] OF DINT:=[3,-1,4];
bStart: BOOL:=FALSE;
(*activates the function*)
END_VAR
When the variable bStart is set to TRUE, the function is carried out.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_CONTACT,,bStart,4,1,6,3,);
B(B_F,FP_DATA_MEAN_SUM_DINT0!,,14,0,28,5,,?DEN?Ds1_Start?Ds2_End?AENO?Cd1_Sum?Cd2_Mean);
B(B_VARIN,,adiDataField[0],12,2,14,4,);
B(B_VAROUT,,adiSum,28,2,30,4,);
B(B_VARIN,,adiDataField[2],12,3,14,5,);
B(B_VAROUT,,diMean,28,3,30,5,);
L(1,0,1,5);
L(1,2,4,2);
L(6,2,14,2);
END_NETWORK_BODY
END_NET_WORK
END_BODY
if (bStart) then
FP_DATA_MEAN_SUM_DINT0(s1_Start := adiDataField[0],
s2_End := adiDataField[2],
d1_Sum => diSum,
d2_Mean => diMean);
End_if;