Average Recent Measurements
medium
Averages the latest eight accepted measurements, using only received samples during warm-up.
What it teaches
A fixed window answers what happened recently. Build on Queue Parts for Processing to discard the oldest sample when a ninth arrives, then average the remaining eight. Writing each new reading over the oldest one, with a running total, gives the same answer without moving data. Zero is a reading like any other, and empty space must not drag the average down before the window fills.
Parameters
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| In_Sample | Input | BOOL | 0 | Request to accept In_Value |
| In_Value | Input | REAL | 12.5 | New finite measurement, magnitude at most 10000 |
| In_Reset | Input | BOOL | 0 | Discard the measurement history |
| Out_Count | Output | DINT | 0 | Number of valid readings, saturating at 8 |
| Out_Mean | Output | REAL | 0 | Average of the valid window, or 0 when empty |
| Sts_Ready | Output | BOOL | 0 | 1 once the window contains eight readings |
Required behavior
- On each rising In_Sample, accept In_Value once. Holding the request does not accept more readings.
- Retain the latest eight accepted readings. Before eight have arrived, average only the received readings. Zero and negative measurements are valid.
- Out_Count is the window count, at most 8. Out_Mean is its arithmetic mean. Sts_Ready is 1 exactly when Out_Count = 8.
- Without a new request, preserve the window and outputs even if In_Value changes. Internal storage layout is up to the implementation.
- In_Reset discards all history and clears all outputs every scan. Reset wins and consumes a simultaneous sample request; a held request must fall and rise before it can be accepted.