SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By cahofmeyr3
#56513
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
#56514
Are you reading ADCL first and ADCH next? The order is important.

Leon
By cahofmeyr
#56538
Yes
User avatar
By leon_heller
#56539
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.

Leon
By ryowens84
#56584
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
#58343
If you're using the open source avr-libc, you can use ADCW to retrieve a 16-bit wide value.