ADC noise canceller

Dear Group,
Has anybody tried using the ADC noise-canceller function? I'd welcome any experiences or example code.
cheers,

This post Pls help to find a mistake in my code (solved!) - #12 by system - Programming Questions - Arduino Forum has some code I wrote to start an ADC sample and interrupt when it is complete. If you start from that, and modify it to (a) call Sample() from normal (not ISR) code, (b) call set_sleep_mode with the ADC noise cancelling constant in setup (or in Sample()), and (c) call sleep_mode after setting up the ADC, it should get you what you want. There might be some timing requirements regarding how soon after telling the ADC to start you must sleep, in which case you might need a volatile asm section to initiate sleep, but I can't think of anything else. Your ADC ISR can simply do nothing, and you can read the sample in the code immediately following the sleep_mode call. But copy the wait-until-the-sample-is-ready code from analogRead in wiring_analog.c (or have the ISR set a flag and check that) in case the MCU is awoken by something other than the ADC interrupt.

there are three tactics quite common to cancel noise

  1. double read and ignore the first
x = analogRead(A0);
x = analogRead(A0);
  1. Average multiple readings (takes some time)
int val = 0;
#define TIMES 4   // any value > 0 and < 31 will do.
for (uint8_t i =0; i<TIMES ; i++) val += analogRead(A0);
val = val/TIMES ;
  1. running average (quite fast)
#define WEIGHT 24    // 0..32   

int val = (analogRead(A0) * WEIGHT + val * (32-WEIGHT) ) / 32;  // use of power of 2  (32) speeds things up.

hopes this helps

The point about sleep mode while ADC is converting is to switch off most of the clocked circuitry and the clock - this is the chief cause of noise on the chip and supplies.

Averaging multiple readings can not only reduce noise, but actually give you more than 10 bits of precision (but only if there is enough noise in the first place, ironically).

If you are reading from a high-impedance source it is wise to read once to set up the multiplexor, discard that result and read again (if the RC time constant is significant (R is source impedance, C is stray capacitance in the multiplexor and sample/hold circuits).

Thanks Kerthyn, that's what I was looking for. Thanks also for the other comments. In this case I think the CPU is a significant source of noise, so I'm optimistic that I can gain more with the noise-canceller than by over-sampling.

What do you have connected to AREF?

Just a 100nF capacitor to ground.