FB_ALY_MovingAvg_1Ch

The Moving Average 1Ch calculates the moving average, the minimum and the maximum of the most recent input values in an interval of specified length. Furthermore the time values of minimum and maximum are shown. The calculation of the moving average depends on the configuration parameters Num Values and Startup Behaviour.

Syntax

Definition:

FUNCTION_BLOCK FB_ALY_MovingAvg_1Ch 
VAR_OUTPUT
    ipResultMessage: Tc3_EventLogger.I_TcMessage;
    bError: BOOL;
    bNewResult: BOOL;
    bConfigured: BOOL;
    fMovingAvg: LREAL;
    fMovingMin: LREAL;
    fMovingMax: LREAL;
END_VAR

FB_ALY_MovingAvg_1Ch 1: Outputs

Name

Type

Description

ipResultMessage

I_TcMessage

Contains more detailed information on the current return value. This special interface pointer is internally secured so that it is always valid/assigned.

bError

BOOL

This output is TRUE if an error occurs.

bNewResult

BOOL

When a new result has been calculated, the output is TRUE.

bConfigured

BOOL

Displays TRUE when the function block is successfully configured.

fMovingAvg

LREAL

Moving average value of the input value.

fMovingMin

LREAL

Moving minimum of the input value.

fMovingMax

LREAL

Moving maximum of the input value.

FB_ALY_MovingAvg_1Ch 2: Methods

Name

Definition location

Description

Call()

Local

Method for calculating the outputs for a specific configuration.

Configure()

Local

General configuration of the algorithm with its parameterized conditions.

Reset()

Local

Resets all internal states or the calculations performed so far.

SetChannelValue()

Local

Method for passing values to the algorithm.

Sample

VAR
    fbMovingAvg : FB_ALY_MovingAvg_1Ch;
    nNumValues : UDINT := 100;
    eStartupBehaviour : E_ALY_MovingAvgStartupBehaviour := E_ALY_MovingAvgStartupBehaviour.AvgOverExisting;
    bConfigure : BOOL := TRUE;
    nInput : INT;
END_VAR
// Configure algorithm
IF bConfigure THEN
    bConfigure := FALSE;

    fbMovingAvg.Configure(nNumValues, eStartupBehaviour);
END_IF

// Call algorithm
fbMovingAvg.SetChannelValue(nInput);
fbMovingAvg.Call();

Requirements

Development environment

Target platform

Plc libraries to include

TwinCAT v3.1.4024.0

PC or CX (x64, x86)

Tc3_Analytics