Pages: [1]   Go Down
Author Topic: strange changing analog Reference behaviour  (Read 1796 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I have a program on the Arduino UNO Board that reads one analog pin with analogRefernce(DEFAULT), if this value ist below 200 it changes the analog reference to INTERNAL and reads the value again, to spread the accuracy.
But this does not work as expected I always get nearly the same value as with the DEFAULT-Reference and not as expected an approx. four times value.

After experimenting for a while and finding something related here in the discussion boards, I did a for loop for the second reading that reads the value with the INTERNAL-Reference twenty times and printing it to serial console. The measured values are starting with an value like the reading with the DEFAUL-Reference and then increasing with each reading. Reaching a stable value as expected about 4 times the  first reading after 7 to 10 readings. So I use this for loop as an workaround only using the last value I got after changing the analogReference.

Can someone explain me why this happens?
Is it the same for other arduino boards?

If this is by hardware design and not a bug in the firmware. It should be mentioned with an example on the documentation page for analogReference();. I had some very hard hours before finding my solution, thinking i did something wrong.
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 64
Posts: 6055
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What if you put a big delay (1-2 seconds) between changing the reference and the first reading?  Same behavior?
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried it with a delay of 500ms that was not enough. I will give it tomorrow another try with some increasing delays to see what will happen. Anyway either behaviour and workaround should be mentioned in the reference.
Logged

Worcester, MA
Offline Offline
God Member
*****
Karma: 2
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've done a lot of testing with this...http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1280424364 I was trying to make an autoranging ammeter.

It only takes about 5.5 ms for the reference voltage to switch from DEFAULT to INTERNAL, this delay is because of the 100nF cap on the AREF pin.  In your loop you will actually have to throwaway the first 50 readings or so before you get a stable reading.  

Also keep in mind the stabilization time does not start from when you change analogreference, it starts from the first analogread after you change the reference.
Logged

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I added a note about this to the analogReference() page: http://arduino.cc/en/Reference/AnalogReference.  If you can suggest more precise wording based on the datasheet or observed behavior, I can update it.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello thank you for adding it to the reference page. I suggest to add some more words. I am not a native speaker an expert. But from what I got in the mentioned threads. Something like your sentence plus added:

A safe way after changing the reference ist to do an analogRead wait for 6ms with delay and then the next reading should be fine.

would be great.
Logged

Pages: [1]   Go Up
Jump to: