hey
i am using LPC 2148. and configured the hardware for taking the analog signal at P0.28 which is ADC0 channel 1.
i am using following code but the output stays 0 or 1023 only.
my hardware connections are verified with several ready made boards and kits for the same controller..
kindly check and help for my problem..
thanks
#include<lpc214x.h> #include<stdio.h> //VPB clock 30Mhz void delay(int); extern long val,stat,s; extern long adc_val; int main() { serial_init(); clear_arrays(); adc_init(); //printf("MISSAR SYSTEMS\n\n"); while(1) { adc_read(); printf("%i\n",adc_val); delay(1000); } } void adc_init(void) { PINSEL1 = 0x01000000; // P0.28 - AD0.1 PCONP |= 0x00001000; AD0CR &= 0x00000000; AD0CR |= 0x00201302; // with clock = PCLK/(7+1) = 30Mhz/8 = 3.75Mhz AD0INTEN &= 0x00000000; } void adc_read(void) { AD0CR |= 0x01000000; // Start AD conversion NOW on AD0.1 (P0.28) delay(100); do { val = AD0DR1; // Get value } while ((val & 0x80000000) == 0); // until bit 31 is high (DONE) val = (val>>6); adc_val = val & 0x3FF; // Extract AD result } void delay(int delay_value) { int out_delay=0,in_delay=0; for(out_delay=0 ; out_delay < delay_value ; out_delay++) { for(in_delay=0 ; in_delay <= 1000 ; in_delay++); } }
Hi
In this part
val = AD0DR1; // Get value } while ((val & 0x80000000) == 0); // until bit 31 is high (DONE)
you assign the ADC register to a variable and then you use a while on that variable which will never change. You have to use the actual register in the while loop to detect when you have a result.
Alex
dear sir,
i have made changes as u said. but still there is no change in out put.
the routine in which the changes are made is...
void adc_read(void) { AD0CR |= 0x01000000; // Start AD conversion NOW on AD0.1 (P0.28) delay(100); while ((AD0DR1 & 0x80000000) == 0); // until bit 31 is high (DONE) val=AD0DR1; adc_val = (val>>6) & 0x3FF; // Extract AD result }
the output stays 0 up to certain limit and then jumps to 1023 directly. its kind of when voltage crosses digital voltage level of 0 to 1 it goes from 0 to 1023.
Do you have a valid voltage reference connected? Your results sounds a lot like a chip with zero reference voltage.
yes sir,
i have connected 2.5v reference on the Vref pin. also checked voltage on the uC pin itself.
Are you 100% sure that you do have 2.5V on the pin, and not just on the PCB pad?
yes sir.
firstly the problem is solved..
i have measured the voltage on the pin itself.. and it was 2.5v only on pin. but the problem was the pin next to the Vref pin was having some king of short ckt with the vref.
actually the short ckt was not visible. but when u teld me that it seems like 0v ref so i just tried to re solder and removed any short ckt by blade.
and it worked..
thanks a lot for your support..
also for many people facing the same problem.. Do always verify the hardware..
Good that you got it working :)
And it is also very nice that you reported back the outcome. It's so much more valuable for other people who happen to find an old thread to not just see similar problems but also see the outcome.
Since you solder the chips you should get a magnifier about 15x, it helps a lot to check the correct soldering. Also a strong light behind the PCB (the opposite side of the chip) will show if the chip alignment is correct or if there is any short circuit problem with the pins.
thanks a lot.. i'll surely follow the advise about soldering and verifying it in future now on..