Reconfiguration with initial values

This sample shows how a filter can be reconfigured or dynamically adapted during runtime. It also describes how previous knowledge of a signal can be used to shorten the settling time of a filter after reconfiguration.

Download: Tc3_Filter_InitVals.zip (*.tnzip)

Description:

Observation:

The recording of the TwinCAT 3 Scope shows a signal curve that is very noisy and jumps between two levels.

Reconfiguration with initial values 1:
Signal curve of the input signal (red) and signal curves of the output signals (green FB_ContinuousFilter, blue: FB_DynamicFiltering)

The first filter described in the function block FB_ContinousFilter remains unchanged during runtime. The output signal of this filter is limited in its dynamics due to the low-pass effect.

The second filter, which is described in the function block FB_DynamicFiltering, responds dynamically to the variations of the input signal during runtime.

Reconfiguration with initial values 2:
Signal curve of the input signal (red) and signal curves of the output signals (green FB_ContinuousFilter, blue: FB_DynamicFiltering) (zoom into an edge)

The bTrigger input informs the fbDynamicLowPass instance of the FB_DynamicFiltering function block that there is a jump in the signal. In practice, this can be indicated by the signal itself or by an action initiated by the PLC.

If bTrigger is set to TRUE, the Configure() method is called, which sets the low-pass cut-off frequency to the maximum permitted value. This means that the low-pass effect is lost the next time the Call() method is called. However, the output signal can quickly follow the jump in the input signal.

Finally, the filter effect is reactivated by calling the Configure() method and greatly reducing the cut-off frequency.

In order to reduce the settling time of the filter considerably, previous knowledge about the two plateaus is used. To this end, the parameter pInitialValues of the configuration structure stParams (type ST_FTR_IIRSpec) is assigned the initial value 1 or 5. The values are defined in the MAIN program (fPreKnowledgeHigh, fPreKnowledgeLow) and reflect the user's knowledge that the signal to be evaluated will jump approximately between 1 and 5. The filter is thus already in the steady state around this value when the Call() method is called for the first time.

stParams.fCutoff := Main.fCutOff; // reduce cutoff freq. 

IF bRisingEdge THEN
    // on rising edge apply preknowledge (Signal around 5)
    bRisingEdge := FALSE;
    stParams.pInitialValues := ADR(fInitValHighLevel);
    stParams.nInitialValuesSize := SIZEOF(fInitValHighLevel);
ELSE
    // on falling edge
    stParams.pInitialValues := ADR(fInitValBaseLevel);
    stParams.nInitialValuesSize := SIZEOF(fInitValBaseLevel);
END_IF;

fbFilter.Configure(stConfig := stParams);

The time it takes to settle to the new plateau can be reduced significantly by event-based switching of the filter characteristics.

See also: