I use the following part of code to read the ADC value:
Code:
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
delay_us(10);
ADCSRA|=0x40;
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
while (1)
{
A1=read_adc(0);
lcd_gotoxy(0,0);
sprintf(buf,"L1:%d%d%d%d",A1/1000,(A1%1000)/100,(A1%1000%100)/10,A1%1000%100%10);
lcd_puts(buf);
}
The value that I see in the 16x2 LCD is always changing (very very fast). Is there any way to overcome this so that ADC value will be updated slowly, at least I can see it??
There are two methods for that. You could read ADC at a slower rate, or you could update the result on LCD at a slower rate. I have heard people using both techniques. If you ask me, I prefer the second approach. The ADC result could be used from other parts of the program as well, like the detection of a low AC level for example, if we assume that the ADC is used to read mains voltage. Since you are not keeping a timebase in this sample program, you could experiment with cycles delays like this:
Code:
#define _VISUALIZATION_CYCLES 100000ul
unsigned long cnt=0;
while (1)
{
A1=read_adc(0);
cnt++;
if (cnt >= _VISUALIZATION_CYCLES)
{
cnt = 0;
lcd_gotoxy(0,0);
sprintf(buf,"L1:%d%d%d%d",A1/1000,(A1%1000)/100,(A1%1000%100)/10,A1%1000%100%10);
lcd_puts(buf);
}
}
You could then experiment with _VISUALIZATION_CYCLES value, to achieve the result that is most convenient for you.