LPC1769 ADC Problem

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by andretendi on Mon Mar 18 23:12:00 MST 2013
Hi guys, I'm trying to use the ADC function on LPC1769 but for some reason, I can't make it work.
I am using software controlled ADC from AD0.0 to read in an analog voltage between 0-3.3V.

When I run the program, however, the ADC never starts at all. My program gets stuck at the 'while' loop waiting for bit DONE to be set, which indicates that ADC is completed. It never did. I wonder if any of you can point my mistakes and set me on the right track

I understand that I have to configure the following:
[LIST=1]1. PINSEL1: Set P0.23 as AD0.0[/LIST]
[LIST=2]2. PINMODE1: Set P0.23 as neither pull-up or pull-down resistor enabled[/LIST]
[LIST=4]4. ADCR: Select AD0.0[/LIST]
[LIST=5]5. ADCR: CLKDIV set to 4. Hence, ADC clock -> (100MHz/4)/(4+1) = 5MHz[/LIST]
[LIST=6]6. ADCR: Burst = 0 for software controlled[/LIST]
[LIST=7]7. ADCR: Enable PDN[/LIST]
[LIST=8]8. ADCR: START = 001 to start conversion[/LIST]
[LIST=9]9. ADDR0: wait for DONE to be set[/LIST]
[LIST=10]10. ADDR0: Read RESULT[/LIST]

My program code is as follows:

#include "LPC17xx.h"

//****** ADC variables and arrays ******//
unsigned int adc_result[5];//adc_result array to store results from the different channels

int main(void)
//A/D Converter is powered on
LPC_SC->PCONP |= 1<<12;

//set P0.23 as AD0.0
LPC_PINCON->PINSEL1 |= (0x1 << 14);

//Set PINMODE of AD0.0 as no pull-up/down resistors
LPC_PINCON->PINMODE1 |= (0x2 << 14);

//select AD0.0, CLKDIV = 4+1 => 25MHz/5 = 5MHz < 13MHz, power on
LPC_ADC->ADCR |= (1 << 0) | (4 << 8) | (1 << 21);

//start conversion
LPC_ADC->ADCR |= (1 << 24);

//wait for conversion to finish by checking ADGDR.31
while((LPC_ADC->ADDR0 & (1<<31)) == 0);

//return conversion result
adc_result[0] = ((LPC_ADC->ADDR0 >> 4) & 0xFFF);

// Enter an infinite loop, just incrementing a counter
volatile static int i = 0 ;

while(1) {
i++ ;

return 0 ;

Any inputs are much appreciated.