News:

  • November 23, 2026, 02:40:32 PM

Login with username, password and session length

Author Topic: looking for easy ways  (Read 7857 times)

maciek

  • Sr. Member
  • ****
  • Posts: 95
looking for easy ways
« on: March 04, 2018, 01:13:23 PM »
i want to take the value of D0 take lets say 10 readings of it when C1 is on and get the average of it for more accurate reading
any ideas?
seems simple enough

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6180
  • Yes Pinky, Do-more will control the world!
Re: looking for easy ways
« Reply #1 on: March 04, 2018, 02:27:47 PM »
If your input value is just changing over time, I would just use a FILTER instruction.


If the input needs to be sampled at a specific time, an easier approach that to acquire samples is to use an EMA, like this:
MATH FilteredValue = FilteredValue*FilterCoeff + InputSample*(1.0-FilterCoeff)

A value of 0.9 or 0.95 for FilterCoeff will give you a mild filter. The closer to 1.0 you get the more aggressive the filter. Be sure FilteredValue is a float value like R0.


If you really want to keep all samples and do an average, do this:

1. Create a memory block to hold your samples...we'll call it Sample0-9.

2. Use a V memory location as an index...we'll use V0 as Index, and initialize it to 0.

3. Do these math boxes to sample and calc average.
MATH Sample[Index] = D0
MATH Index = IF(Index == 9, 0, Index+1)
MATH Average = AVGR(Sample, 10)

"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