ADC in ATmega32 ... VREF

Discussion in 'Embedded Systems and Microcontrollers' started by senator_31, Apr 23, 2011.

  1. senator_31

    Thread Starter New Member

    Apr 23, 2011
    3
    0
    Hello friends .. nice to be here with u :)

    i am using Atmega32 ADC to measure a 5V analog voltage and also get the temp. through LM35 temp sensor (it doesn't output more than 2 volts).

    when i use AVCC = 5 volts as reference (for all conversations) it is working properly, but i want to change the ADC_VREF_TYPE in the program it fails.

    i want to make an ADC conversation using ADMUX=0x40 (AVCC ref.)
    then make another ADMUX=0xC0 (internal 2,56V ref.)
    then i used a formula to change the steps to corresponding voltages and temperature and display the result in an LCD.
    unfortunately it's not working and the results keep changing without any changes in the voltages and temp.
    i don't know where is the problem :s

    can i get some HELP plz.

    Code ( (Unknown Language)):
    1.  
    2.  
    3.  
    4.  
    5. unsigned int read_adc(unsigned char adc_input, int VREF_TYPE)
    6. {
    7. ADMUX=adc_input | (VREF_TYPE & 0xff);
    8. // Delay needed for the stabilization of the ADC input voltage
    9. delay_us(20);
    10. // Start the AD conversion
    11. ADCSRA|=0x40;
    12. // Wait for the AD conversion to complete
    13.  
    14. while ((ADCSRA & 0x10)==0);
    15. ADCSRA|=0x10;
    16. return ADCW;
    17. }
    18.  
    19.  
    20. void main(void)
    21. {
    22. ADMUX= 0x40 & 0xff;
    23. ADCSRA=0x86;
    24.  
    25.   while(1)
    26.   {
    27.  
    28.       delay_ms(10);
    29.       result = read_adc(0, 0x40 );
    30.       voltage=(result+1)/1024*5.0;
    31.  
    32.       result = read_adc(1, 0xC0 );
    33.       temp=(result+1)/1024*2.56;
    34.  
    35.   }      
    36. }
    37.  
    38.  
     
  2. senator_31

    Thread Starter New Member

    Apr 23, 2011
    3
    0
    i am using ISIS to simulate the cct
    and codevision to write the software.
     
  3. blacknewnew

    New Member

    Aug 19, 2010
    3
    0
    I think you have already connected 5v to the VREF pin, so when switch Vref source to the internal one, 2.56v and 5v are shorted.

    please refer to Page 208 of the ATMEGA32 datasheet for details:
    "If the user has a fixed voltage source connected to the AREF pin, the user may not use the other reference voltage options in the application, as they will be shorted to the external voltage."
     
  4. senator_31

    Thread Starter New Member

    Apr 23, 2011
    3
    0
    Thanks alot blacknewnew 4 replying
    i thought i was alone ;)

    i am going to update my design and tell u .. hope it works :)
     
Loading...