Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: RBPLC on October 19, 2020, 11:36:10 AM

Title: Direct Way to get Running Average Value
Post by: RBPLC on October 19, 2020, 11:36:10 AM
Is there a direct way to get a running average for a value? Say I had a value at R100 and I wanted to "Start" averaging this value and store the average in R101 and then "Stop" at some other time (manual start/stop, sampling could be every scan or at some predetermined interval). I could probably come up with a solution but didn't know if there was a direct way to do this. 
Title: Re: Direct Way to get Running Average Value
Post by: BobO on October 19, 2020, 02:43:40 PM
Is there a direct way to get a running average for a value? Say I had a value at R100 and I wanted to "Start" averaging this value and store the average in R101 and then "Stop" at some other time (manual start/stop, sampling could be every scan or at some predetermined interval). I could probably come up with a solution but didn't know if there was a direct way to do this.

I would just use FILTER. Virtually the same results, without the effort.
Title: Re: Direct Way to get Running Average Value
Post by: Garyhlucas on October 20, 2020, 12:37:20 PM
At my last job we used a running average over 24 hours to set the rate that we processed waste water so the process ran very consistently.  I have the BRX code around here if that would help you.
Title: Re: Direct Way to get Running Average Value
Post by: RBPLC on October 20, 2020, 02:04:41 PM
Yes I would appreciate it.
Title: Re: Direct Way to get Running Average Value
Post by: Garyhlucas on October 21, 2020, 01:45:42 PM
Hope this helps.  Two examples shown here in the Math blocks, clocked by a minute pulse, and there are 1440 minutes in a day.
Title: Re: Direct Way to get Running Average Value
Post by: PLCwannabe on October 21, 2020, 04:22:12 PM
Use FIFO. Then use math to average the fifo table. Works great to get a rolling interval average, if that is what you need. 
Title: Re: Direct Way to get Running Average Value
Post by: Controls Guy on October 22, 2020, 05:07:37 PM
Yeah, FIFO's PROBABLY the best.  Ring accumulator works OK for storing the last n values too.