AverageTimeCal (FB)

FUNCTION_BLOCK AverageTimeCal

Short Description

Averaging of an analog value over four different time periods
Mean value formation: Weighted mean value (see formula below)
Typical application: Averaging over time of the outside temperature

Portrayal

../_images/AverageTimeCal_FB.png

Interfaces

Inputs

Name

Datatype

Range

Init-Value

Function

rIn REAL    

Analog value input

Outputs

Name

Datatype

Range

Init-Value

Function

rOutCH0 REAL    

Average value for time period 1

rOutCH1 REAL    

Average value for time period 2

rOutCH2 REAL    

Average value for time period 3

rOutCH3 REAL    

Average value for time period 4

rOutMin REAL    

Minimum value of all measured values

rOutMax REAL    

Maximum value of all measured values

dtLastNewValue DATE_AND_TIME    

Save time of the last measured value

sErr STRING    

Current error text

Setpoints / Parameters

Name

Datatype

Range

Init-Value

Function

xCalculation BOOL   TRUE

Enable / disable data recording

xResetOnInput BOOL   FALSE

Initialization of the measured value memory and the average value outputs with rIn.

rInitValue REAL   10

Initialization value for the measured value memory and the average value outputs with eInitial = eInit2. InitValue.

tInitDelay TIME   5s

Delay time for saving measured values with eInitial = eInit2. InputValueDelayed.

eInitial eInit2   eInit2.LastValue

Definition of the type of initialization

wCH3Time WORD   48

Definition of the time period 4 in hours

wCH2Time WORD   36

Definition of the time period 3 in hours

wCH1Time WORD   24

Definition of the time period 2 in hours

wCH0Time WORD   12

Definition of the time period 1 in hours

wInterval WORD   15

Setting the recording interval in minutes

Functional description

General

Mean value formation

The value at the rIn analog value input is recorded in the iInterval recording interval (default = 15 minutes).
For the calculation of the mean value of a time period X (X = 0 ... 3), three factors are now determined in each case.


Factor 1 - Time period X: Total number of measured values ​​to be taken into account

Factor 1 = ( iCHXTime * 60 ) / iInterval


Factor 2 - Time period X: Factor for the saved average

Factor 2 = ( Factor 1 - 1 ) / Factor 1


Factor 3 - Time period X: Factor for the current value at the iIn analogue value input

Factor 3 = 1 - Factor 2


The mean value of each time period is calculated in the iInterval recording interval according to the following formula and transferred to the
average value outputs:


Mean value = (Mean value before * Factor 2) + ( rIn * Factor 3)


Legend: X =0 .. 3

Example

iInterval = 15 minutes, wCH0Time = 12 hours, Mean value before = 20.0, rIn = 22.0

Factor 1 = 48

Factor 2 = 47 / 48

Factor 3 = 1 / 48

Mean value = 20.041

rOutCHX Average value outputs ( X = 0 ... 3 )

At the rOutCHX average value output (X = 0 ... 3), the mean value of the recorded input values ​​is available for the first time after the iCHXTime time period.

rOutMin minimum value output

At the rOutMin minimum value output, the absolute minimum value of all recorded input values ​​is available for the first time after an iInterval
recording interval.

rOutMax maximum value output

At the rOutMax maximum value output, the absolute maximum value of all recorded input values ​​is available for the first time after an iInterval recording interval.
recording interval.

dtLastNewValue time stamp

At the dtLastNewValue* time stamp output, the time stamp of the last filing is available in the measured value memory for the first time after an iInterval recording interval.
recording interval.

sErr error text

At the sErr output for the current error text, a descriptive text is available in case of error. If there is no error, an empty string is the output.

eInitial type of initialisation

This set-point / parameter will define the type of initialisation of the measured value memory and the average value outputs.

Type

Initialization value

Notes

eInit2.InitValue rInitValue

Configurable initial value

eInit2.InputValue rIn

Input value

eInit2.InputValueDelayed rIn

Delayed input value

eInit2.LastValue

Average - measured value memory (measured value memory filled)

Last Value

eInit2.LastValue

rIn (measured value memory empty)

Last Value

Enable / disable data recording xCalculation

This data recording is enabled (= TRUE) or disabled (= FALSE) with this set-point / parameter

**xResetOnInput**reset of the measured value memory / the average value outputs

With this set-point / parameter, the measured value memory / the average value outputs are reset to the ‘rIn’ value (= TRUE).

Visualization




Information

Element

Authors

Date

Version

Note

Function

Adam Bartod 06.2016 1.0

Initial version

Programming

Adam Bartod 06.2016 1.0

Initial version

Test   12.2016 1.0

Initial version

Documentation

Jochen Reu 11.2017 1.0

Initial version

Codesys

InOut:
Scope Name Type Initial Comment
Input rIn REAL  

Analog value input

xCalculation BOOL TRUE

Enable / disable data recording

xResetOnInput BOOL FALSE

Initialization of the measured value memory and the average value outputs with rIn.

rInitValue REAL 10

Initialization value for the measured value memory and the average value outputs with eInitial = eInit2. InitValue.

tInitDelay TIME TIME#5s0ms

Delay time for saving measured values with eInitial = eInit2. InputValueDelayed.

eInitial eInit2 eInit2.LastValue

Definition of the type of initialization

wCH3Time WORD 48

Definition of the time period 4 in hours

wCH2Time WORD 36

Definition of the time period 3 in hours

wCH1Time WORD 24

Definition of the time period 2 in hours

wCH0Time WORD 12

Definition of the time period 1 in hours

wInterval WORD 15

Setting the recording interval in minutes

Output rOutCH0 REAL  

Average value for time period 1

rOutCH1 REAL  

Average value for time period 2

rOutCH2 REAL  

Average value for time period 3

rOutCH3 REAL  

Average value for time period 4

rOutMin REAL  

Minimum value of all measured values

rOutMax REAL  

Maximum value of all measured values

dtLastNewValue DT  

Save time of the last measured value

sErr STRING  

Current error text