View Full Version : What exactly does analogReadAveraging does?

01-26-2013, 04:58 AM
Can someone explain to me what analogReadAveraging does? I seem to have better noise rejection using analogReadAveraging versus a manual averaging, i.e. the results from the following pseudo codes are not the same



for (i=0;i++;i<16)
average the 16 readings from analogRead(A0);

This is especially true when reading a value that is very close to ground. For the first piece of code, I got an average ADC value of around 2 to 3, but for the second piece of code, I got an average ADC value of around 8 to 9. Both on are 12 bit resolution.

01-27-2013, 06:21 PM
In theory, they should do the same thing.

However, analogReadAveraging(16) causes the averaging to be done inside the A/D, with no delay between the readings. It's hard to imagine why that would matter, but apparently in this case it does.

Is the signal created by resistors, or something else?

01-29-2013, 01:20 AM
Paul, the readings are coming from a circuit that I have been building from my other thread (http://forum.pjrc.com/threads/15718-Interesting-observation-on-the-ADC-of-Teensy-3-0). It is basically one of the terminals on a sense resistor which the other terminal is grounded. The current flowing through this is controlled via a n-channel MOSFET which is turned off. So theoretically, the voltage should be zero at that point (since theoretically no current should be able to flow).

01-29-2013, 05:13 PM
That thread has a lot of stuff. ;)

If this is still a problem, please start a new thread about only this near-zero error. Please try to start the first message with enough info so I can easily reproduce the same results here. I have plenty of parts and equipment.... but if details like part numbers, wiring, or code are missing, I end spending far more time asking for the missing info that I would to actually investigate the problem!

Please, try to think of *all* the information someone (me) would need to recreate exactly the same results. Concise info and examples are nice, but missing info means I can't actually do much to help.