Sliding window average of a variable over a period of time using RTES

Variables

Analog Input : LEVEL

Registers :

R0017 LEVEL0
R0018 LEVEL1
R0019 LEVEL2
R0020 LEVEL3
R0021 LEVEL4
R0022 LEVEL5

R0028 AVERAGE

R0029 LEVELSX

R0030 LEVELS
R0031 LEVELTOP
R0032 LEVELVAR

Rules

RULE AVERAGE=(LEVEL0+LEVEL1+LEVEL2+LEVEL3+LEVEL4+LEVEL5)/6
RULE LEVEL0=LEVEL
RULE LEVELSX=LEVELSd9
SHIFT LEVELS=LEVELSX’d1
RULE LEVELTOP=17
RULE LEVELVAR=6

Notes

This example uses the SHIFT function. Whenever the expression associated with SHIFT changes from false to true, the registers referenced by the next two registers are shifted one position down. AVERAGE contains the average value of LEVEL over the last 6 readings.

Registers LEVEL0 through LEVEL5 must be consecutive.
Registers .LEVELS, LEVELTOP and LEVELSX must be consecutive.
LEVELTOP is set at register number for LEVEL0 (17)
LEVELVAR is set to the quantity of registers to be shifted
The delays (9 seconds+1 second) add up to a ten second period.