Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ATMega8 ADC Input Only Reads Max Value?

Status
Not open for further replies.

OMMad

New Member
i'm currently messing around with the adc on my atmega8 just to get an understanding of how ADC works because i plan to make a guitar tuner based on a circuit i found on the internet.

my question is, with 5v going into my adc input port i get a reading of ~1024 which is expected, but when i run the supply through a voltage divider i get reading of 0 even though my multimeter shows a voltage of ~2,5v from the output of my divider circuit.

i think this might be a problem with my program? can anyone help me troubleshoot this?

here is the program i've written

Code:
ADMUX = 0b00000000;
ADCSR = 0b10000000;
ADCSRA  |= (1<<ADSC);
  		
while (ADCSRA &  (1<<ADSC));  
adc_value = ADCW;
        
sprintf(buf,"%i ADC",adc_value);
lcd_clear();
lcd_puts(buf);
delay_ms(100);

thanks in advance for any solutions. i'm sorry if this is the wrong place to ask this question

EDIT:

I might be misunderstanding how to plug the input into the adc? i assume the adc port is connected to an output point between the two resistors but it doesn't seem to be reading it. both the microcontroller and the voltage divider share the same ground. what could be the issue?

i would also like to say that the lcd is working and all the ports are properly configured... it seems like the solution is very simple and i've just misunderstood how to properly hook up the circuit.
 
Last edited:
What voltage Reference You'll use?
You can use the internal 2,56V reference, an external reference or the 5V Supply Voltage.

The AVCC Pin should be connectet via a 10µH coil to +5V and must be decoupled with an 100nF Capacitator.
At the AREF Pin should be puttet an 100nF capacitator to GND.
The AGND pin has to be connected to GND.

At high Ohm Voltage dividers at the ADC Pin should be applied a little Capacitator ( 1nF...10nF ) at the ADC input Pin to GND.

Is the used A/D Pin configured with an additional function ( Think at the Fuses too ) ?

When all these ist done properly it should work.
 
The AVCC Pin should be connectet via a 10µH coil...

Never heard that.. bypass capacitor should be used in a good design, but a coil? What is the point? Put the coil+capacitor in the VCC pin to reduce current spikes in supply rail. I believe AVCC does not cause current spikes.
 
i've actually used both Avcc and an external reference voltage of 5v through Aref and i'm experiencing the same problem. it seems to me that the problem might be with how the output of the voltage divider is connected to the main circuit.

i've tested the adc with a 3,7v battery and gotten the proper readings ~768... and of course ground gives me 0 and vcc gives me a reading of ~1024. however, whatever the source, when i run it through the voltage divider i get no reading at all -- more accurately i get a reading of 0. i'm certain this is a connection problem with an embarrassingly simple solution.

i'd like to add that my voltage divider circuit is on a separate breadboard, whereas my main circuit is soldered onto a pcb matrix board. could there be a grounding issue? i'll upload a picture as soon as i get the opportunity.

thank you for the suggestions, i'll give them all a shot the next chance i get. right now i've only got a 1uF capacitor from Aref to GND. thanks again for the help.
 
...10µH Coil...Never heard that.. bypass capacitor should be used in a good design
Take a look into the Datasheet, there is a recommendation about this.

Take a look at Page 200 figure 96 of the ATMEGA 8 Datasheet.

It should avoid electrical disortion into the A/D Converter from the 5V Power Line.

It's not an absolute must, but it increases the stability of the A/D Converter.

@OMMad
I think your problem could be the impedance of the voltage divider.
At the input of the A/D Converter is a sample and hold circuit.
There is a little capacitator inluded. When the impedance of the voltage divider ist too high, this capacitator discharge the voltage nearly to 0V.
When putting in an external capacitator, this internal one gets only a little bit of charge of the external one, and the A/D Result is correct.

Look at Figure 95 of the Datasheet.
 
At high Ohm Voltage dividers at the ADC Pin should be applied a little Capacitator ( 1nF...10nF ) at the ADC input Pin to GND.

I think your problem could be the impedance of the voltage divider.

Ahh it seems that may be the problem. In which case I will indeed give your capacitor fix a shot and report the results here. I'm curious, however, since this high impedance seems to be caused by the resistor values, what would be the recommended resistor values for a divider circuit of this nature? considering Vcc is 5v and i'd like to divide that to 2,5v, i used a circuit of two 50k resistors to divide the voltage. is 50k too high a value?

once again all help is greatly appreciated. i'm quite new to electronics and this is all very fascinating for me.

UPDATE:
i switched out the 50k resistors with a pair of 1k resistors and now i'm getting an input, but it's still incorrect. i get a reading of 24 on the ADC when i should (theoretically) be getting a reading of 512, right? i'm going to try again with a pair of 500 ohm resistors next.

in addition i tried your solution of adding a capacitor from adc input to ground but it seems the capacitor i used is of the wrong value. i used a 47uF capacitor even though 10nF was recommended simply because that was the only capacitor i had available. the result was the adc still failed to read an input from the voltage divider circuit. i'm going to get my hands on smaller value capacitors in a few hours so i'll give them a test run.
 
Last edited:
With a resistor about 5 to 10k Ohm the Result should be OK.
I've done this many times and there was never a problem.

There could only be a couple of failures.

1 The ADC Frequency is wrong.
2 You've chosen the wrong reference in your code.
3 One or more decouple capacitator's are not included or at the wrong place.
4 One or more supply voltages of the A/D Converter failes.

I think Your problem is Nr.2. ADMUX=0b00000000; .
You've Choosen external reference Voltage. ( REFS0 and REFS1 Bit in ADMUX Register are 0 ).
Is there a proper reference Voltage?
Try 0b01000000 for AVCC as reference and include a 100nF capacitator at AREF Pin.
or 0b11000000 for internal 2,56V reference and capacitator at AREF Pin.

I would suggest You to take a look into the datasheet, it will prevent some problems.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top