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
nDivider
: Specifies the downsampling factor as an integer divisor. For example, a sample rate of 10 kHz can be converted to a sample rate of 2 kHz withnDivider=5
.nChannels
: For downsampling a multi-channel data set, the number of channels is specified at inputnChannels
.
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 isTRUE
if an error occurs. -
hrErrorCode
: If an error occurs, a corresponding error code of the typeHRESULT
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.
- Return value: If an error occurs, a corresponding error code of the type
HRESULT
is output. Possible values are described in the List of error codes.
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
pDataIn
: The assigned input buffer.nDataInSize:
Specifies the size of the PLC input buffer and must meet the following condition:nChannels * nElementSize * „
Number of elements per channel".pDataOut
: The assigned output buffer must remain unchanged until the outputbNewResult
is set. Usually, input and output buffers are always maintained.nDataOutSize
: Specifies the size of the PLC output buffer and must meet the following condition:nDataOutSize = n * nDataInSize
. If the quotient is divisible by the parameternDivider
without remainder, the following condition can be used as an alternative:nDataOutSize = n * (nDataInSize/nDivider)
.nElementSize
: Specifies the size of an element in bytes. For an array of LREAL elements the size is 8, for example.bError
: The output isTRUE
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. This output is identical to the return value of the method.
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. |
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 |
Limited functional scope already available with CM 3.1. See section Compatibility. |