Connect with us

help with my atmega16 ADC conversion

Discussion in 'Microcontrollers, Programming and IoT' started by aishiqi, Jul 21, 2011.

Scroll to continue with content
  1. aishiqi

    aishiqi

    9
    0
    Jan 4, 2011
    i want 10 bit precision of ADC with my code below.but the problem is that the result does not change Continuously while i change the voltage continuously with two Precision potentiometer.
    do you konw what i mean??

    for example :

    now ADCL is 0x56.i turn the potentiometer slowly, but ADCL doesn't change immediately .i keep turning, suddenly ADCL changes to 0x60,then 0x62,then0x63,then0x71;it can't be 0x57,0x58,0x59,0x61...........


    i hope someone can help me!! thanks a lot first .


    this is my code:

    #include<iom16v.h>

    unsigned long angular,adth,adtl;
    unsigned char count=0,adjok=0;
    unsigned long speed=0;
    unsigned long temp;
    adinit()
    {
    ADMUX=0xc0;
    ACSR=0x80;
    ADCSRA=0xc8;
    }
    uinit()
    {
    UBRRL=51;
    UCSRB|=0x88;
    SREG|=0x80;

    }

    portinit()
    {
    DDRA=0;
    PORTA=0x00;
    }

    delay(){
    unsigned int i;
    for(i=0;i<100;i++);
    }
    sendchar(char ch)
    {
    while(!(UCSRA&0x20));
    UDR=ch;}

    adjust()
    {SREG&=0x7f;
    speed=0;
    angular=0;
    count=0;
    adjok=0;
    SREG|=0x80;
    }

    #pragma interrupt_handler adcsvr:15
    adcsvr()
    {
    adtl=ADCL;
    adth=ADCH;

    ADCSRA=0xc8;
    //sendchar(adth);
    sendchar(adtl);

    angular=angular+((adth<<8)+adtl)*1000-speed;

    if(adjok==0)
    {
    if(count<255) count++;
    else
    {adjok=1;
    speed=angular/256;
    }
    }

    }

    main()
    {
    MCUCR=0x00;
    uinit();
    portinit();
    adinit();
    delay();
    adjust();
    while(1)
    {
    /*sendchar(adtl);
    sendchar(angular>>24);
    sendchar((angular>>16)&0xff);
    sendchar((speed>>8)&0xff);
    sendchar(speed&0xff);
    delay();
    */


    }

    }
     
  2. JoeyAVR

    JoeyAVR

    16
    0
    Aug 25, 2011
    When debugging an ADC always start off by not doing any mathematical cleverness, just display the raw data. That way you can be sure what you're getting.

    Very often ADC errors aren't errors - its the voltage you're measuring that isn't what you expect it to be!

    What hardware are you using. Have you copied the example layouts and decoupling in the data sheet?

    Is it possible that there is a jump in pot values due to dirt or construction? Measure the wiper voltage with a DVM at the same time and see if it really does jump.

    Joey
     
  3. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,411
    2,779
    Jan 21, 2010
    Do you have the pot connected across the power supply and the wiper connected to the ADC pin? (i.e. not connected to just one supply rail)

    What is the resistance of the pot? (is it too high?)

    +1 to the DMM and the raw data.
     
  4. duke37

    duke37

    5,364
    769
    Jan 9, 2011
    I was involved with a large data logger some time ago which had a similar problem. A large capacitor was charged up and the voltage measured as it slowly discharged. The measured value came down in steps with a resolution of about 8 bits.

    The problem was digital interference into the analogue input. Make sure that the digital and analogue circuits have independant grounds.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-