FB_PMA_Frequency_Period_1Ph

The function block FB_PMA_Frequency_Period_1Ph calculates the base frequency of the given input signal. To do this, the signal is first filtered with a Butterworth low-pass filter. The zero crossings of the input signal are then determined from the filtered values, and the frequency is calculated from their difference. The results refer to one or more periods, depending on the configuration. The statistical results refer to the entire runtime or the time at which the statistical results were last reset.

The input buffer is provided via the function block FB_PMA_Source_1Ph. This can include one or more signal periods or individual fragments of oversampling arrays.

Syntax

Definition:

FUNCTION BLOCK FB_PMA_Frequency_Period_1Ph
VAR_INPUT
    nOwnID              : UDINT;
    tTransferTimeout    : LTIME := LTIME#500US;
    stInitPars          : ST_PMA_Frequency_Period_InitPars;
END_VAR
VAR_OUTPUT
    bError              : BOOL;
    ipResultMessage     : I_TcMessage;
    bNewResult          : BOOL;
    nCntResults         : ULINT; 
    fFreq               : LREAL;
    fFreq_Min           : LREAL;
    fFreq_Max           : LREAL;
    fRocof              : LREAL;
    bValidStatistics    : BOOL;
    bOutOfRange         : BOOL;
END_VAR

FB_PMA_Frequency_Period_1Ph 1: Inputs

The input parameters of this function block represent initialization parameters and have to be assigned during the declaration of the function block instance (alternatively: Init method). They may only be assigned once. A change at runtime is not possible.

Name

Type

Description

nOwnID

UDINT

Identifies the function block instance with a unique ID. This must always be greater than zero. A proven approach is to define an enumeration for this purpose.

tTransferTimeout

LTIME

Setting of the synchronous timeout for internal multi-array forwardings. See Parallel Processing in Transfer Tray.

stInitPars

ST_PMA_Frequency_Period_InitPars

Function block-specific structure with initialization parameters. The parameters must correlate to the above definition of the input and output buffers.

FB_PMA_Frequency_Period_1Ph 2: Outputs

Name

Type

Description

bError

BOOL

TRUE if an error occurs.

ipResultMessage

I_TcMessage

The interface offers detailed information about the return value.

bNewResult

BOOL

TRUE once new results have been calculated.

nCntResults

ULINT

Count value is incremented with new output data.

fFreq

LREAL

Frequency determined by two or more zero crossings.

fFreq_Min

LREAL

Smallest value of fFreq that has occurred. Can be reset via bResetStatistics of the Call method.

fFreq_Max

LREAL

Largest value of fFreq that has occurred. Can be reset via bResetStatistics of the Call method.

fRocof

LREAL

Rate of change of frequency (ROCOF).

bValidStatistics

BOOL

TRUE if the Min and Max value calculation has been performed. These values are valid.

bOutOfRange

BOOL

TRUE as soon as the input value or the frequency is not within the configured limits.

FB_PMA_Frequency_Period_1Ph 3: Methods

Name

Description

Call

The method is called in each cycle to execute the calculations from the input buffer when new data is present.

Init

Alternative to the function block initialization

PassInputs

As an alternative to the Call method, the method can be called in each cycle if no calculation is to take place. The incoming input buffer is then forwarded accordingly.

Reconfigure

The method is called in order to reconfigure the function block during the runtime.

Reset

The current calculations are reset with the method.

Sample

VAR CONSTANT
    cOversamples : UDINT := 10;
    cSourceInitPars: ST_PMA_Source_InitPars := (
        nBufferLength := cOversamples);
    cFrequencyInitPars : ST_PMA_Frequency_Period_InitPars := (
        nBufferLength := cOversamples,
        fSampleRate := cOversamples * 1000,
        fMinFreq := 45.0,
        fMaxFreq := 55.0,
        nPeriods := 1,
        nFilterOrder := 2,
        fCutOff := 70.0,
        eInputSelect := E_PMA_InputSelect.Voltage,
        fMinInput := 200.0);
END_VAR
VAR
    aVoltage AT%I* : ARRAY[1..cOversamples] OF LREAL;
    aCurrent AT%I* : ARRAY[1..cOversamples] OF LREAL;
    fbSource : FB_PMA_Source_1Ph := (nOwnID := 1, aDestIDs := [2], stInitPars := cSourceInitPars);
    fbFrequency : FB_PMA_Frequency_Period_1Ph := (nOwnID := 2, stInitPars := cFrequencyInitPars);
END_VAR
// Call source
fbSource.Call(ADR(aVoltage), ADR(aCurrent), SIZEOF(aVoltage), 0);

// Call algorithm
fbFrequency.Call(FALSE);

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4024.0

PC or CX (x86, x64)

Tc3_PowerMonitoring