FB_ALY_SlopeAnalysis_1Ch

The Slope Analysis 1Ch calculates the slope between two values of the input stream. One of those two values is the current input value and the second value is the input value that occurred a defined number (configured by the parameter Num Values) of cycles before in the input stream. The difference between these two values is returned as Delta Value.

The corresponding distance on the time-coordinate is calculated as the difference of the timestamps of these two values and is provided as the output value Delta Time. Note that the value Delta Time is displayed in nanoseconds, but for the calculation of the slope it is scaled to a second as base unit.

The Slope is then calculated as the fraction of Delta Value and Delta Time (scaled to seconds) and estimates the gradient for the timestamp in the center of the two timestamps used in the calculation of Delta Time. This is the value returned as Time Slope if it corresponds to a timestamp of the input stream. For configurations, where Num Values is an uneven number there is no input value matching the exact centre timestamp. In this case the timestamp of the value that directly succeeded the calculated centre timestamp is returned as Time Slope.

Further, the algorithm provides the minimal slope, the maximal slope and the time values of minimum and maximum.

Syntax

Definition:

FUNCTION_BLOCK FB_ALY_SlopeAnalysis_1Ch
VAR_INPUT
    bPersistent: BOOL;
END_VAR
VAR_OUTPUT
    ipResultMessage: Tc3_EventLogger.I_TcMessage;
    bError: BOOL;
    bNewResult: BOOL;
    bConfigured: BOOL;
    fSlope: LREAL;
    fSlopeMin: LREAL;
    fSlopeMax: LREAL;
    fDeltaValue: LREAL;
    fbDeltaTime: FB_ALY_Timespan;
    fbTimeSlope: FB_ALY_DateTime;
    fbTimeSlopeMin: FB_ALY_DateTime;
    fbTimeSlopeMax: FB_ALY_DateTime;
END_VAR

FB_ALY_SlopeAnalysis_1Ch 1: Inputs

Name

Type

Description

bPersistent

BOOL

If the value is TRUE, the internal data is stored persistently.

FB_ALY_SlopeAnalysis_1Ch 2: 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.

fDeltaValue

LREAL

Difference of the values of the first and last element of the window.

fbDeltaTime

FB_ALY_Timespan

Difference of timestamp values of the first and last element of the window. It is scaled to seconds.

fSlope

LREAL

Division of fDeltaValue and fDeltaTime.

fSlopeMin

LREAL

Minimum occurred value of fSlope.

fSlopeMax

LREAL

Maximum occurred value of fSlope.

fbTimeSlope

FB_ALY_DateTime

Timestamp of the calculated slope. It is placed in the center of the configured window.

fbTimeSlopeMin

FB_ALY_DateTime

Timestamp of the last updated fSlopeMin.

fbTimeSlopeMax

FB_ALY_DateTime

Timestamp of the last updated fSlopeMax.

FB_ALY_SlopeAnalysis_1Ch 3:Methods

Name

Definition Location

Description

Call()

Local

Method calculates the outputs for a given configuration.

Configure()

Local

General configuration of the algorithm with its parameterized conditions.

Reset()

Local

Resets all internal states or the calculations made so far.

SetChannelValue()

Local

Method to pass values to the algorithm.

Sample

VAR
    fbSlopeAnalysis : FB_ALY_SlopeAnalysis_1Ch;
    fbSystemTime : FB_ALY_GetSystemTime;    
    nNumValues : UDINT := 200;
    bConfigure : BOOL := TRUE;
    nInput : INT;
END_VAR
// Configure algorithm
IF bConfigure THEN
    bConfigure := FALSE;

    fbSlopeAnalysis.Configure(nNumValues);
END_IF

// Get current system time
fbSystemTime.Call();

// Call algorithm
fbSlopeAnalysis.SetChannelValue(nInput);
fbSlopeAnalysis.Call(fbSystemTime.tSystemTime);

Requirements

Development environment

Target platform

Plc libraries to include

TwinCAT v3.1.4024.0

PC or CX (x64, x86)

Tc3_Analytics