The attached download "STEP7_V11_Average" includes a STEP 7 project with the function block FB1. You can use this block to calculate a current arithmetic average value from any number of values read in. Fig. 01 shows the call and parameters of the FB1 in OB1.
Input parameters of FB1 "Average"
- "Reset" with the data type: Bool
The default value is False. If the "Reset" input receives the value True, the block is reset and the "Average" receives the value Zero.
- "Value" with the data type: Real
This parameter is for reading in the input values from which the current average value is calculated.
- "By_Value_Change" with the data type: Bool
Defines the mode for calculating.
- True: the block calculates the new average value only if the "Value" parameter changes.
- False: the average value is recalculated each cycle.
Output parameters of FB1 "Average"
- "Average" with the data type: Real. Returns the arithmetic average value calculated.
In the case of input values read in consecutively, the current arithmetic average is recalculated for each sum when the value of the "Value" parameter changes. The division denominator for calculating the average value increments by the value "1" for each input value read in.
||X1 / 1|
||(X1+X2) / 2|
||(X1+X2+X3) / 3|
||(X1+X2+X3+ ... Xn) / n|
Table 02 shows an example of five values read in one after the other. The average value is calculated upon input of the fifth value "14.0":
- Average value = (5.0+3.0+1.0+7.0+14.0) / 5 = 6
||5 / 1 = 5,0|
||8 / 2 = 4,0|
||9 / 3 = 3,0|
||16 / 4 = 4,0|
||30 / 5 = 6,0|
The average value is also calculated when the value at the "Value" input is zero. Cyclic interrupts or a call in OB1 are suitable for the FB1's runtime level.
The attached download contains a STEP 7 project with the blocks described above (FB1, instance DB1 and OB1).
STEP7_V11_Average.zip ( 1500 KB )
Copy the "STEP7_V11_Average.zip" file into a separate directory and then start the file with a double-click. The STEP 7 V11 project is now unpacked automatically with all the associated subdirectories. You can then use STEP 7 V11 + SP2 to open and process the extracted project.
The screens and downloads in this FAQ response were created with STEP 7 V11 + SP2. The table below lists the components that have been used to create this entry and verify the functions described.
||Intel(R) Core(TM)2 Duo CPU P8700 2.53 GHz|
|PC operating system
||MS Windows XP SP3|
|STEP 7 (TIA Portal)
||V11 + SP2|
|CPU 1214C (6ES7214-1AE30-0XB0)