Page 1 of 1

AT91SAM3S4 ADC_EnableChannel is not working properly

Posted: Sun Nov 27, 2011 11:42 am
by ramonf
Hey.
We're working on AT91SAM3S4 board, and we're trying to use the ADC channel enable function provided in adc.h:

#define ADC_EnableChannel( pAdc, channel ) { \
assert( channel < 16 ); \
(pAdc)->ADC_CHER = (1 << (channel)); \
}

Currently, while running this, the channel is not set properly without a delay after the function ADC_EnableChannel.
we read the status on ADC_CHSR, and sometimes the value changes. only the delay solved the issue for us.
However, we didn't find any reference for needing a delay after that.
Can someone maybe give us some insight about that ?

here's our code:

/* Clear the VREF of the ADC Pin - actually it's set.*/
PIO_Clear(pin_vref);

/* Enable peripheral ADC clock because now the SLEEP option not work O.K.*/
PMC->PMC_PCER0 = 1 << ID_ADC;

// enable channel to check voltage
ADC_EnableChannel ( ADC, channel );

Delay(100); // Don't remove this because the channel is not stable
// dummy read to clear EOC flag in ADC_ISR
pAdc->ADC_CDR [channel] ;

ADC_StartConversion (pAdc);

while ( ( pAdc->ADC_ISR & (1 << channel) ) == 0 );

result = (word) ADC_GetConvertedData ( pAdc, channel );