Host Engineering Forum
General Category => General Discussion => Topic started by: maciek 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
-
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)