AnsweredAssumed Answered

LPC822 ADC Conversion

Question asked by Karthik K on Jul 30, 2018
Latest reply on Aug 1, 2018 by Karthik K

LPC822 ADC Conversion - Result in ADC Count Varying Continuously. Through polling method i am reading ADC value. For 0V ADC input the system showing 0 to 20 count variation.

 

Someone help me to come out from this error?

 

My Code is here:

Adc_Init()

{

     LPC_SYSCON->PDRUNCFG &= (~(1<<ADC_ON));
    LPC_SYSCON->PRESETCTRL |= (1<<ADC_RST_N);
    LPC_SYSCON->PRESETCTRL &= ~(1<<ADC_RST_N);
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<GPIO)|(1<<SWM)|(1<<IOCON)|(1<<ADC);

   LPC_SWM->PINENABLE0 &= ~(1<< (13 + Adc_Channel));

   LPC_ADC->TRM &= ~(1<<VRANGE);

// Calibration

SystemCoreClockUpdate();
  current_clkdiv = (SystemCoreClock / 500000) - 1;

LPC_ADC->CTRL = ( (1<<ADC_CALMODE) | (0<<ADC_LPWRMODE) | (current_clkdiv<<ADC_CLKDIV) );

while (LPC_ADC->CTRL & (1<<ADC_CALMODE));

#define desired_sample_rate 1200000
current_clkdiv = (SystemCoreClock / (25 * desired_sample_rate)) - 1;

LPC_ADC->CTRL = ( (0<<ADC_CALMODE) | (0<<ADC_LPWRMODE) | (current_clkdiv<<ADC_CLKDIV) );

}

 

Adc_Conversion()

{

   LPC_ADC->CTRL &= 0x00000000;                              
    LPC_ADC->SEQB_CTRL |= (1<<ADC_3);                               
    Delay_mSec(10);
    LPC_ADC->DAT[3] &= 0;
    LPC_ADC->SEQB_CTRL |= 0x80040000;       

LPC_ADC->SEQB_CTRL |= (1<<26);

while(LPC_ADC->SEQB_GDAT & (0x80000000)); 

return((LPC_ADC->DAT[3] >> 4) & 0xfff);

}

Outcomes