What exactly does analogReadAveraging does?

Status
Not open for further replies.

darkness

Active member
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

Code:
analogReadAveraging(16);
analogRead(A0);

versus

Code:
analogReadAveraging(1);
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.
 
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?
 
Paul, the readings are coming from a circuit that I have been building from my other thread. 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).
 
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.
 
Status
Not open for further replies.
Back
Top