This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ADC Problem

Hi everyone, I'm getting started with ARM microcontrollers and I'm having a issue with ADC in LPC2148, I'm trying to make work a code that is supposed to read the analog input in AD0.6 (P0.4), and show it on an lcd, Clock and Timer is perfectly setted, the only problem is ADC, it is definetely converting something, but isn't the right results, it oscilate when the tension in the pin is constant and things like that, so I would really appreciate if anyone could help me. Thanks in advance, John.
Here is the code.

#include <lpc214x.h> ///////////////////////
#include "clocks.h"  //    including      //
#include "types.h"   //     libraries     //
#include "lcd.h"     ///////////////////////

#define AD06 ((1<<9)|(1<<8)) //Select AD0.6 function for P0.4
#define SEL_AD06 (1<<6)

#define CLKDIV (15-1) // 4Mhz ADC clock
#define BURST_MODE_OFF (0<<16) // 1 for on and 0 for off
#define PowerUP (1<<21) //ADC on
#define START_NOW ((0<<26)|(0<<25)|(1<<24)) //001 for starting the conversion immediately
#define ADC_DONE (1<<31) //bit done check

#define VREF 3.3 //Reference Voltage at VREF pin

unsigned long AD0CR_setup; //declaration global variable
int result=0; //declaration global variable

int main(void)
{
        char s[100];
        initClocks(); //Initialize CPU and Peripheral Clocks @ 60Mhz
        initTimer0(); //Initialize Timer0
  lcd_init(); //initialize lcd

        PINSEL0 |= AD06 ; //select AD0.6 for P0.4
        AD0CR_setup = (CLKDIV<<8) | BURST_MODE_OFF | PowerUP;//AD0CR settings
        lcd_puts("\f"); //clear lcd

  while(1)
  {
                AD0CR =  AD0CR_setup | SEL_AD06; //setting up AD0CR register
                AD0CR |= START_NOW; //Start new Conversion

                while( (AD0DR6 & ADC_DONE) == 0 );//wait until conversion is done

                result = (AD0DR6>>6) & 0x3ff;//extracting conversion result of AD0DR6 register
                sprintf(s,"\rV = %.4d",result);//printing result in the lcd
                lcd_puts(s); //printing result in the lcd
                delayMS(1000); //wait 1sec
  }

}

Parents
  • I don't think you have mentioned how much the read value varies.

    But one issue with the ADC is that it does not measure better than what you can properly stabilize the reference voltage. Any failure to keep the reference stable will result in very bad measurement values. It's easy to quickly get jitter in measurements of 10% or more. So besides an exact reference to get the measurement scale correct, you also want some LC construct to remove all jitter on the reference. Especially important if the reference has some relation to VCC and the wildly varying current consumption of the processor.

Reply
  • I don't think you have mentioned how much the read value varies.

    But one issue with the ADC is that it does not measure better than what you can properly stabilize the reference voltage. Any failure to keep the reference stable will result in very bad measurement values. It's easy to quickly get jitter in measurements of 10% or more. So besides an exact reference to get the measurement scale correct, you also want some LC construct to remove all jitter on the reference. Especially important if the reference has some relation to VCC and the wildly varying current consumption of the processor.

Children