Measuring procedure
A typical measuring procedure for determining the mass of a body consists of three main steps: filtering, scaling and evaluation.

1. Filtering
The signal from the EtherCAT Terminals of the ELM35xx and EL3356 series typically has a level of noise that requires filtering to ensure valid measurement results. The function block FB_WG_ComboFilter offers an effective solution for this by switching a combination of PTn, Moving Average and Notch filters in series. If these filter options are not sufficient, a selection of further filters from the TwinCAT 3 filter library is available.
2. Scaling
The filtered input signal must then be scaled in order to specify the weight in the desired unit (e.g. grams [g]). Scaling is performed by the function block FB_WG_Scaling. Accurate measurement also requires calibration of the PLC function block, which can be carried out using a two-point calibration, for example.
3. Evaluation
In the final step, the scaled signal is analyzed using the function block FB_WG_Weighing. It is necessary to provide the configuration structure ST_WG_Weighing with the appropriate parameters. A key parameter in this structure is ST_WG_Weighing.nWindowLength, which defines the number of samples used to calculate the moving average - a variable also known as the window size. This parameter determines how many past values are used to calculate the outputs fWeight, fStd, fMin and fMax of the function block FB_WG_Weighing. Here, fWeight represents the average, fStd the standard deviation and fMin/fMax the minimum or maximum value of the last nWindowLength input values. A supplementary figure can illustrate these relationships.

To obtain additional results from the function block, such as bValidMeasurement, bNewResult, tLastResult, fLastWeight and fLastStd, it is necessary to configure the substructure ST_WG_Weighing_Validation accordingly.
Within ST_WG_Weighing_Validation, the parameters fThresholdWeight, fMaxWeightDeviation and fMaxStd define the criteria for a valid measurement. For a measurement to be considered valid, the following conditions must be met:
FB_WG_Weighing.fWeightmust be greater than or equal tofThresholdWeight.- The difference
FB_WG_Weighing.fMax - FB_WG_Weighing.fMinmust not exceedfMaxWeightDeviation. FB_WG_Weighing.fStdmust be less than or equal tofMaxStd.
These conditions must be met over the number of consecutive samples defined in nValidationSamples in order to set FB_WG_Weighing.bValidMeasurement to TRUE .
The measurement is initiated as soon as FB_WG_Weighing.fWeight exceeds the value of ST_WG_Weighing_Validation.fThresholdWeight for the first time. As long as FB_WG_Weighing.bValidMeasurement has the value TRUE , the weight (fWeight) with the smallest standard deviation (fStd) is searched for and continuously updated in FB_WG_Weighing.fLastWeight and in FB_WG_Weighing.fLastStd. If the parameter ST_WG_Weighing_Validation.fRelativeWeightLimit is defined, the measurement ends as soon as FB_WG_Weighing.fWeight falls below the value of fThresholdWeight * fRelativeWeightLimit . If this parameter is not set, the measurement ends when fWeight falls below fThresholdWeight .
At the end of the measurement, the timestamp is saved in FB_WG_Weighing.tLastResult and FB_WG_Weighing.bNewResult is set to TRUE for exactly one cycle. If FB_WG_Weighing.fWeight exceeds the value fThresholdWeight again, FB_WG_Weighing.fLastWeight is reset and a new measurement begins.
The following figure illustrates the process described above and shows the relationship between the parameters and the conditions for a valid measurement:

ST_WG_Weighing_AutoTare can be configured in the same way as ST_WG_Weighing_Validation to receive results such as fAutoTareOffset and bNewAutoTareResult from the function block. These are essential for automatically taring the function block FB_WG_Scaling, for example by calling AutoTare(fbScaling,E_WG_AutoTareType.eEnd).
The parameters fThresholdWeight, fMaxWeightDeviation and fMaxStd in ST_WG_Weighing_AutoTare define the criteria for the validation of a measurement. A measurement is considered valid if:
FB_WG_Weighing.fWeightdoes not exceed the valuefThresholdWeight.- The difference
FB_WG_Weighing.fMax - FB_WG_Weighing.fMindoes not exceed the specifiedfMaxWeightDeviation. FB_WG_Weighing.fStdis less than or equal to the definedfMaxStd.
The update of fAutoTareOffset begins as soon as fWeight falls below fThresholdWeight for the first time and the stated conditions are met over a series of consecutive samples defined in nValidationSamples . The system searches for the weight with the lowest standard deviation and updates continuously fAutoTareOffset.
The measurement ends as soon as FB_WG_Weighing.fWeight exceeds fThresholdWeight. FB_WG_Weighing.bNewAutoTareResult is then set once to TRUE , which signals the end of the measurement. If FB_WG_Weighing.fWeight falls below the threshold value fThresholdWeight,, FB_WG_Weighing.fAutoTareOffset is reset and a new measurement is initiated.
The figure below illustrates the process and clarifies the relationship between the parameters and the criteria for a valid measurement.
