FP_DATA_MEAN_SUM_INT

Calculate total and mean numbers in data table of INT numbers

This FP instruction calculates the sum and the arithmetic mean of positive and negative INT 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.

Parameters

Input

s1_Start (INT)

Beginning of data table

s2_End (INT)

End of data table

Output

d1_Sum (INT)

Sum of all elements in data table area specified

d2_Mean (INT)

Mean of all elements in data table area specified

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • 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.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • 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.

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
		bStart: BOOL:=FALSE;
			(*activates the function*)
		aiDataField: ARRAY [0..4] OF INT:=[2,3,6,-3,1];
		diSum: DINT:=0;
			(*the sum of all elements of 
data_array; here: 9*)
		iMean: INT:=0;
			(*the arithmetic mean of all
elements of data_array;
here: 1*)
	END_VAR

POU body

When the variable bStart is set to TRUE, the function is carried out.

LD body

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,,bStart,6,2,8,4,);
B(B_VARIN,,aiDataField[0],10,3,12,5,);
B(B_VARIN,,aiDataField[4],10,4,12,6,);
B(B_VAROUT,,diSum,25,3,27,5,);
B(B_VAROUT,,iMean,25,4,27,6,);
B(B_F,FP_DATA_MEAN_SUM_INT!,,12,1,25,6,,?DEN?Ds1_Start?Ds2_End?AENO?Cd1_Sum?Cd2_Mean);
L(8,3,12,3);
L(1,3,6,3);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF bStart then
    FP_DATA_MEAN_SUM_INT(s1_Start := aiDataField[0], 
                         s2_End := aiDataField[4], 
                         d1_Sum => diSum, 
                         d2_Mean => iMean);
END_IF;

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