lpcware

ADC on 1768

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Dols on Fri Sep 03 13:46:37 MST 2010
Hello,

I'm new to the lpc1768, lpcxpresso ide, and cmsis. but have have experience on other microcontrollers like lpc2148, 2468 etc.

Somehow i don't get the ADC to work. I tried the example of code-red. Everthing seems to be ok, except i always read 4095, that's certainly not the value present on the pin.

Looking thourgh the manual i see pinmode is not set in the example, and in the errata i see the peripheral clock needs to be set before enable pll0. Played arround with it, but still i don't get it to work.

Anyone got a working example?

the example i use:


#define ADC_POWERON (1 << 12)
#define PCLK_ADC 24
#define PCLK_ADC_MASK (3 << 24)
#define SELECT_ADC0 (0x1<<14)
#define START_ADC (1<<24)
#define OPERATIONAL_ADC (1 << 21)
#define SEL_AD0 (1)
#define ADC_DONE_BIT (1 << 31)

// Turn on power to ADC block
LPC_SC->PCONP |=  ADC_POWERON;
//LPC_SC->PLL0CON = 1;
// Turn on ADC peripheral clock
LPC_SC->PCLKSEL0 &= ~(PCLK_ADC_MASK);
LPC_SC->PCLKSEL0 |=  (3 << PCLK_ADC);
// Set P0.23 to AD0.0 in PINSEL1
LPC_PINCON->PINSEL1 |= SELECT_ADC0;
//LPC_SC->PLL0CON = 3;
int adval = 0;
while(1)
{
  // Start A/D conversion for on AD0.0
  LPC_ADC->ADCR = START_ADC | OPERATIONAL_ADC | SEL_AD0 ;
  do
  {
   adval = LPC_ADC->ADGDR;            // Read A/D Data Register
  } while ((adval & ADC_DONE_BIT) == 0); // Wait for end of A/D Conversion
  // Stop A/D Conversion
  LPC_ADC->ADCR &= ~(START_ADC | OPERATIONAL_ADC | SEL_AD0) ;
  // Extract AD0.0 value - 12 bit result in bits [15:4]
  adval = (adval >> 4) & 0x0FFF ;
  //Convert integer ADC value to string
  printf("%04d\n", adval);
}

Outcomes