FB_BA_TiAvrg
The function block FB_BA_TiAvrg calculates the average from a sequence of past input values.
The function acquires input values fIn at defined time intervals nIntval and calculates the average of the acquired values. After each time interval, a new average value fOut is available.
The values to be averaged are written to a FIFO memory. This memory is limited to a maximum of 512 entries nNumOfElem. After the time interval nIntval has elapsed, a new value is written to the memory and then the average value is formed. If the entries of the FIFO memory = nNumOfElem, the oldest entry is deleted so that a new value is included for the average calculation.
Interval | nNumOfElem | fIn | FIFO memory | fOut | fMax | fMin |
---|---|---|---|---|---|---|
1 | 5 | 2 | 2 / 1 | 2 | 2 | 2 |
2 | 5 | 4 | (4+2) / 2 | 3 | 4 | 2 |
3 | 5 | 5 | (5+4+2) / 3 | 3.667 | 5 | 2 |
4 | 5 | 6 | (6+5+4+2) / 4 | 4.25 | 6 | 2 |
5 | 5 | 7 | (7+6+5+4+2) / 5 | 4.8 | 7 | 2 |
6 | 5 | 9 | (9+7+6+5+4) / 5 | 6.2 | 8 | 2 |
7 | 5 | 14 | (14+9+7+6+5) / 5 | 8.2 | 14 | 2 |
8 | 5 | 1 | (1+14+9+7+6) / 5 | 7.4 | 14 | 1 |
9 | 5 | -4 | (-4+1+14+9+7) / 5 | 5.4 | 14 | -4 |
10 | 5 | -12 | ((-12)+(-4)+1+14+9) / 5 | 1.6 | 14 | -12 |
Inputs
VAR_INPUT
bEn : BOOL;
fIn : REAL;
nIntval : UDINT;
nNumOfElem : UDINT;
END_VAR
Name | Type | Description |
---|---|---|
bEn | BOOL | Enables the function block. FALSE means that the output variables have the value 0 and the content of the FIFO memory is deleted. |
fIn | REAL | Field with the values to be calculated. |
nIntVal | UDINT | Time interval [s] for writing new values into the FIFO. Internally limited to a value between 1 and 2147483. |
nNumOfElem | UDINT | Size of the FIFO buffer. A change resets the previous averaging. Internally limited to a value between 1 and 512. |
Outputs
Ausgänge
fOut : REAL;
fMax : REAL;
fMin : REAL;
END_VAR
Name | Type | Description |
---|---|---|
fOut | REAL | Calculated average |
fMax | REAL | Largest value in the FIFO buffer |
fMin | REAL | Smallest value in the FIFO buffer |
Requirements
Development environment | Required PLC library |
---|---|
TwinCAT from v3.1.4024.22 | Tc3_BA2 from v5.2.5.0 |