FP_DATA_MEAN_SUM_UDINT0

Calculate total and mean numbers in data table of UDINT numbers

This FP instruction calculates the sum and the arithmetic mean of UDINTnumbers 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 (UDINT)

Beginning of data table

s2_End (UDINT)

End of data table

Output

d1_Sum (ARRAY[0..1] OF UDINT)

Sum of all elements in data table area specified

d2_Mean (UDINT)

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*)
		audiDataField: ARRAY [0..4] OF UDINT:=[31111,42440,55555,61000,87778];
		udiSum: UDINT:=0;
			(*the sum of all elements of 
data_array; here: 161688*)
		uiMean: UINT:=0;
			(*the arithmetic mean of all
elements of data_array;
here: 32337*)
	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,,audiDataField[0],8,3,10,5,);
B(B_VARIN,,audiDataField[4],8,4,10,6,);
B(B_VAROUT,,udiSum,24,3,26,5,);
B(B_VAROUT,,uiMean,24,4,26,6,);
B(B_F,FP_DATA_MEAN_SUM_UDINT0!,,10,1,24,6,,?DEN?Ds1_Start?Ds2_End?AENO?Cd1_Sum?Cd2_Mean);
L(1,3,6,3);
L(8,3,10,3);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF bStart then
    FP_DATA_MEAN_SUM_UDINT0(s1_Start := audiDataField[0], 
                         s2_End := audiDataField[4], 
                         d1_Sum => udiSum, 
                         d2_Mean => udiMean);
END_IF;

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