I am working on LPC11u68 with Keil IDE. I havent used the adc peripheral on this chip before. I am not getting the proper ADC output. The output which am getting is 0xfff. Please see my init code and adc_read code and do let me know what i am doing wrong.
void ADCInit( void)
{
unsigned char i;
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<13 |1<<16); /* Enable AHB clock to the ADC and IOCON */
LPC_SYSCON->PDRUNCFG &= ~(0x1<<4); /* Disable Power down bit to the ADC block. */
LPC_IOCON->PIO0_11 |= 0x02; // Cnfigure PIO0_11 as ADC9
LPC_IOCON->PIO0_11 &= ~(3<<3); //Disable the internal pull up.
LPC_IOCON->PIO0_11 &= ~(1<<7); //Configure PIO0_11 as analog pin
LPC_ADC->CTRL |= 47; //ADC clkdiv = val+1 i.e 48. 48M/*48
LPC_ADC->TRM &= ~(1<<5);
LPC_ADC->SEQA_CTRL &= ~(1<<31); //Disable the conversion sequence by setting the SEQ_ENA bit to 0
LPC_ADC->SEQA_CTRL |= 1<<18; //Set the TRIGPOL bit to 1 in the in the SEQA_CTRL register
LPC_ADC->SEQA_CTRL |= 1<<31; //Enable the conversion sequence by setting the SEQ_ENA bit to 1
}
unsigned int ADCRead( unsigned char channelNum )
{
unsigned int regVal, ADC_Data;
LPC_ADC->SEQA_CTRL |= 1<<channelNum; // select channel for conversion
LPC_ADC->SEQA_CTRL |= 1<<26; //start adc conversion
while ( 1 ) /* wait until end of A/D convert */
{
regVal = LPC_ADC->SEQA_GDAT;
if ( regVal & ADC_DONE )
{
break;
}
}
if ( regVal & ADC_OVERRUN ) /* save data when it's not overrun, otherwise, return zero */
{
return ( 0 );
}
ADC_Data = ( regVal >> 6 ) & 0x3FF;
return ( ADC_Data ); /* return A/D conversion value */
}
Also the Vrefp is 3.3V and Vrefn is 0V.