SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By cahofmeyr3
I'm using an ATMEGA8 and trying to get the ADC to work.
I have a 10k potentiometer connected between two 330 ohm resistors, and according to my multimeter this yields a linearly varying voltage of 0.16V to 4.85V.

Unfortunately, when I read ADCL and ADCH after a conversion, ADCL only varies from 0 to 64 and ADCH is always 0.

I've used Vcc as a reference voltage, and I've also tried connecting 5V to AREF and using that.

Any help would be appreciated
User avatar
By leon_heller
Are you reading ADCL first and ADCH next? The order is important.

By cahofmeyr
User avatar
By leon_heller
I can't think what the problem is. It's a long time since I used an AVR ADC, but I didn't have any problems.

By ryowens84
Have you configured the ADMUX register and double checked that you've selected the correct channel and reference?

Maybe post your code so we can see how your are starting the conversion and getting the result. If you read the result out of ADCL and ADCH before the conversion is completed, you won't get the proper reading.
By hdon
If you're using the open source avr-libc, you can use ADCW to retrieve a 16-bit wide value.