ADC in ATmega32 ... VREF

Thread Starter

senator_31

Joined Apr 23, 2011
3
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.

Rich (BB code):
unsigned int read_adc(unsigned char adc_input, int VREF_TYPE)
{
ADMUX=adc_input | (VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(20);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete

while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}


void main(void)
{
ADMUX= 0x40 & 0xff;
ADCSRA=0x86;

  while(1)
  {

      delay_ms(10);
      result = read_adc(0, 0x40 );
      voltage=(result+1)/1024*5.0;

      result = read_adc(1, 0xC0 );
      temp=(result+1)/1024*2.56;

  }      
}
 
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."
 
Top