I'm using atmega32 µc with the internal 10-bit ADC. I connected my potentiometer to the ADC 1 and I'm using 5 V Voltage Reference.

using the following code, I did the ADC-config

void ADC_init(void)
{

ADMUX  |= 1<<REFS0 ;  // Config VRef (external Vref in this case)

}


Then in Main function I am calling the following function each 1000ms and send the data to the USART interface

void ADC_measure(void)
{
_delay_ms(50);

_delay_ms(50);

_delay_ms(50);

_delay_ms(50);

_delay_ms(50);
//start the the measure conversion
}


The problem is : when I open the terminal , I see only the ADC Value = 255 or 248 increasing or decreasing the potentiometer value doesn't change the ADC value.

what can I do now?

• You're using the pot as a voltage divider, right? – Ignacio Vazquez-Abrams Sep 7 '14 at 15:59
• Why not use the ADC interrupt? I have no idea if your conversion is finished when you're reading the result register, because you're not even checking if it's done -- you're just delaying some arbitrary amount of time, and blindly reading the register. There are two ways I typically see ADC code implemented: using interrupts, or burning time in a while loop waiting for the "conversion finished" flag to be set. – Jay Carlson Sep 7 '14 at 16:18

You have incorrect multiplexer setting. To select channel 1, it should be

ADMUX  |= 1<<MUX0 ;  // ADC-Channel 1


Edit: Another thing is incorrect clock prescaler. To get $f_{clk}/128$:

ADCSRA |= 7<<ADPS0;  // Assign ADC-prescaler 128

• thanks for your reply. but it still have the same problem – user3213767 Sep 7 '14 at 17:05

Try:

ADC_TenBit = (uint16_t)ADCH<<8 | theLow;


And you did declare ADC_TenBit uint16_t, right?

• thanks for your reply. it works for the first measurement then again fails. the values are 255 or 290 or 245 ...just in this range. independent of the input Signal – user3213767 Sep 7 '14 at 17:03