One advantage to Melanie's technique is very obvious when you have a moving a/d value to read. For slow moving, if you have a quality circuit with low noise, you can usually just average. I used an a/d port to track the charging of a battery once, using 10 point averaging. I could almost get better resolution than the PIC advertised because with a steady and slow moving v-in, the readings changed very slowly... that is, on a 10-bit reading, I'd get 5 readings at, say, 480, and 5 at 481. The next time, it would be 4 at 480 and 6 at 481... then 3 & 7, etc.
If you really want a "rolling average" then you can take a reading and add it to your average, and subtract your oldest rolling number. That saves time in computation if it matters. Otherwise, just adding all of your numbers every time may be easier to read and comprehend.




Bookmarks