LPC822 ADC Conversion

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC822 ADC Conversion

Jump to solution
1,293 Views
kaarthick
Contributor II

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);

}

Labels (1)
1 Solution
908 Views
ianbenton
Senior Contributor I

A few points to note:

Driving Vrefp from a high impedance source is probably not such a great idea, although the manual says nothing about the current drawn by that pin; but it does say that the midpoint between Vrefp and Vrefn should be half the supply voltage.

I think that the pullup on PIO0_23 remains active on an LPC800 even when in analogue mode, so you should switch it off.  (IOCON->PIO0_23 = 0x80). That pullup current flowing in your resistor input network would account for the offset voltage.

R2 is superfluous, as the impedance at TP1 is about 450k. That does mean you have a low-pass filter on the input with a time constant of 45ms (f cutoff = 3.5Hz) so if that wasn't intended, change the divider impedance.

Measuring down to millivolt level when you have a supply with high-frequency ripple will be very layout-dependent!

What does your circuit mean by "R18=100E"?

View solution in original post

6 Replies
908 Views
ianbenton
Senior Contributor I

What is connected to the A/D input? And how is it connected? Where does your power supply come from, and how is it regulated?

20 counts in 4096 is a little under 0.5%, so it could easily be noise on the signal or ripple on the power supply.

908 Views
kaarthick
Contributor II

Power supply is SMPS and from same i gave ADC input. Is there any problem with my code?

0 Kudos
908 Views
ianbenton
Senior Contributor I

Most likely not. At a quick glance it looks OK, but the fault just looks like noise on the input.

A variation from 0 to 20, with a mean of 10 is an average DC voltage on the input of 16mV, with 5.6mV rms of noise. You say that the input is connected to 0V. Where is it connected to 0V? If it doesn't go exactly and only to a Vss pin on the chip you could easily have a DC offset of 16mV due to the current flowing out of the Vss pin. If there any length of track, and the input isn't connected to 0V with a very low impedance, and doesn't have a low-pass filter on the input then the 5.6mV rms noise could quite easily have been picked up from the PSU, and what you are seeing is an alias of the PSU ripple.

Good analogue design and/or a basic IIR filter on the data will probably solve it.

Are you just experimenting, or are you trying to measure something in particular?

0 Kudos
908 Views
kaarthick
Contributor II

Capture.JPG

0 Kudos
909 Views
ianbenton
Senior Contributor I

A few points to note:

Driving Vrefp from a high impedance source is probably not such a great idea, although the manual says nothing about the current drawn by that pin; but it does say that the midpoint between Vrefp and Vrefn should be half the supply voltage.

I think that the pullup on PIO0_23 remains active on an LPC800 even when in analogue mode, so you should switch it off.  (IOCON->PIO0_23 = 0x80). That pullup current flowing in your resistor input network would account for the offset voltage.

R2 is superfluous, as the impedance at TP1 is about 450k. That does mean you have a low-pass filter on the input with a time constant of 45ms (f cutoff = 3.5Hz) so if that wasn't intended, change the divider impedance.

Measuring down to millivolt level when you have a supply with high-frequency ripple will be very layout-dependent!

What does your circuit mean by "R18=100E"?

908 Views
kaarthick
Contributor II

That 100E not placed in PCB.  And I found that there is problem due to noise only. By adjusting RC Filter i get fine output.

Thanks for supporting me to find out problem and proper solution.

Thanks Mr.Ian Benton

0 Kudos