starkb

Rolling average

11 posts in this topic

New to progamming. Don't know how to create a 15 minute rolling average of inlet pressure in a SLC 5/04. Thanks.

Share this post


Link to post
Share on other sites
Need more information, what sampling rate? one per minute? two per minute? The more often you record a sample, the more memory you will need? 1/min = 15 registers 4/min = 60 12/min = 180 etc....

Share this post


Link to post
Share on other sites
The only way is to log the data and then average it and the most efficient way is to keep a rolling total. Keep a list of previous values. When a new value is read, subtract the oldest value from the total and and add the new value, then store the new value over the top of the old value. Either perform a division to calculate the average on the total or on each value as you use it (if you are not too bothered about accuracy) If you are very new to programming then the indirect addressing required will stump you. Remember if the rolling total exceeds 32767 then you will either have to use 32-bit maths or floating point numbers Failing that, there is probably an example somewhere on this site but if not then give a bit more info (input ranges and number of sample) and someone here may help further. Edited by Spedley

Share this post


Link to post
Share on other sites
Being new to programming, you will want to get an understanding of indexed addressing subroutines, and jump and label instructions to comprehend my example. Basically, it stores the current pressure every 15 seconds at N17:[POINTER] and increments the POINTER. It then jumps to a subroutine that adds up the sixty samples and divides by 60. I used a counter.acc for the pointer and F8:0 for the raw pressure data. This example should work as programmed once you fill in the correct addresses for your machine. You could change the presets of the timer and counter to get more/less frequent calculations. Make sure to use a Floating point address for the total in the average subroutine. Chances are, 60 samples will exceed the limit for a 16 bit integer. The subroutine uses a jump and a label which may be slower than 60 rungs of addition. Your overall scan time will take a small hit every time this subroutine executes. If this is unacceptable, you can change it to add the latest sample and subtract the oldest. That method, however, requires initialization or the use of a FFU, FFL pair. hope this helps and doesn't blow your mind too much... ROLLING_AVERAGE_504.RSS

Share this post


Link to post
Share on other sites
Okie's example is a good one. However, you will get very low averages untill you have filled all 60 registers. I took Okie's logic, and modified it slightly, I put in a slight delay on startup, and then fill all 60 registers with the current value. Either way will work, it's a matter of preference. ROLLING_AVERAGE_504_A.RSS

Share this post


Link to post
Share on other sites
The formula for a running average is (A - (A/N) + PV) /N A=average N=number of samples PV=process variable current value This is a running average, not a continuous average. A running average is often good enough for a process that is somewhat stable and not subject to large fluctuations. You must pre-seed the value of A with either an anticipated average or the current PV when you first begin or it will take a long time to reflect the true running average. See the attached .RSS file for another example of how to do a continous average with indirect addressing and a data storage table. RunningAverage.RSS Edited by Alaric

Share this post


Link to post
Share on other sites
Okay, here's a better one that uses FFU and FFL. It doesn't require initialization, but a rung exists to reset the stack position to 0 which will "restart" it. The average is calculated from the number if items in the fifo stack, so if you only have one sample, your average will be equal to it, and so on. Also, I tested it (not too thoroughly) on a PLC5/40 using input values from -32768 to 32767 and various sample rates with a stack size of 60 samples. BTW Alaric: your program's very first instruction should be XIO, not XIC. ROLLING_AVERAGE_504_r001.RSS Edited by OkiePC

Share this post


Link to post
Share on other sites
Thanks. Good catch. I just banged that out real quick in the mnemonic editor, tested it in my head instead of on a machine, and missed that one.

Share this post


Link to post
Share on other sites

Sorry to raise this thread but is there any way to currently download the *.RSS examples you gentlemen created?

 

Thanks!

Share this post


Link to post
Share on other sites

This is an old thread but the files are not available anymore. What I need is a 5 minute average of a pressure transmitter. I am using A Micro logix  1100. I need to be able to pull data from any point in time while the five-minute rolling average is happening. I figure I would need 300 registers to do this. 

Share this post


Link to post
Share on other sites

Odds are that your use up all the memory in your ML1100.  You need to find out how much memory your currently have.  You might not be able to achieve either 5 minutes at your 1 sec resolution, probably not even 1 minute.  You'll have to play around with it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now