Simple Running Average Implementation with Ladder Logic?

blw2k1

Member
Join Date
Dec 2005
Location
n/a
Posts
4
I am trying to implement a running average function using ladder logic in an AB PLC5. I have a digital input that pulses. Every minute I need to get the last five minute average pulse count (i.e. total count over last five minutes / 5). Can this type of thing be done easily with ladder logic or should this type of calculation be performed outside of the PLC? I'm updating a system that previously used a desktop computer with an i/o card that ran a c program to do this calculation. I'm upgrading the system with the PLC and I'd like to avoid doing any external manupulation of the data if possible. Anyone have any ideas? I'm new to PLC programming... hope this all makes sense. Thanks.
 
It can be done far more simply in the PLC that in a desktop computer.

There are several wasy to approach this. You will need to know and understand the following things:
indirect addressing
timers
files
one-shots
FFL,FFU,
FAL

Here is one way:
Reserve five contiguous words of memory or create a dedicated file with at least five words of data in it. This is your averaging array.

Create a self restting 1 minute timer.

Each time the timer /DN bit is set, using indirect addressing, move the pulse count into array and increment the array position pointer. If the pointer > 5, then reset the pointer.

Now calculate the average as the array sum / 5.

Here is one quick and dirty way to do it. Adjust as needed for your application.
qndrunningaverage1.GIF
 
Last edited:
Yes, this should be fairly easy to do in any PLC. You just need a counter, a one minute timer and a 5 register array. Count pulses for one minute, move the count into the next register array position, and reset the count and the timer. Then add up the registers and divide them by 5 (or the number that contain a non zero value, if you haven't reached 5 minutes yet). When you reach the 6th minute, simply place the count into the first position again. Hopefully someone will be kind enough to write you a bit of code (I would but haven't worked out how to do it on the forum yet - doh)
 
Oh will you look at that. Someone put up some AB logic while I was typing. Looks exactly like I was trying to explain too!!
 

Similar Topics

Hi to all, Please find attached a simple CFC circuit of running lights. The problem is that i cannot loop it and make the timer restart again...
Replies
4
Views
3,203
Hi all, Writng a FB in ST on Beckhoff TC for a pulser which turns on and off on a cycle, is paused by turning bControlInput to FALSE, but resumes...
Replies
2
Views
53
I'm trying to build my Classic Step 7 programming skills this weekend. I get stuck on little things that are not covered in YouTube tutorials. I'm...
Replies
7
Views
248
I have a program that does a 7 second "scan" sensor calibration routine whenever a setting (setting is called assistance level or "AL" and ranges...
Replies
3
Views
171
Hi all, I have a simple question that I have overcomplicated and gotten stuck on. I have a variable, we can call it "light" that I need to stay...
Replies
4
Views
213
Back
Top Bottom