calculation of Average value on the fly

Michal_dk

Member
Join Date
Oct 2007
Location
Vejen
Posts
153
Hi Guys!

I have resently got my hands on a small project, getting data from a check weigher that speaks Modbus RTU.

I want to use the ML1100 to communicate with the weight and I need to collect values continously. Theese values have to end up in a report made every friday by the ML1100 and then collected with Excell on monday. Report is to hold average, min and max values for 3 weight groups - 1,0 kg, 1,5 kg and 2,0 kg.

Now what I was planning to do was use a FIFO to collect the data and then when it is filled up (or the group changes), use the AVA instruction to make the average of that part of the production. Do the same for the next filled FIFO and collect that into another FIFO and at some point do an average on that FIFO as well.
My problems began as I tested this in Excell, doing a MIDDEL instruction on 102 different numbers gives me 112192,9, splitting it up in 4 MIDDEL instructions and then adding a fifth on those 4 gives me 95447,45 (y)
Not excactly the same number!

So I guess I'll have to use an ADD instruction to add all the weight data to one another and another to count the number of times that weight group has been added and then using those to do my average calculation on fridays.

Now my question for the esteemed members of this board is this: Is there another simpler way of doing this? As the accumulated value of all the weighings in say the 1,0 kg group could/will exceed the max value for a tag of the typr REAL.

I expect somewhere between 30-50 weighings per minute 8 hours a day - for normal production.
 
Hi!

I haven't used the micrologix myself, just the bigger logix units, but my initial thought was to just break it down into smaller time segments (average per day, average per hour etc), and also log the amount of weighings per segment (per group).


If accuracy isn't an issue, or the weight deviation isn't that huge, you could also define pre-set sub-ranges and count the number of weighings that match each.


I assume the reason your initial fifo average didn't yield consistent results is because you didn't take into account the number of weighings per average when calculating the total average; example:
first average A consists of 10 weighings, second average B consists of 20 weighings, calculating the total average like this: (A+B)/2 will not yield an accurate average for the whole series of weighings but skew the results towards A (i.e. each weight in sub-set B counts for less than each weight in sub-set A).

Not sure I explained that in an understandable way though... :D

Anyway, hope this helped a bit.
 
try this
counter-1/counter*average+weight/counter=average
25897/25896*1.4999kg+1.523kg/25896
counter+1
this way you always have average.
also do this for min and max.
please also calculate the deviation.
if you put it in a plot it will help operator to get closer to the limit. watch the rejects as they do not count in the average.
 
Hi!

I haven't used the micrologix myself, just the bigger logix units, but my initial thought was to just break it down into smaller time segments (average per day, average per hour etc), and also log the amount of weighings per segment (per group).


If accuracy isn't an issue, or the weight deviation isn't that huge, you could also define pre-set sub-ranges and count the number of weighings that match each.


I assume the reason your initial fifo average didn't yield consistent results is because you didn't take into account the number of weighings per average when calculating the total average; example:
first average A consists of 10 weighings, second average B consists of 20 weighings, calculating the total average like this: (A+B)/2 will not yield an accurate average for the whole series of weighings but skew the results towards A (i.e. each weight in sub-set B counts for less than each weight in sub-set A).

Not sure I explained that in an understandable way though... :D

Anyway, hope this helped a bit.

Yes it did make me see where my problem came from, but accuracy IS important. The customer wants to use the program to enhance their precision in the weight in each net of onions. Thanks!

try this
counter-1/counter*average+weight/counter=average
25897/25896*1.4999kg+1.523kg/25896
counter+1
this way you always have average.
also do this for min and max.
please also calculate the deviation.
if you put it in a plot it will help operator to get closer to the limit. watch the rejects as they do not count in the average.

This was the kind of formula I was looking for :pThanks! But shouldn't it be 25896/25897*1.4999+1.523/25897=Average? And to make absolutely sure I've got it right: ((25896/25897)*1.4999)+(1.523/25897)=Average?

See this thread for a sample Micrologix program.

http://www.plctalk.net/qanda/showthread.php?t=37722

I'll be looking into this program, either over the weekend or next thing monday, Thanks!

Shouldn't you be using the Mean function in Excel to get the average?

Actually I think all functions in Excell er pretty nice, haven't met any that were mean :rolleyes: No seriously, Mean is propably the same as Middel - I'm using a danish version of Excell. Thanks!
 
Hmm, Alaric your program seems to do what I want, but I'm a bit concerned as my total of weighings (worstcase) would be 50 weighings per minute totalling up to 120000 over 5 days.

Shooter, that formula does what I want and on the fly, but doing the standard deviation is rapidly graying my hairs :angr:

Calculating standard deviation should be something like

STDDEV = SQR(E(Weight-Average)^2/Counter)
(E is my poor attempt at making the epsilon o_O, e.i summing up the values).
But the summing up of all the values is whats giving me trouble, any idea where I'm making the fault? :unsure:
 

Similar Topics

Hi! Currently I'm trying to implement an average calculator in a S5-95U. In order to do the job, I'm using the folowing equation: M(k) =...
Replies
16
Views
8,608
Does this instruction calculate values during a single scan, or does it require number of scans based on element count in the array? For Example...
Replies
3
Views
113
Hi, I need a bit of help. We have a labeler that is experiencing some crazy down time and we want to show the supervisors a few more metrics to...
Replies
3
Views
1,820
I want to take a sample every minute from the analogue value, and after 24h calculate the average value. Does Siemens has a standard SFB for this...
Replies
4
Views
4,838
Hello, I'm a novice seeking advice. I need to claculate and display a running average for the number of items passing by on a conveyor. The...
Replies
24
Views
11,311
Back
Top Bottom