Average
This function block calculates the average of a specified number of input values.
Based on the formula
the following calculation has been implemented:
The function block supports three types of averages:
Type 1: Simple
The input signals are added up until the number of values is reached. After adding the last value, the average is calculated. The result is written to the Average-output. Then the input values will start to add up again. The previous average is shown at the output until the new result is calculated. The number of values that was specified in the parameter dialog is available on the ValNbr output.
Type 2: Simple triggered
At this type, the function block receives an additional Trigger input. As long as a HIGH-signal is set to this input, the incoming signals are summed up and the counter for the number of values is incremented. After that, in the first cycle with a LOW-signal on the Trigger-input, the average is calculated and output. The number of values is written to ValNbr. The previous values for the average and the number of values remain on the outputs until the new results are calculated.
Type 3: Moving
After starting the application, the incoming signals are summed up, until the entered number of values is reached. When the last signal is added, the average is calculated and written to the Average output. After that the average is calculated in every subsequent cycle using the stored previous signal values. The number of values that was specified in the parameter dialog is available on the ValNbr output.
The type of the average can only be set in Edit mode. The number of values can be entered in Edit mode (then the entered value is used by the class and all new created instances) and Run mode (the value is only used by the current instance).
If the type of the average is changed in the class, the same type is assigned to all existing instances of the function block. If the new type is the simple or the moving average, the number of values that was specified in the class is written to all instances.
The dialog cannot be opened during online observation.
Signals
Name | I/O | Type(s) | Function |
---|---|---|---|
Signal | I | FLOAT | Input signal |
Trigger | I | BIT | Activate the calculation |
Average | O | FLOAT | Average |
ValNbr | O | WORD | Number of values |
Comments
The calculation is performed with FLOAT values. Therefore precision problems may occur at wide dispersion of the input signal.