Craig,
I am currently using the code below to run the ADC on an 'M128 with external mux'es to expand
the system to 42 channels. The whole mess is scanned once per second (without putting the
cpu to sleep) and I'm only seeing +/- one bit of noise. Each mux input has a 10K/.1uF RC filter
and all of the filters and mux'es are (SMT) mounted on the top of the board right next to the
'M128 and are over and connected only to an isolated ground plane (1st inner layer below the top)
that is connected to the AGND pin. To my amazement, this setup worked so well that I didn't need
to do noise canceling.
// setup the muxes for a conversion
// vp points to the target channel
void set_mux(struct VOLT_SRC * vp)
{
static BYTE last_iic_addr = 0;
BYTE cur_iic_addr;
cur_iic_addr = vp->iic_addr;
ADMUX = (ADMUX & 0xf8) | (vp->amux_addr);
if(last_iic_addr != cur_iic_addr) // if current is different chip
iic_set_mux(last_iic_addr, 0); // disable last
iic_set_mux(cur_iic_addr, vp->lmux_addr | 0x08);
last_iic_addr = cur_iic_addr;
}
// measure all analog voltages
void scan_analog(void)
{
BYTE i;
int val;
for(i = 0; i < CH_COUNT; ++i)
{
set_mux(&volts[i]); // set the mux'es
while(ADCSRA & (1 << ADSC)); // wait for ADC idle
ADCSRA |= (1 << ADSC); // start new conversion
while(ADCSRA & (1 << ADSC)); // wait for conversion done
val = ADCL; // Read 8 low bits first (important)
val |=((int)ADCH << 8) | 0x8000; // 2 high bits and new value bit
adc_Val[i] = (VWORD) val;
}
}
> Here is my signal routine:
>
> SIGNAL(SIG_ADC)
> {
> adchannel[curchannel] = ADCH;
> doingadc = 0;
> }
The 'M128 ADC must be read low byte first in order to latch the upper bits into a temp register.
I haven't checked the 'M32 data sheet but I suspect the same restrictions apply.
Hope this helps.
BruceMessage
Re: [AVR-Chat] Noisy ADC lines
2004-05-11 by Bruce Parham
Attachments
- No local attachments were found for this message.