Unity Pro V8.1 Moving Average

JanJibs15

Member
Join Date
Dec 2016
Location
NSW
Posts
1
I know unity pro comes with a AVGMV block. Does anyone know how to use it so it samples input values over a time period of say 60 seconds and outputs the average of these values once every 60 seconds?
:oops::oops::oops::oops::oops:🔨
 
I have to admit that i also cant figure out how the avgmv block should work. But you could always create your own. Create an array of 60 reals. every second move a value into the array and increment a counter which defines in which position the value will move into array. Add all the values together and divide by 60
 
Unity AVG block

The key to this block is the EN (Enable) line. Every time this block executes it will read the input value and put it into the internal array, and then calculate the average. Once it gets the programmed number of samples the oldest value is thrown away.

If you put logic on the enable line to turn it on for one scan every two seconds, and set the number of samples to 30 you'll get the output you are looking for. You could use the SAMPLETM block to get a pulse once each time period you require.

There are a few things to watch for.

First, according to the documentation, the block must be called on the first PLC scan as it does some initialization. I've never seen this to be a problem, but it is called out in the documents. Second, the block can only do 50 samples, so you can't quite get a minute worth of data averaging once per second. There are ways to get bigger samples by combining two averaging blocks, but at that point it's probably just easier to roll your own. Third, the average will change each time the block is executed. In the example above the average would be updated every two seconds and would represent the previous minute worth of data.

Another possible block would be the AVGMV_K. This can do far more than 50 samples because it works a bit different. It takes the number of samples requested, and subtracts 1/(#samples)*average from the average before adding 1/(#samples)*current_value to the average. If you have a value with noise around an average point it works pretty well. If you have a step change in value it is a little less accurate until it has performed the number of samples for the new value.
 

Similar Topics

Hello, I am using Unity pro V15. I have Quantum CPU 671 and Ethernet NOE 77101 configured. I have configured IO scanning on NOE. I have attached...
Replies
5
Views
191
HELLO MY FRİENDS ı have problem. ı tought you can solved thıs problem for me. First of all When I checked all the cable connections of the...
Replies
0
Views
411
Hi All, I haven't installed Unity Pro in years and needed to install it recently. I initially tried installing Version 11.1 and the whole...
Replies
3
Views
738
Hello i want to implement a Read_var / Write_var functions to communicate with a modbus tcp device at the moment i use the unity simulator at the...
Replies
4
Views
1,951
Hi, I've exported a PL7 application to the .FEF file succesfully. Imported the .FEF file in my Unity Pro project, but two of the five sections in...
Replies
0
Views
781
Back
Top Bottom