LPC1768 ADC Reads Garbage

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by melpel on Wed Mar 20 15:01:48 MST 2013
Unable to get the ADC to read anything but garbage.  Started with the test code on my board, changed boards, went back to the Keil board... all do the same thing.  What am I missing...?

Fault Symptoms:
Typically reads back 0 or FFF.  When adjusting the analog control on the eval board there was a small range where the values would bounce around randomly, then flop to the other extreme. 
On my board if I hard ground the analog input I get 0, otherwise any slight value on the pin reads FFF.

The key steps I am using:
1.  LPC_SC->PCONP |= ADC_PCONP_BIT;// Set global ADC Power Enable
2. LPC_ADC->ADCR = adcChan | adcClk | adcBurst | adcPdn | adcEdge;  // Edge = Burst = 0

Trigger Read:
3.adcStatus = LPC_ADC->ADGDR;// Dummy read to clear overrun bit if set
5.while ((LPC_ADC->ADGDR & CONV_COMPLETE_FLAG) == 0);   /* Bit 31 is the done bit, set to 1 when conversion is complete */

Read value:
6.avalue = (LPC_ADC->DR[chan] >> 4);
6.b//value = (LPC_ADC->ADDR >> 4);