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 } }
Per, the problem isn't in VREF pin, I just tested, with a regulated DC power supply on 3V3 and the result was the same :/ and John, thanks for all the helping :)
How to Remove fbcdn-sphotos-a-a.akamaihd.net Popup Tabs.
--
Most regular visitors would not click suspect links.
There is no popups, actually is just the address of the image in web. But doesn't metter anymore, because I've found out that the circuit isn't the problem, sorry about the link ..