Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need Help: AVR Analog-to-Digital Converter

Status
Not open for further replies.

Don_dody

Full Member level 1
Full Member level 1
Joined
Nov 4, 2012
Messages
96
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Indonesia
Visit site
Activity points
1,921
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.
 

Hi,

Add in a delay of say ms(250) after each ADC result.

You may find the lsb of the result fluctuate a lot, even if the input is stable; often over come by running a x16 averaging routine
 

Thanks for helping.
I need to use this ADC value for another program and it should be accurate. If it changing too much, I bet I'll get more problem.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top