13 posts / 0 new
Author
Message

So I'm learning about the ADC now and I'm trying to make a conversion from PC5 and print the output to my LCD. The output value is always 1023 from the ADC and I'm not sure why. I have two 1k resistors wired up and I'm taking the vout from between them.... the voltage should be half of the source so the value should be 512?

Here is my breadboard - http://s29.postimg.org/ns2g8r32v...

Here is my code - http://pastie.org/10071039

Thanks in advance for any help.

EDIT:

## Attachment(s):

This topic has a solution.

Last Edited: Fri. Apr 3, 2015 - 03:28 AM
This reply has been marked as the solution.

Couple of things,

1) your LCD init, and ADC init, only need to be called once, so do that BEFORE you enter the while(1) loop.

2) you set the reference in :



InitADC()
// Select Vref=AVcc
ADMUX |= (1<<REFS0);

But then you clear it here in getADC:

ADMUX=0x05;

which leaves the reference connected to nothing

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Thanks so then can I call

ADMUX|=5;

To keep the ref connected?

Or just set up the mux in the INIT routine and be done with it if you are only using the one channel

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Wanted to have the code available to use multiple channels later if I needed to.

I changed my code to the following and it worked like a charm thanks to you!

http://pastie.org/10071093

One problem though...

I have two 1k resistors... by my calculations shouldn't that HALF the voltage if I take the VOUT from between the resistors? (ref is 5v).... I'm using a USB power source.

Currently my adc is telling me 932 which equals out to 4.55Volts

Edit: Just measured with my multimeter and I'm getting 4.33 volts from VOUT between the resistors to ground.

Last Edited: Fri. Apr 3, 2015 - 03:45 AM

Do you have a voltmeter to measure the voltage at the pin?

Edit:we posted at the same time. I see you found your problem

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Last Edited: Fri. Apr 3, 2015 - 03:46 AM

Yes but isn't the forumula the following -

Vout=Vin( (R2) / (R1+R2) )

So 5( 1000 / (1000+2000) )

The voltage should be 1.6V

Post a schematic. I am not looking at that horrible picture. And what is the voltage at the avr pin? That's what the avr sees, not your resistor network

Edit:look at the formula, and the numbers you have posted. I think you have a boo boo based on the picture(hint)

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Last Edited: Fri. Apr 3, 2015 - 04:06 AM

4.58 at the pin. If you look at the picture you can see the top left of the ATMEGA is a black wire on pc5 going to between two 1k resistors. My schematic looks even worse than this picture. Not sure how to make it all look good with so many connections going everywhere.

Check the resistor going to ground. Maybe the ground really is not connected. Or you have an incorrect value resistor?

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user