Problem with AREF input (MEGA2560)

Hi all,

Working on a MEGA2560, and I would like to set the analog voltage range to 3.3V.

Related to this, the main page says:

http://arduino.cc/en/Main/ArduinoBoardMega2560:
... By default they measure from ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and analogReference() function.

There are a couple of other pins on the board:

AREF. Reference voltage for the analog inputs. Used with analogReference().

Right .... And then, the analogReference page says:

http://arduino.cc/en/Reference/AnalogReference:
Don't use anything less than 0V or more than 5V for external reference voltage on the AREF pin! If you're using an external reference on the AREF pin, you must set the analog reference to EXTERNAL before calling analogRead().

So, the way I'm reading this, AREF should be an input pin (in other words, Hi-Z/high-impedance pin), to which I should be able to bring some sort of a reference voltage source.

However, the problem is that AREF by default, constantly generates a 5V reference!

Ok, so then, I thought that the problem is with the analogReference function, so in my code, I added first in setup:

void setup()
{
  // set up the analog reference pin; 
  analogReference(EXTERNAL);
...

.... and NOTHING happens - the AREF pin STILL generates +5V... How do I know this? Well, I made a small jumper that connects the Arduino 3V3 pin to AREF pin: and the 3V3 pin measures 3.3V when it is unconnected - but as soon as I connect it to the AREF pin, it is forced to 5V!!! I'm thinking, this cannot be good..

So will someone explain to me:

  • Obviously, the AREF pin behaves like a voltage source; is it supposed to behave like a Hi-Z input at times?

  • Is the analogReference(EXTERNAL); supposed to make the AREF pin behave like an input?

If I'm going completely wrong with the statements above - what would I need to do, in order to set the analog voltage range to the 3.3V that come out of the 3V3 pin of the Arduino?

Many thanks in advance for any answers,
Cheers!

Ok, I think I found what the problem is...

Basically, the doc2549 - MEGA2560 datasheet on pg 276 gives a schematic, where we can see that AREF is basically led to the output of a transistor - the transistor otherwise feeding the choice between AVCC and internal reference. Obviously, if this transistor is ON, then AREF will behave as a voltage source.

Thus, the trick is to turn off this transistor - and that is controlled by bits REFS(1:0) - the most significant bits of ADMUX register; specifically, to turn the transistor OFF, REFS(1:0) have to be set to 0 0.

In my case, the loop part of the code (which is not listed above in the OP), actually sets specifically ADMUX in order to sample, and I realized it is set to 0b01xxxxxx - which selects the AVCC reference... Since this part ran in the loop, it basically cancelled any influence analogReference(EXTERNAL) may have had - and hence I kept getting a 'voltage source' behavior from AREF pin.

As soon as I changed the ADMUX to be set to 0b00xxxxxx - the AREF pin seems to behave; it basically sits at 0V, and when 3V3 is brought to AREF - AREF seems to happily accept it now...

Well, hope this may help others in similar trouble :slight_smile:
Cheers!

Thank you for the follow-up.

Why are you changing ADMUX? For most folks, the Arduino Core manages that detail. Are you using the analog-to-digital converter in a non-Arduino way?

Hi Coding Badly,

Yup - I'm trying to use the ADC on higher frequency, and so trying to do the MUX switching and ADC sampling "manually" in separate steps...

Cheers!

Yup - I'm trying to use the ADC on higher frequency, and so trying to do the MUX switching and ADC sampling "manually" in separate steps...

Be sure to check the accuracy of reading a value following a mux channel change. Several of us found it took some time for the channel to 'settle down'. As your going for increase ADC conversion speed, be sure to check that out carefully.

Lefty