News:

  • July 25, 2026, 07:58:52 AM

Login with username, password and session length

Author Topic: Direct Way to get Running Average Value  (Read 8659 times)

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Direct Way to get Running Average Value
« 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. 

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6168
  • Yes Pinky, Do-more will control the world!
Re: Direct Way to get Running Average Value
« Reply #1 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.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Garyhlucas

  • Hero Member
  • *****
  • Posts: 421
Re: Direct Way to get Running Average Value
« Reply #2 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.

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Re: Direct Way to get Running Average Value
« Reply #3 on: October 20, 2020, 02:04:41 PM »
Yes I would appreciate it.

Garyhlucas

  • Hero Member
  • *****
  • Posts: 421
Re: Direct Way to get Running Average Value
« Reply #4 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.

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Direct Way to get Running Average Value
« Reply #5 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. 

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3622
  • Darth Ladder
Re: Direct Way to get Running Average Value
« Reply #6 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.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.