T_AVG

Calculates the average value of the process variable over the specified time period. The calculation of the time averaged value (PVavg) is time weighted and achieved through a method of sampling.
t_avg_block
Parameter values for the T_AVG function block:
Parameter
Data Type
Description
PV
REAL
Process variable having a REAL value. Infinity or Not a Number (NaN) values are not supported by this input.
Tp
TIME
Specified time period for calculating the average for PV.
Possible values range from 0ms to 23hr59m59s999ms.
Ts
TIME
Minimum time interval between samples of average values.
Collects new samples when the elapsed time since the last sample is >=Ts.
Possible values range from 0ms to 23hr59m59s999ms.
EN
BOOL
When TRUE, T_AVG calculates the average value of the process variable.
OUT
REAL
When EN is TRUE, PV=PVavg
On initialization, sets to PV. Recalculates the average value when collecting new samples on subsequent scans.
When EN is FALSE, sets to PV.
TIP: Each T_AVG instance can store a maximum of 64 samples. Exceeding the 64 samples may result in too few stored samples to support Tp. OUT sets to the time averaged value of the available samples.
When an overflow or underflow condition occurs during execution, the OUT sets to PV and the corresponding
ERRSTAT
Overflow or Underflow error counter increments.
Calculation of the Time Averaged Value (PVavg)
PVavg is calculated using this method:
  • Ns is the maximum number of stored samples (currently 64)
  • n is the current number of stored samples (1 <= n <= Ns)
  • PV[1], PV[2], ..., PV[n] are the values of the previous n samples (PV[1] is the least recent sample, PV[n] the most recent)
  • T[1], T[2], ...., T[n] are the times of the previous n samples (strictly increasing)
    TIP:
    If (T[n] - T[n-1]) < Tp then PVavg = PV else if there exists a natural number k such that:
    (T[n] - T[n-k]) >= Tp
    PVavg is calculated by method A.
    If no such k exists, then if n < Ns, PVavg is calculated by method B.
    If n = Ns, PVavg is calculated by method C.
Method A
PVavg =
(
( 0.5 * (PV[n] + PV[n-1]) * (T[n] - T[n-1]) ) +
( 0.5 * (PV[n-1] + PV[n-2]) * (T[n-1] - T[n-2]) ) +
...... +
( 0.5 * (PV[n-k+1] + PV[n-k]) * (T[n-k+1] - T[n-k]) )
)
/ (T[n] - T[n-k])
Method B
Calculating PVavg using this method assumes that before time T[1], PV[1] was constant longer than Tp.
PVavg =
(
( 0.5 * (PV[n] + PV[n-1]) * (T[n] - T[n-1]) ) +
( 0.5 * (PV[n-1] + PV[n-2]) * (T[n-1] + T[n-2]) ) +
...... +
( 0.5 * (PV[2] + PV[1]) * (T[2] - T[1]) ) +
( PV[1] * (Tp - (T[n] - T[1]) ) )
)
/ (Tp)
Method C
Use Method Cwhen requiring more than Ns samples to support Tp. Method C calculates the time averaged value over all Ns samples. This corresponds to an effective time period shorter than Tp.
PVavg =
(
( 0.5 * (PV[n] + PV[n-1]) * (T[n] - T[n-1]) ) +
( 0.5 * (PV[n-1] + PV[n-2]) * (T[n-1] + T[n-2]) ) +
...... +
( 0.5 * (PV[2] + PV[1]) * (T[2] - T[1]) )
)
/ (T[n] - T[1])
Function Block Diagram Example
t_avg_fbdexample
Structured Text Example
T_AVG(Process1, T#1m, IntervalT, Calculate); av_value := T_AVG.OUT;
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal