I have not looked at your implementation, but I've been mulling over your logic, and I don't think I can agree.
First, it sounds like you are really interested in the mode, rather than the median. i.e. take a number of readings and report the one that comes up most often.
But I guess I have a problem with the fundamental assertion that using average is somehow flawed. The value fluctuates because of quantization distortion - basically the real value falls between the ADC steps. You can actually get additional resolution by "oversampling" and averaging the results. There's lots of detail on the issue (or opportunity depending on you point of view), and an excellent solution here http://www.darreltaylor.com/DT_Analog/ It's discussed at length on the MicroChip site too.
The bottom line, though, is that the fluctuation is not noise - it's additional information that you should WANT to incorporate, and hence the almost universal use of average.
Great discussion topic - too often we do things without thinking about why we do them.
Bookmarks