Infosys在阅读器中打开 / AI 翻译

TF3xxx - Measurement · 0 次阅读

Configuration of a filter with FB_FTR_IIRSpec

This sample shows how to configure a filter of type Butterworth with the function block FB_FTR_IIRSpec.

Download: Tc3_Filter_SimpleIIRSpec.zip (*.tnzip)

Description:

  • The sample project consists of a TwinCAT PLC project and a measurement project.
  • In the measurement project, two input signals and two output signals are configured in two axes.
  • The two input signals are generated synthetically via a function generator called in the PLC. They are harmonic signals (sine) with a frequency of 250 Hz for the first channel and 300 Hz for the second channel. The signals are processed by a Butterworth type filter. The implemented filter has a cut-off frequency of 250 Hz.
  • The MAIN PLC program is called by a task with a cycle time of 1 ms.

Implementation:

  • First, a structure stParams of type ST_FTR_IIRSpec is declared and initialized. The structure is used for parameterizing the function block FB_FTR_IIRSpec or for configuring the filter.
stParams : ST_FTR_IIRSpec := ( … )
  • An instance fbFilter of the function block FB_FTR_IIRSpec is then created. The structure stParams is transferred during instantiation.
fbFilter : FB_FTR_IIRSpec := (stConfig := stParams);
  • In the source code, the Call() method is called to execute the filter, and error checking variants are listed.
IF NOT fbFilter.bError THEN
    fbFilter.Call(ADR(aSignalBuffer), SIZEOF(aSignalBuffer),
                  ADR(aFilteredSignal), SIZEOF(aFilteredSignal));
ELSE
    // if on error state, do something
    nErrorCount := nErrorCount + 1;
    // e.g. check if filter is configured
    // IF fbFilter.bConfigured THEN
    // or use ipResultMessage to check root cause
    // fbFilter.ipResultMessage
END_IF;
  • The Configure() and/or Reset() methods are also called to change the filter configuration during runtime (fbFilter.Configure) or to perform a reset (fbFilter.Reset). The call of the methods is controlled by the flags bReconfigure and bReset. They can be manually set to TRUE or FALSE in the Online Watch.

Observation:

Recording with TwinCAT 3 Scope shows that the amplitude of the output signals is attenuated and phase-shifted by the filter. The signal in the second channel (green) is attenuated more strongly than that in the first channel (blue, attenuation by -3 dB).

Configuration of a filter with FB_FTR_IIRSpec 1:Fig.1: Signal curves of the input signals (top) and the output signals (bottom) (blue: channel 1, green: channel 2)

If the flag bReconfigure is set, the cut-off frequency is shifted to 50 Hz, which makes the amplitude of both output signals even smaller.

Configuration of a filter with FB_FTR_IIRSpec 2:Fig.2: Signal curves of the input signals (top) and the output signals (bottom), if the flag bReconfigure is set (blue: channel 1, green: channel 2)

If the flag bReset is set, the internal state of the filter is deleted, i.e. past input and output values are no longer taken into account. The continuous signal curve is interrupted (at approx. 27 ms), and the filter settles again.

Configuration of a filter with FB_FTR_IIRSpec 3:Fig.3: Signal curves of the input signals (top) and the output signals (bottom) when the flag bReset is set (blue: channel 1, green: channel 2)

See also: