Averaging Sampled Data

Averaging Sampled Data
none 0.0 0

Hi @jjansen,

I would recommend that you use a macro to calculate this average, here is an example that may be suitable for this application:

  1. Within the “Project” tab click “Macro”:

  2. Within the following menu, click “New”:

  3. Follow the instructions within this post to implement a GetData() command and pull the sampled data into the macro:
    Note: In this example I’m retrieving data from LW-59. You may need a variable to hold the total sum and average and a variable to count the number of samples. The data type I am reading this example is a short, but please configure the data type of the variable used within GetData() such that it matches the type sampled.
    image

  4. Store the total count within HMI memory, in this example I am storing the count within LW-1000:
    Note: Information related to the SetData() command can be found within the post mentioned above as well.
    image

  5. Add the current data to a running total and save this data within HMI memory as well:
    image

  6. Calculate the average and set this within HMI memory:

  7. Enable periodical execution and run this macro every one minute:
    image

  8. Click “Save & Compile” when finished:
    image

Here is a link to a demo project: Link