FB_BA_TiAvrg

FB_BA_TiAvrg 1:

The function block FB_BA_TiAvrg calculates the arithmetic mean value of an analog value that was logged over a certain period. Discrete values are written into a FIFO buffer. udiIntval_sec specifies the time interval [s] over which the values are logged and written into the FIFO. Values are written if the input bEn is TRUE. The variable udiNumOfElem is used to determine the size of the FIFO buffer. It is limited to 1..512.
The function block can be used for calculating an hourly mean outside temperature over a day, for example. In this case udiNumOfElem would be 24 and udiIntval_sec would be 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

 

First cycle

Second cycle

Third cycle

Fourth cycle

 

rIn

rOut

rIn

rOut

rIn

rOut

rIn

rOut

t0

2

2/1 = 2

6

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

1

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

3

rIn = 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

rIn = 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

 

 

VAR_INPUT

bEn           : BOOL;
rIn           : REAL;
udiIntval_sec : UDINT;
udiNumOfElem  : UDINT;

bEn: Enables the function block.

rIn: Input value for averaging.

udiIntVal_SEC: Time interval [s] for writing new values into the FIFO. Internally limited to a value between 1 and 2147483.

udiNumOfElem: Size of the FIFO buffer. A change resets the previous averaging. Internally limited to a value between 1 and 512.

VAR_OUTPUT

rOut       : REAL;
rMax       : REAL;
rMin       : REAL;

rOut: Calculated mean value.

rMax: Largest value in the FIFO buffer.

rMin: Smallest value in the FIFO buffer.

Requirements

Development environment

Required PLC library

TwinCAT from v3.1.4024.7

Tc3_BA from v1.1.6.0