Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Wrong ADC reading

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 945
Location: the Netherlands

netherlands.gif
PostPosted: Wed Oct 16, 2013 11:11 pm    Post subject: Wrong ADC reading Reply with quote

Hi,

On my desk i have 3 prototype's with an Atmega1281 on it.
There are 24, 10 and 3.3 VDC powersupply's on board.
Each powersupply feeds a resistor divider, in the middle of the divider there is a resistor of 10K to the ADC pin of the 1281.
For example the 3.3 volt goes into a resistor divider of 2 x 10k, so in the middle there is 1.65 volt (in reality 1.79 volt).
This middle point voltage goes to a 10K resistor to the ADC pin.
So far so good, but.

With a reference voltage of 2.56 i expect an ADC reading of (1024/2.56)x1.79=716
But the actual reading is 844 !!!
The same is valid for the 24 en 10 volt measurements, the ADC reading is not as expected (to high).
When i measure the voltage on the ADC pin it is 2.11 volt which compares to 844, so this is fine.
But where is the 2.11 volt coming from, in the middle of the divider the voltage is 1.79 volt
So there is a voltage of 0.32 over the resistor which is in serie with the ADC input pin.

All the proto's act the same.

This is the config ADC line:
config ADC = single, prescaler = auto, reference = INTERNAL_2.56
The voltage on the Aref pin is 2.55 volt, so the reference voltage is correct.


Frank.

(BASCOM-AVR version : 2.0.7.6 )
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2470
Location: Queensland

australia.gif
PostPosted: Wed Oct 16, 2013 11:35 pm    Post subject: Reply with quote

Sounds a bit like you have the ADC port set to inputs ( correct ) but with pullups enabled ( not correct ). Try explicitly setting

portf = 0

in your configuration code.
I presume you have the AVCC line connected to Vcc, as it must be.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 945
Location: the Netherlands

netherlands.gif
PostPosted: Thu Oct 17, 2013 8:02 pm    Post subject: Reply with quote

Avcc is connected to Vcc which is 3.3 volt
I did try the PORTF = 0 but in doesn't help.

This is really strange.
The proto's are a renewal of an earlyer design with an Atmega64 on it.
On that design there was no problem and the hardware concerning the 24, 10 and 3.3 volt is not changed.

What's next to try?
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4970
Location: Holland

blank.gif
PostPosted: Thu Oct 17, 2013 8:24 pm    Post subject: Reply with quote

I assume you disabled jtag?
And did you connect via L and decoupling cap as shown in the manual?
That it worked with a different older chip means nothing. only that the chips have different characteristics.
I would remove the chip connections to the A/D input and then measure the resistance divider. Is that really giving the right voltage?
You can also try to connect a small cap to the input pin of the a/d converter. it will remove noise. i guess what you pick up is noise. for the a/d converter it is important that none of the port pins from the a/d converter switch during conversion.
forget that your old design worked : just start at the begin step by step.

_________________
Mark
Back to top
View user's profile Visit poster's website
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 945
Location: the Netherlands

netherlands.gif
PostPosted: Thu Oct 17, 2013 8:38 pm    Post subject: Reply with quote

aaargh, it was the JTAG.

Everytime when i read here the advise to disable JTAG (and that is quite often) i think to myself "everybody know that you must disable JTAG"
And now i do it myself.
I guess i think that i got what i deserve, i will no longer think bad about others.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4970
Location: Holland

blank.gif
PostPosted: Thu Oct 17, 2013 8:51 pm    Post subject: Reply with quote

I only mentioned JTAG for users that read this topic later. I could not imagine you would have checked this first thing. But i know one can become blind for certain things ;-0
_________________
Mark
Back to top
View user's profile Visit poster's website
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 403

newzealand.gif
PostPosted: Sun Feb 15, 2015 9:22 pm    Post subject: Reply with quote

When reading an ADC pin, do you have to configure the pin as an input and turn off the pullup, or is this done for you in the getadc(xxx) command? The help does not show the pin being configured, but several authors have mentioned "turn off the pullup explicitly"
_________________
Neil
Back to top
View user's profile
Plons

Bascom Member



Joined: 24 May 2005
Posts: 434
Location: Hilversum - The Netherlands

netherlands.gif
PostPosted: Sun Feb 15, 2015 11:43 pm    Post subject: Reply with quote

After reset, all ports are set as inputs with pull-up disabled. Therefor you do not need to worry about it ..... unless you alter the port configuration. AFAIK the Getadc(xx) does not alter the portsetting. A simple test can confirm this.
_________________
Bascom AVR ver 2.0.8.1
ProtectedParallelPortProgrammingDongle: http://www.aplomb.nl/TechStuff/PPPD/PPPD%20English.html
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel"
Back to top
View user's profile
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 403

newzealand.gif
PostPosted: Mon Feb 16, 2015 7:08 am    Post subject: Reply with quote

Thanks Plons.
_________________
Neil
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum