Korniman
This Filter make usage of 3 Analog Inputs then make the Average of it and then samples 100 inputs in a arrey and build the  Weighted Moving Average Filter

[203128%2F8583099%2Fmceclip0]
 
 
 
FUNCTION_BLOCK WeightedMovingAverageFilter
VAR_INPUT
Analog_In_1: UINT; 
Analog_In_2: UINT; 
Analog_In_3: UINT; 
Samples_Qty: DINT; 
END_VAR
VAR_OUTPUT
AVG_Out: UINT; 
WMAVG_Out: UINT; 
END_VAR
VAR
AVG_Sum: DINT; 
WMAVG_Input: DINT; 
Previous_Value_Array: ARRAY [1..100] OF DINT; 
Previous_Value_Index: DINT := 1; 
WMAVG_Sum: DINT := 0; 
END_VAR
 


 
(* Calculates the average of the input values and converts it to UINT *)
AVG_Out := DINT_TO_UINT(UINT_TO_DINT(Analog_In_1 + Analog_In_2 + Analog_In_3) / 3);
 
(* Converts the average to DINT type for use in weighted average *)
WMAVG_Input := UINT_TO_DINT(AVG_Out);
 
(* Updates the sum for the weighted average *)
WMAVG_Sum := WMAVG_Sum - Previous_Value_Array[Previous_Value_Index] + WMAVG_Input;
 
(* Stores the current input value in the array of previous values *)
Previous_Value_Array[Previous_Value_Index] := WMAVG_Input;
 
(* Calculates the weighted average and converts it to UINT *)
WMAVG_Out := DINT_TO_UINT(WMAVG_Sum / Samples_Qty);
 
(* Increases the index for the next position in the array of previous values *)
IF Previous_Value_Index < Samples_Qty THEN
Previous_Value_Index := Previous_Value_Index + 1;
ELSE

(* Resets the index to 1 if the array is full *)
Previous_Value_Index := 1;
END_IF;
 
[203128%2F8583104%2Fmceclip0]
Reply 2 0
Reply