We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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.
how much does the data 'vary'? if it 'varies', say, 2% the possible reasons are very different from the potential causes of a variance of, say, 50%
post a series of readings
Erik
for a 3.5v the data is 1023.when im using a sensor the data is varying from 990 to 1023 for a 3.5v. similarly whwn sensor detects a valu the data is varying +/- 30 value.at 0v its is varying up to 16 from 0 value.
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.
what kind of filters should i use to make my sensor output stable.so that my adc output should not vary continously.
is any thing can be changed in the code (i.e conversion from binary to decimal).so that i can stable my output.
You can reduce the noise by software filtering. But note that bad filtering in hardware will probably result in not just noise by also significant scale/offset errors.
Note that I didn't ask how you connected your sensor to the ADC. I asked how you filtered the reference voltage for the ADC, and how this 3.3V is isolated from the 3.3V VCC that powers the processor.
You really, really, should take a look at GND/VREF/VCC and try to make them as stable as possible.
Filter caps on VCC - very, very close to the processor GND/VCC pins. Filter caps on VREF - and inductors in series with the signal after it splitted off from VCC.
Have you compared your design with available reference designs? You can find the schematics for the Keil boards on this site.