FB_CMA_Downsampling

Downsampling of signal data through copying of the signal data from one PLC buffer to another PLC buffer (array).

A signal that is present as a buffer (e.g. an oversampling array), can be scanned with a rate that is reduced by an individual factor. Downsampling is a way of analyzing lower frequencies without having to increase the FFT length to maintain a high resolution.

Usually, a downsampling block is inserted in the Condition Monitoring analysis chain before an FB_CMA_Source.

Inputs and outputs

Input parameters

VAR_INPUT
    nDivider   : UDINT := 1;    // given input signal is sampled down by the specified divider. (1 = no downsampling)
    nChannels  : UDINT;         // number of channels in data buffer (=1:onedimensional dataset, >1:twodimensional dataset)
END_VAR

Output parameters

VAR_OUTPUT
    bError         : BOOL;                           // TRUE if an error occurs. Reset by next method call.
    hrErrorCode    : HRESULT;                        // '< 0' = error; '> 0' = info; '0' = no error/info
    ipErrorMessage : I_TcMessage := fbErrorMessage;  // Shows detailed information about occurred errors, warnings and more.
    nCntResults    : ULINT;                          // Counts outgoing results (MultiArrays were calculated and sent to transfer tray).
END_VAR
  • bError: The output is TRUE if an error occurs.
  • hrErrorCode: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
  • ipErrorMessage: Contains more detailed information on the current return value. Refer here to the section Error description and information. This special interface pointer is internally secured so that it is always valid/assigned.

Methods

Call():

Writes data from the input data buffer into the output data buffer. The output data buffer is full when bNewResult is set.

METHOD Call : HRESULT
VAR_INPUT
    pDataIn       : POINTER TO BYTE;  // address of data buffer (e.g. oversampling data)
    nDataInSize   : UDINT;            // size of data buffer in bytes
    pDataOut      : POINTER TO BYTE;  // address of result buffer
    nDataOutSize  : UDINT;            // size of data buffer in bytes
    nElementSize  : UDINT;            // Size of element type in bytes
END_VAR
VAR_OUTPUT
    bNewResult    : BOOL;             // TRUE every time when outgoing data buffer was calculated.
    bError        : BOOL;             // TRUE if an error occurs.
    hrErrorCode   : HRESULT;          // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
FB_CMA_Downsampling 1:

If a timeout occurs or no MultiArray buffer is available for the result, then neither the input data nor the result data are lost. They are forwarded on the next call.

FB_CMA_Downsampling 2:

A copy action is executed if an error occurs.

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4022.25

PC or CX (x86, x64)

Tc3_CM, Tc3_CM_Base

FB_CMA_Downsampling 3:

Limited functional scope already available with CM 3.1. See section Compatibility.