AVERAGE
Stores a value at each cycle and calculates the average value of all stored values. 

Arguments | ||
---|---|---|
RUN | BOOL | TRUE=run / FALSE=reset |
XIN | REAL | Any real variable |
N | DINT | Application defined number of samples |
XOUT | REAL | Running average of XIN value |
Only the latest N values are stored.
The maximum number of samples N is 128. When N exceeds 128, the number of samples is truncated to 128.
When the "RUN" command is FALSE (reset mode), the output value is equal to the input value.
Upon reaching the maximum N of stored values, the first stored value is overwritten with the latest value.
TIP:
When setting or changing the value for N, set RUN to
FALSE, then set it back to TRUE.
Example
(* FBD program using the AVERAGE block: *)

(* ST Equivalence: AVERAGE1 instance of AVERAGE block *)
AVERAGE1((auto_mode & store_cmd), sensor_value, 100);
ave_value := AVERAGE1.XOUT;
Provide Feedback