show the entry list
STEP 7 (TIA Portal) -- Creating S7 programs -- Creating program sequences
How can you migrate alarms in the TIA Portal from the S7-300/400 to the S7-1500?
In STEP 7 (TIA Portal) V12, why do you have to insert a SET instruction after a jump command in order to ensure a first scan?
Where in STEP 7 (TIA Portal) V11 is there a program for the S7-1200 that lets different bit patterns rotate or flash under time control?
Recommended programming for S7-1200 and S7-1500 with STEP 7 (TIA Portal) V12
In STEP 7 (TIA Portal) V11, how do you calculate a current arithmetic average value from any number of values read in?
In STEP 7 (TIA Portal) V11, how do you calculate the minimum and maximum limit values for a temperature range?
How do you convert degrees into radians and vice versa in STEP 7 (TIA Portal) V11?
In STEP 7 (TIA Portal) V11, how can you buffer the return values from the "RETVAL" parameter consecutively in a DB?
How do you calculate in STEP 7 (TIA Portal) V11 the distance "D" between two points in a rectangular coordinate system?
How do you define a setpoint value with ramp function in STEP 7 (TIA Portal) V11?
How do you establish a MODBUS-RTU communication with STEP 7 (TIA Portal) for the SIMATIC S7-1200?
In STEP 7 (TIA Portal) V11 how can you invert an output signal of the "Bool" data type after each positive edge?
In STEP 7 (TIA Portal) V11, how can you count forwards and backwards in a bandwidth between -2147483648 and +2147483647?
How can you process 64-bit floating-point numbers in STEP 7 V11 with a SIMATIC S7-300/400 CPU?
In STEP 7 (TIA Portal) V11, how do you calculate a current arithmetic average value from any number of values read in?
Part number:

Instructions
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.


Fig. 01

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.

Program description
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.
 
No. Value Average value
1 X1) X1 / 1
2 X2) (X1+X2) / 2
3 X3) (X1+X2+X3) / 3
... ... ...
n Xn (X1+X2+X3+ ... Xn) / n
Table 01

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
No. Value Average value
1 5,0 5 / 1 = 5,0
2 3,0 8 / 2 = 4,0
3 1,0 9 / 3 = 3,0
4 7,0 16 / 4 = 4,0
5 14,0 30 / 5 = 6,0
Table 02

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.

Creation environment
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.
 
Test environment Version
PC platform 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) Firmware V2.1
Table 03

 Entry ID:39333120   Date:2012-04-16 
I regard this article....as helpfulas not helpful                                 
mySupport
My Documentation Manager 
Newsletter 
CAx-Download-Manager 
Support Request
To this entry
Print
Create PDF 
Send to a friend
QuickLinks
Compatibility tool 
Help
Online Help
Guided Tour