The output is varying continously in my lcd even there is no change in the adc input.i want a code to display the output in lcd.please give any suggestions to my code.
#include <lpc21xx.h> /* LPC2200 definitions */ #include <stdio.h> /* standard I/O .h-file */ //#define VREF 3 int i,j; long val,adc_val; unsigned char d1=0,d2=0,d3=0,d4=0,d5=0,d6=0;
//extern void init_serial (void);
void delay(void); void adc_init(void); void adc_read(void);
void data(void); void lcddata(unsigned char c); void lcdcmd(unsigned char c); void lcdinit(void); void lcddisplay(unsigned char *ptr); void message(unsigned char k,unsigned char *ptr1);
int main() { PINSEL0=0X00000000; PINSEL1=0X00400000; IODIR0=0X70000000; IODIR1=0X00ff0000;
lcdinit(); delay(); //lcdcmd(0x01); //delay(1000); message(0x80,"ir measurement"); adc_init(); while(1) { adc_read(); data(); delay(); } }
void adc_init(void) { //PINSEL1=0x01000000; ADCR&=0x00000000; VPBDIV = 0x02; /*Set the Pclk to 30 Mhz */ ADCR|= 0x00210601; }
void adc_read(void) {
ADCR|= 0x01000000; /* Start A/D Conversion */ delay(); delay(); delay();
while ((ADDR & 0x80000000) == 0); /*Wait for the conversion to complete */ val=ADDR; adc_val = ((val>> 6) & 0x00FF); /*Extract the A/D result */ }
void delay(void) { for(i=0;i<=75;i++) for(j=0;j<=1000;j++); }
void lcddata(unsigned char c) { IOCLR1=0x00ff0000; IOSET0=0x10000000; // rs =1 p0.28 IOCLR0=0x20000000; // rw =0 p0.29 IOSET0=0x40000000; // en=1 p0.30 IOSET1 = c<<16; delay(); IOCLR0=0x40000000; //en=0 p0.30 }
void lcdcmd(unsigned char c) { IOCLR1=0x00ff0000; IOCLR0=0x10000000; // rs =0 p0.28 IOCLR0=0x20000000; // rw =0 p0.29 IOSET0=0x40000000; // en=1 p0.30 IOSET1 = c<<16; delay(); IOCLR0=0x40000000; //en=0 p0.30 } void lcdinit() { lcdcmd(0x38); delay(); lcdcmd(0x01); delay(); lcdcmd(0x0c); delay(); //lcdcmd(0x01); //delay(); lcdcmd(0x80); delay(); }
void lcddisplay(unsigned char *ptr) { while(*ptr) { lcddata(*ptr); ptr++; } }
void message(unsigned char k,unsigned char *ptr1) { lcdcmd(k); delay(); lcddisplay(ptr1); }
void data(void) {
d1=adc_val/10; d2=adc_val%10; d3=d1/10; d4=d1%10;
//d5=d3/10; //d6=d3%10;
lcdcmd(0xc0); delay(); lcddata(d3+0x30); //lcddata(d6+0x30); lcddata(d4+0x30); lcddata(d2+0x30);
}
1) Debug to find out if the "varying" data you see are correctly captured or not. 2) Debug to find out if the "varying" data you see are correctly displayed or not. 3) Decide if you need to implement software filtering as low-pass filter. 4) Decide if you need to improve the voltage reference or better filter the supply voltages to reduce noise.
i checked the reference voltage .it is 3.3v the value is varying contuniously even there is no change in the input from +/- 30 value for 0v and 3.3v and in between.
So you have to improve your hardware. More filtering both for supply voltage and reference voltage. With proper hardware, it is only the last bit that should show some noise.
Go back and check for reference designs, and compare with your own hardware. Notice that ground-plane bounces are just as bad as noise in the ADC reference voltage or the supply voltage.
By the way - exactly how are you isolating your 3.3V supply voltage from your 3.3V analog reference voltage? The supply voltage suffers huge current spikes caused by the running processor.
im directly connected my sensor output to the controller adc 0.0.
View all questions in Keil forum