Need Advice - Running Average Calculation

sbman

Member
Join Date
Jun 2005
Location
Michigan
Posts
11
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 input is simply "on" when an item passes. I need to calculate the average rate over the past minute.

I can conceive a method for sampling every minute, but it would be preferred to keep a "live" running average that counts the number of items passed in the previous 60 seconds at all times.

Hardware: AB Micrologix 1200; Inview panel display 2706-P42R for message display.

Thanks in advance for any help.
 
You could do it like this:
sample8.jpg


Counts accumulate for six seconds and are then moved to a register (N17:0 thru N17:9). The averaging calc. is performed (shown as a sub in my example), the pointer (c5:0.acc) is incremented and the counter is reset.
This would give you a rolling average that's updated every six seconds. You could change the timer/counter presets to get more or less frequent calculations.
 
First my apologies for an Off-Topic comment!

OK, I assume this is AB ladder, but frankly I wouldn't find it any easier to understand if it was in Siemens Ladder. Surely this is something that cries out to be done in STL or ST. And don't tell me that it's easier for the maintenance guys if it's done in ladder. I can't believe an average electrician with little programming experience can easily understand this.

Perhaps I see this wrong, because ladder is so much more common in US than in Europe, but I'd be curious to know what others think.
 
As a maintenance guy, and speaking for the other maintenance guys who want the PLC to be simple...

I only know ladder...I don't particularly want to learn other methods if they are not going help in 95% of situations. Everything i deal with is in ladder. In some situations it may be easier for the programmer to use something other than ladder, but it will cause problems for me if i need to access it later. I really appreciate it when someone makes it harder for themselve in order to make it easier for me.

All the best

Guy
 
Thanks OkiePC!!!

Now I know why you guys are the experts! I'll try this method; it looks pretty good to me.

And btw - I only know ladder, so any other solution would be over my head.

Thanks again!

sbman
 
I will not get started

OK, I assume this is AB ladder, but frankly I wouldn't find it any easier to understand if it was in Siemens Ladder. Surely this is something that cries out to be done in STL or ST. And don't tell me that it's easier for the maintenance guys if it's done in ladder. I can't believe an average electrician with little programming experience can easily understand this.
How many electricians you know that have programming experience? Ladder is similar enough to relay logic that almost any electrician can eventually understand it. NEVER EVER think because ST or STL is easier or whatever for you that it should be or will be easy for a maintenance electrician.

I will get started a little.
An electrician here in the US and probably many other places has to go thru extensive classroom and OJT to become adept and licensed within that profession. Whats the initiative to learn programming too? Especially when it requires multiple languages.

Whats a maintenance electrician to do? Go EENY MENNY MITY MO which LANGUAGE DO I WANT TO KNOW?

BTW I have met MANY Electrical Engineers that couldnt program or troubleshoot a PLC if their life depended on it.
 
Quite frankly, with the extremely good functiona available in the latest PLC's, I am finding STL or ST becoming a bit redundant in most cases.

For example, mucking around scaling non-linear inputs. Just put together a table and use a linear approximation function. It does it for you. Lot easier than doing the other way. By the way, that function has been available for over 10 years. Just an example.

There are very few things that cannot be done in ladder these days.

FB is OK, provided the FB can be online programmed. No good if you are using FB and have to go off line to do a change to the block.

And don't tell me that it's easier for the maintenance guys if it's done in ladder.

It is!!

I can't believe an average electrician with little programming experience can easily understand this.

Surprisingly many can.

Perhaps I see this wrong, because ladder is so much more common in US than in Europe,

And Ozz. Many electrical consultants will not allow the use of STL and ST here because maintenace electricians cannot understand it and find it difficult to monitor.

Siemens Ladder.

Strangely enough not generally liked in Ozz. AB, Omron, Mitsubishi etc are.
 
what is st and stl

what is st and stl are these other languages ? what are they used for ? and how different are they from ladder ?
 
