We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello everyone,
I am working with ADC Polling method in LPC1788 and I am using 16*2 LCD for displaying the converted value.
I did all settings as mentioned in user manual and readed the channel 0 as mentioned below.But my LCD is flooding with unmatched values.
my adc settings and reading procedure is as follows,
void adc_init() { LPC_SC->PCONP |= (1<<12); //Power up for ADC
LPC_IOCON->P0_23 &= ~(0x07<<0); //clearing the function of ADC0 pin
LPC_IOCON->P0_23 |= (0x01 & (0x07<<0)); //Selecting func for P0_23 as adc
LPC_GPIO0->DIR |= (0<<23); //Making ADC0[0]-P0.23 as input
LPC_ADC->CR = (1<<0) |(0<<8) | (1<<21); //ADC0[0],so SEL=0x01,clkdiv_ADC=0,PDN=1 }
int adc_read() { unsigned int adc_result,ADC_Data;
LPC_ADC->CR &= ~(0xFF<<0); //clearing the Channel already used ADC0 in SEL bit of CR
LPC_ADC->CR |= (1 << 24) | (1 << channelNum); // switch channel using SEL,start A/D convert */
do { adc_result = LPC_ADC->DR[channelNum]; //Getting channel0's data register value in adc_result variable
/* read result of A/D conversion */
//Note:-Here the ADC_DONE macro value is 0x80000000
}while((adc_result & ADC_DONE)==0); //Waiting for ADC_DONE=1.[i.e DR value to become 0x8]
LPC_ADC->CR &= ~(7<<24); // stop ADC now (i.e.)CR[26:24]=000
ADC_Data = ( adc_result >> 4 ) & 0xFFF; //Getting adc converted result from 4th to 15th bit of DR
return ( ADC_Data );
}
Reading friends help me to clear the bug and execute as well.
Thanks in advance.