Moving average

davetcw

Member
Join Date
Dec 2014
Location
Gilbert, AZ
Posts
8
How can I average values in an array when the array is not full? For example, I have an array of size 1440. However, if only six values are loaded, how can I get an average of just those six? I was trying to use the MAVE instruction but if the array is not full, the average is not accurate.
 
Also, I use RSLogix 5000 so I can use either ladder, function block, or structured text. I was trying to use the MAVE instruction in function block for this.
 
You might have to use {MAVE_Instuction_Name}.Initialize to control when the data you want to sample enters the array. If .Initialize is set the instruction will pass the input to the output. When is it reset the instruction will start averaging values as they come in up until you reach the sample size value. If you know when valid data is coming in this should do what you want.

Keith
 
How are you moving the values into the array? If you're using an FFL or something, you can use the .POS element of the FFL control to determine how many values are currently in your array, and then just set your AVE instruction to average only that many array elements
 
I used a FSC instruction to Find Zero. Then Move the .POS of the FSC to the AVG Control.LEN for divisor. If you have 6 values in your array then Array[0] thru Array[5] are populated with values. That makes POSITION 6 the first Array = 0. Just Make your Array length +1 than your entries to allow FSC to find Last Position once full. In the Example below you'll see the FAL populates my array for a length of 10 but my FSC Length is set to search thru 11. This is one time Allen Bradley starting with 0 comes in handy.

Avg Array.jpg
 
Thanks!!

Thank all of you for your responses! I ended up using the .Initialize response and it did the trick, even though others would have worked just as well. I didn't know what the .initialize would do in a MAVE instruction.:D
 

Similar Topics

Hi all, I'm trying to set up a moving average in PME 8.6 and apparently there is such an instruction (MAVG) but when I try to insert it into an...
Replies
6
Views
2,236
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...
Replies
3
Views
4,559
Hello all, The task at hand is a little tricky for me... a novice at best... This is all about an alarm and storing data into rs batch. I have...
Replies
3
Views
5,443
Hi all, I am pretty new to the PLCs and I had a question about data handling. I get readings from a pressure sensor and display it to the screen...
Replies
15
Views
6,049
Does anyone know if there is a standard block to perform Moving Average in S7-300? I can't see one in the library, even though Siemens suggest...
Replies
13
Views
8,441
Back
Top Bottom