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.
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;
}
}