The STL and Function Block stuff almost looks boolean. Kind of reminds me of the way you programed a little Micro 1 Idec with the hand held programmers. May be they were a head of their time? I think if people learned on the old stuff all this new stuff might make more sense. Quien se? :confused:
 
To me it sounds like you need a running total not really a running average. There is no averaging required.

Here's a quick Untested stab at an ST chunk of code to do the running total. Can anyone with only ladder experience understand this? Maybe RMA can post his version?


VAR (* Declaration of Variables *)
Time_is_up :BOOL;(* Flag to signal when to Update the Total *)
Running_Total :INT; (* The sum of all the values in the array *)
Count_Array :ARRAY [0 to x] OF INT;
(* Array to hold all the sample counts *)
Count_Index :INT; (* The index into Count Array *)
This_Count :INT; (* The count for the current sample period *)
Number_of_Samples :INT; (* The number of samples in the Array *)

END_VAR;
(*
...
...
...
Code here to Add to the counter
and set a timer for signaling
when to recalculat the Running Average
...
...
...
*)
(* Here's where the Running Average Calculation Takes Place *)
IF Time_is_up THEN
(* Subtract the oldest count from the Running Total *)
Running_Total := Running_Total - Count_Array[Count_Index];

(* Add the New Count to the Running Total *)
Running_Total := Running_Total + This_Count;

(* Save the New Count to the Count Array *)
Count_Array[Count_Index] := This_Count;

(* Increment the Count Index *)
Count_Index := Count_Index + 1;

(* See if the Index is Out of Range and if so, Reset *)
IF Count_Index >= Number_of_Steps THEN
Count_Index := 0;
END_IF;
(* Reset the Current Sample Counter *)
This_Count := 0;

(* Reset the calc flag to avoid double calls to the routine *)
Time_is_up := FALSE;
END_IF;

 
Last edited:
The STL and Function Block stuff almost looks boolean.

Yes and no. STL is very similar to Boolean.
Also known as mnemonic.

in 0.10
and 0.11
and not 0.12
out 5.00

FB is really quite a good step in the right direction for repetative tasks such as alarm routines, PID control etc etc. The BMS people have had these blocks for years. Commissioning the block once and repeat use it. Another advantage of the FB is that it is stored only once in the FB storage area in the PLC. It is then "called" each time it is required with the appropriate bits/words/timers etc for the current "instance". Saves on storage space in memory.

Typically, inside a function block there is ladder or ST. On the outside of the block you see and can change timer numbers, SV's, input and output numbers/names etc but you do not see what is in the block, only the external status of the bits and values of timers, counters etc. These days, the FB's can usually be online edited. Very handy. Omron (don't know about others) have also made each FB password protectable. Very handy as one can allow acess to most of the program but not the proprietary code in the FB. If you wish you can only password protect 1 FB in the program and leave the others viewable.
 
ndzied1 said:
To me it sounds like you need a running total not really a running average. There is no averaging required.
I agree with that, There is no averaging required.
As you said, he need a running total.
Or may be different thing is needed which is the rate of items passes in a minute (How many items passes in a minute?)

Look at sbmans' words :"but it would be preferred to keep a "live" running average that counts the number of items passed in the previous 60 seconds at all times".


Any way, the only one know which one is correct is sbman.
 
Last edited:

Similar Topics

I'm currently working on a PLC setup and could use some advice on the best way to manage my power supply units (PSUs). Here's the configuration...
Replies
3
Views
403
So, I'm about to start my first ever project that include a servo motor Here some of the component i bought for the project so far: - PLC: Omron...
Replies
0
Views
380
Dear connoisseurs of antiquity and non-standard solutions, welcome) I don’t really hope, but suddenly someone had a deal and, most importantly...
Replies
0
Views
569
Hey guys, We have a metal container at work, we fill with saw dust (20fts x 15fts x 10fts) with the top open but we normally put a container...
Replies
4
Views
1,543
heya guys, For my project, i'm currently looking to add this type of linear encoder. The control company i'm working with told me they had bad...
Replies
6
Views
1,203
Back
Top Bottom