FB_BA_TiAvrg

Averaging over a time interval

FB_BA_TiAvrg 1:

Functional description

The function block FB_BA_TiAvrg calculates the arithmetic average of an analog value that was logged over a certain period. Discrete values are written into a FIFO buffer. udiIntval specifies the time interval [s] over which the values are logged and written into the FIFO. Values are only written if the input bEnAvrg is TRUE. The variable udiNumOfElem is used to determine the size of the FIFO buffer. It is limited to 1…256. If a value outside this limits is entered, the number is automatically set to a default value of 48. The actual number is output at the output udiStaNumOfElem for verification purposes.
The function block can be used for calculating an hourly mean outside temperature over a day, for example. In that case udiNumOfElem = 24 and udiIntval = 3600 seconds. bEn is the general enable of the function block. If bEn = FALSE, the FIFO buffer within the function block is deleted completely, and no data are recorded.

Example:

udiNumOfElem = 5

The area highlighted in pink indicates the phase, in which bEnAvrg is set to FALSE. No values are written into the FIFO, and the output value lrOut is maintained.

 

First cycle

Second cycle

Third cycle

Fourth cycle

 

lrIn

lrOut

lrIn

lrOut

lrIn

lrOut

lrIn

lrOut

t0

2

2/1 = 2

6

(4+6+7+7+6)/5 = 6

1

(7+6+5+4+1)/5 = 4.6

3

lrIn = 3

t1

4

(2+4)/2 = 3

5

(6+7+7+6+5)/5 = 6.25

2

(6+5+4+1+2)/5 = 3.6

1.5

lrIn = 1.5

t2

6

(2+4+6)/3 = 4

4

(7+7+6+5+4)/5 = 5.8

4

(5+4+1+2+4)/5 = 3.2

 

 

t3

7

(2+4+6+7)/4 = 4.75

2

(7+7+6+5+4)/5 =5.8

5

(4+1+2+4+5)/5 = 3.2

 

 

t4

7

(2+4+6+7+7)/5 = 5.2

1

(7+7+6+5+4)/5 =5.8

4

(1+2+4+5+4)/5 = 3.2

 

 

FB_BA_TiAvrg 2:

Inputs/outputs

VAR_INPUT

bEn          : BOOL;
bEnAvrg      : BOOL;
lrIn         : LREAL;
udiIntval    : UDINT;
udiNumOfElem : UDINT;

bEn: enable of the function block

bEnAvrg: enable averaging, bEnAvrg = TRUE activates logging, if bEnAvrg is FALSE, the calculated value remains at the output.

lrIn: input value for averaging

udiIntVal: time interval [s] for writing new values into the FIFO

udiNumOfElem: size of the FIFO buffer. A change resets the previous averaging. The number of values is automatically limited to 1..256.

VAR_OUTPUT

lrOut           : LREAL;
lrMax           : LREAL;
lrMin           : LREAL;
udiStaNumOfElem : UDINT;

lrOut: average value

lrMax: largest value in the FIFO buffer

lrMin: smallest value in the FIFO buffer

udiStaNumOfElem: number of entries in memory

Requirements

Development environment

Target system

required library

required supplement

TwinCAT 2.11 R3/x64

PC/CX

TcBA library from V1.0.0

TS8040 | TwinCAT Building Automation from V1.0.0