:-[
I have to thankyou! I did not seen that function and your help is very appreciated. I just made a little change because after changing the N variable, I need to send a reset signal for a Plc cycle or the result is wrong.
(* limit N to size of buffer *)
N := MIN(N, SIZEOF(buffer)/4);
A_TRIG_N(IN:= UINT_TO_REAL(N), RES:= 0.5, Q=> rst, D=> );
(* startup initialisation *)
IF NOT init OR rst OR N = 0 THEN
init := TRUE;
FOR i := 0 TO UINT_TO_INT(N)-1 DO
buffer := X;
END_FOR;
sum := X * N;
Y := X;
ELSE
i := INC1(i, UINT_TO_INT(N));
sum := sum + X - buffer;
Y := sum / N;
buffer := X;
END_IF;
I have to thankyou! I did not seen that function and your help is very appreciated. I just made a little change because after changing the N variable, I need to send a reset signal for a Plc cycle or the result is wrong.
(* limit N to size of buffer *)
N := MIN(N, SIZEOF(buffer)/4);
A_TRIG_N(IN:= UINT_TO_REAL(N), RES:= 0.5, Q=> rst, D=> );
(* startup initialisation *)
IF NOT init OR rst OR N = 0 THEN
init := TRUE;
FOR i := 0 TO UINT_TO_INT(N)-1 DO
buffer := X;
END_FOR;
sum := X * N;
Y := X;
ELSE
i := INC1(i, UINT_TO_INT(N));
sum := sum + X - buffer;
Y := sum / N;
buffer := X;
END_IF;