I am trying to scale my analog readings and I get into a problem of 'unstable' values.
My goal is to scale 0-1023 to 50-250. I am using the map function – map(A0, 0, 1023, 50, 250). I have set up a display to check the values.
The problem is that sometimes I run into 'middle' values, where the display is flickering between two – for example 69 and 70.
How would you approach this topic? Some DSP low-pass filtering?
I am trying to scale my analog readings and I get into a problem of 'unstable' values.
My goal is to scale 0-1023 to 50-250. I am using the map function – map(A0, 0, 1023, 50, 250). I have set up a display to check the values.
The problem is that sometimes I run into 'middle' values, where the display is flickering between two – for example 69 and 70.
How would you approach this topic? Some DSP low-pass filtering?
Thanks for any help!
Usual first method is to try to take multipule samples and divide by the number of samples taken, thus getting a average value. That acts like a first order low pass filter. Start with maybe 8 samples, divide by 8 then perform your map function. If that settles down the value you can then try with just 4 samples, etc.
I would use a single stage butter worth filter on the data I assume you have a known sample time interval, so just google code samples in C for simple butterworth filters utilities that to limit the effects of random results etc. Alternatively use a moving average with dead band on the raw data this however will not exclude random read results that will occur due to extenrnal influences.
So the ideal is a filter first followed by a moving average IMO.