Yet another AREF (EXTERNAL) Question

Hi all,

I’m starting my first project, a battery discharge tester, and have a question about using the external aref pin for a precision voltage.

My objective is to get a precise(ish) reading from an analog pin (mega256 is my test controller) to measure the loaded voltage of a battery. After reading many posts, blog articles, and general topics, I think I have an understanding of how the aref pin works. So far my observations are:

  • Internal/Default - uses VCC as the basis for the 10-bit ADC – can vary based upon what the actual voltage is
  • 1.1 or 2.56V - reference voltages that can be used – unsure if these are relative on VCC or actually close values
  • External - voltage provided that can be used as reference V for measurements - fraught with danger is not properly addressed on the inout circuit and sketch

I have an LM4040-4.1 that I’d like to use as the reference V. Overall though, I’d like to ensure that the circuit I design to provide the AREF voltage protects the Arduino from potential damage (e.g., in the event I upload the wrong sketch).

My understanding is that when the DEFAULT setting is used an analogRead() is issued, AREF it’s tied to the AVCC and there is no resistance is tied to GND. But when EXTERNAL is used, there is a 32K resistor. In reading, there is mention that if using an external V, a 5K resistor should be used to protect the AREF pin and allow for switching between INTERNAL and EXTERNAL voltages.

Not having a EE background, how does having a resistor between the external reference V and the AREF pin protect the circuit when reference is changed from external to internal? Is it because the resistor on the provided external source provides the reduction of current so it doesn’t blue smoke the pin?

Before I actually hook up the circuit, I’d like to understand the why of protecting the AREF pin.

And for an actual 4.096V reference, would the following be something that is suitable:

5V → 1K R → +LM4040- → GND

  • on the LM4040 tied to the AREF, which in turn is tied to 10K to GND and also parallel to the AREF 32K resistor if external, or 0R if changed to internal. The LM4040 appears to have a total draw of < 1mA, inclusive of the 128uA AREF draw.

Appreciate any guidance of clarification on how multiple voltage sources are dealt with…

Sorry, too much resistors confusion.

The AREF pin should not be connected to a resistor or voltage for most users. It is connected to the inside reference circuit inside the microcontroller.
That is why a 100nF from AREF to GND is recommended, for a nice noise-free reference.

Having DEFAULT (5V) reference is not always bad. When a sensor output is relative to the 5V, and the microcontroller reference is 5V, they eliminate small changes on the 5V. The result is always okay, even if the 5V changes.

The internal reference is a real voltage reference. But instead of 1.1V or 2.56V, the actual voltage is never 1.100V or 2.560V. The actual voltage could be measured at AREF and tuned in the sketch. In the sketch, perhaps a value of 1.053V should be used.
The reference voltage depends on the temperature, but it is good enough for most projects.

Connecting anything to AREF should be avoided. It should never be connected to AVCC via an external wire.

So far so good. Now about using an external voltage reference.

When a voltage is applied to AREF and the function analogRead() is used, there will be an internal shortcut inside the microcontroller, since the microcontroller was still using the 5V as reference or one of the internal voltage references.

To avoid that internal shortcut, use analogReference(EXTERNAL) before analogRead(), or use a protection resistor. The protection resistor might reduce the accuracy.

I suggest this: use 1k resistor from reference voltage to AREF to protect it during development. When you are sure that everything is okay, try without that resistor.

The LM4040 is minimal 60uA and maximum 15mA. In the datasheet some tests are for 100uA, 1mA and 10mA. Let’s not heat it up, so keep the current low. Let’s not have a too high impedance circuit, so use some more than 60uA. Perhaps something between 200uA to 1mA.
When the minimal voltage is 4.5V. 4.5 - 4.096 / 200uA = 2k
When the maximim voltage is 5.5. 5.5 / 2k = 2mA, fine with me.
I would use a resistor of 2k2.

If you don’t understand my explanation, just ask.

You are over-thinking.

Get one of these... http://www.adafruit.com/product/2200 ... Wire VIN to 5V on the Arduino. Wire 4.096 to AREF on the Arduino. Call analogReference(EXTERNAL) in setup. Enjoy very accurate very stable readings (4096/1024 = 4mV per step).

The schematic... http://www.adafruit.com/products/2200#technical-details-anchor is on that page if you want to build it yourself.

Peter_n: Sorry, too much resistors confusion.

The AREF pin should not be connected to a resistor or voltage for most users. It is connected to the inside reference circuit inside the microcontroller. That is why a 100nF from AREF to GND is recommended, for a nice noise-free reference.

Having DEFAULT (5V) reference is not always bad. When a sensor output is relative to the 5V, and the microcontroller reference is 5V, they eliminate small changes on the 5V. The result is always okay, even if the 5V changes.

The internal reference is a real voltage reference. But instead of 1.1V or 2.56V, the actual voltage is never 1.100V or 2.560V. The actual voltage could be measured at AREF and tuned in the sketch. In the sketch, perhaps a value of 1.053V should be used. The reference voltage depends on the temperature, but it is good enough for most projects.

Connecting anything to AREF should be avoided. It should never be connected to AVCC via an external wire.

Unfortunately MANY examples out there, [u]INCLUDING[/u] the arduino-on-a-breadboard example on http://arduino.cc/en/Main/Standalone (incorrectly) connect correct ARef to +5V.

I think I spend half my time on this forum correcting people who blindly follow them.

Coding Badly, why is there a parallel resistor ? that is not in the datasheet.

EDIT: corrected

Peter_n: AWOL, why is there a parallel resistor ? that is not in the datasheet.

What's AWOL got to do with this?

Paul__B: What's AWOL got to do with this?

Sorry, corrected, it is about the links in reply #2 by Coding Badly.

One moderator/ guru begins to look the same as another, eh? :grinning:

Yes, they do, Steve.

Thanks all for the comments. I probably expounded on too many things, so let me focus on trying to understand AREF, sort of like this post.

First, the reason I was looking at AREF was to get a more precise measurement of battery voltage to replicate other battery discharge projects I’ve seen. I started here:

http://www.skillbank.co.uk/arduino/measure.htm

and was going to basically replicate John’s circuit, with the exception of power source other than the Arduino itself:

Then I started to read about the “blue smoke” events that could take place.

I’m still trying to understand from a schematic what takes place when analogReference is INTERNAL vs. EXTERNAL.

EXTERNAL - There is a 32K resistor between the AREF pin and GND and no internal voltage source applied?
INTERNAL - There isn’t any resistance between AREF and GND, and AVCC is tied to AREF?

On the Mega2560 schematic I see the AREF, AGND, and AVCC but don’t see the 32K resistor or how the pins tie to INTERNAL or EXTERNAL. It’s probably my not understanding how to read the schematic.

If the above circuit with the LM4040 is good to provide protection in the event I accidentally have it connected and set to INTERNAL, I’ll start testing (with a change to the 560 ohm resistor to something that limit current on the Vref (AREF) wire.

I look at this as learning exercise for basic circuit design along with understanding tolerances and error limits for different ways of taking measurements.

[/quote]

Peter_n:
I suggest this: use 1k resistor from reference voltage to AREF to protect it during development. When you are sure that everything is okay, try without that resistor.

The LM4040 is minimal 60uA and maximum 15mA. In the datasheet some tests are for 100uA, 1mA and 10mA. Let’s not heat it up, so keep the current low. Let’s not have a too high impedance circuit, so use some more than 60uA. Perhaps something between 200uA to 1mA.
When the minimal voltage is 4.5V. 4.5 - 4.096 / 200uA = 2k
When the maximim voltage is 5.5. 5.5 / 2k = 2mA, fine with me.
I would use a resistor of 2k2.

If you don’t understand my explanation, just ask.

Sounds good. I’m shooting to keep the current < 400-500uA. There was good thread on Adafruit that went through some of the calculations of figuring the resistance of the shunt based on load (assume the load of the shunt + AREF pin) and then use that in parallel to the 32K resistance to calculate the resistor to place at the 5V source.

I’m dreaming this stuff. :slight_smile: Not a bad thing since I love to learn.

Peter_n: Coding Badly, why is there a parallel resistor ? that is not in the datasheet.

The explanation from Adafruit... http://forums.adafruit.com/viewtopic.php?f=19&t=62492

Those links are okay, good information. With a few remarks: When changing the mux, I do one dummy analogRead() and wait 20ms. I did not calculate the internal 32k resistance of AREF in my calculation. I'm not sure if that is an internal resistor or just the impedance of AREF. I would have to measure that. Perhaps I have to adjust my calculation.

You mentioned 'AGND'. There are large discussions about that. But I think there is an application note about it. To keep things simple: just accept that AGND and GND are connected to each other inside the chip.

AVCC is the VCC for the analog section. A LC filter can be used for AVCC so the digital noise from the ATmega chip itself does not go back into the analog section.

I think there is a picture in the datasheet, to which point AREF is connected internally of the ATmega chip.

When the DEFAULT (5V) or INTERNAL (1.1V or 2.56V) is used, there is no use to talk about an internal resistor. That is the reference voltage, and that's it. When you say that AREF is tied to AVCC, that is very confusing for us. When DEFAULT is selected, the voltage of AVCC is internally used as reference. When DEFAULT or INTERNAL is used, the AREF should be open. That is all done inside the chip.

gadams999:
EXTERNAL - There is a 32K resistor between the AREF pin and GND and no internal voltage source applied?
INTERNAL - There isn’t any resistance between AREF and GND, and AVCC is tied to AREF?

You need to send all this crap about “resistance between” back to where you found it. The only resistances involved are ones you provide.

The relevant sections of the ATmega328 datasheet are…

Figure 24-1. Analog to Digital Converter Block Schematic Operation

Table 24-3. Voltage Reference Selections for ADC

Coding Badly, I read the notes from Adafruit about the parallel resistor, and it stinks. They say that the internal resistance of 1 ohm has less effect with the parallel resistor when the ADC input changes the input resistance. I think that is totally nonsense. I think I can prove that the 10k parallel resistor makes it less accurate, since the changes of the 5V have more influence if the voltage is lowered with two resistors as voltage divider. I was using a range for the 5V of 4.5 to 5.5V. With that large range, the parallel resistor is doing more bad than good.

I still have to read about the 32k input resistance. I would like to do some measurements...

From ltspice simulations I came to the conclusion that the lower resistors increase the maximum voltage for VIN but otherwise have a negligible affect.

But I also have to idea what "dynamic reverse impedance" is or how to include it in calculations.

It is my understanding that, to function correctly, a shunt regulator requires a minimum load. An AVR analog input does not provide the necessary minimum load. By including the lower resistor, the regulator can also be used with an analog input (e.g. calibration or differential measurement).

Sorry Coding Badly, but I disagree. This is a two pin voltage reference. Having a "load" is already not what it is. The two resistors make a voltage divider with the 560 ohm parallel 10k as total resistance of the voltage divider.

For a 3-pin voltage reference it is something else of course.

I have done some measurements with this sketch and a Arduino Uno:

bool flagAread = false;

void setup()
{
  Serial.begin(9600);
  Serial.println("Sketch started");
}

void loop()
{
  if (Serial.available())
  {
    byte c = Serial.read();
  
    switch( c)
    {
      case 'a':
        Serial.println("continues analogRead");
        flagAread = true;
        break;
      case 'd':
        Serial.println("DEFAULT");
        analogReference(DEFAULT);  
        analogRead(A0);
        break;
      case 'e':
        Serial.println("EXTERNAL");
        analogReference(EXTERNAL);
        analogRead(A0);
        break;
      case 'i':
        Serial.println("INTERNAL");
        analogReference(INTERNAL);
        analogRead(A0);
        break;
      case 's':
        Serial.println("stopped analogRead");
        flagAread = false;
        break;
    }
  }
  if (flagAread)
    analogRead(A0);
}

When EXTERNAL is selected, there is actually an internal resistor from AREF to GND. It could be 32k, but I measured 37k. So it is not the input impedance, but it is seen from the outside as an internal pulldown resistor. Using analogRead() continuesly did not change it.

Suppose my previous calculated 2k2 resistor is used for the LM4040 voltage reference: 5.0V: (5.0 - (2k2/(2k2+32k)*5) - 4.096) / (2k2//32k) = 132uA through reference and 128uA into AREF. 4.5V: (4.5 - (2k2/(2k2+32k)*5) - 4.096) / (2k2//32k) = less than 60uA. That is not good. So my calculated value of 2k2 was wrong. Sorry for that.

Suppose a value of 120uA through the reference when the VCC is 4.5V is okay. That would result into 1k. 5.0V: (5.0 - (1k/(1k+32k)*5) - 4.096) / (1k//32k) = 624uA through reference and 128uA into AREF. 4.5V: (4.5 - (1k/(1k+32k)*5) - 4.096) / (1k//32k) = 124uA through reference and 128uA into AREF

My conclusion: There is an internal pulldown resistor of 32k inside the ATmega chip when EXTERNAL is selected. A value of 1k from VCC to LM4040 voltage reference is okay. Don't use an extra parallel resistor next to the voltage reference. For testing, a protection resistor of 1k from voltage reference to AREF could be used, but the values read with analogRead() will be very inaccurate. For accurate measurement, connect the LM4040 reference directly to AREF. Be sure to call analogReference(EXTERNAL) before any analogRead(), or else there will an internal shortcut.

[EDIT] Changed "2k2" and "1k" into "2k2//32k" and "1k//32k". I did not recalculate the result, it makes a difference of 3%.

Peter_n: My conclusion: There is an internal pulldown resistor of 32k inside the ATmega chip when EXTERNAL is selected. A value of 1k from VCC to LM4040 voltage reference is okay. Don't use an extra parallel resistor next to the voltage reference. For testing, a protection resistor of 1k from voltage reference to AREF could be used, but the values read with analogRead() will be very inaccurate. For accurate measurement, connect the LM4040 reference directly to AREF. Be sure to call analogReference(EXTERNAL) before any analogRead(), or else there will an internal shortcut.

Paul, I'm still trying to get my head around using a protection resistor or calling analogRead(EXTERNAL) first. Is the protection to limit the current (5mA on a 5V source w/ 1K) going to GND when transitioning between INTERNAL|DEFAULT and EXTERNAL? Or does that short combine the VCC of the Arduino + the VCC presented on the AREF pin?

If I use breadboard the following (4.096V reference:

and use the same 1K for Rs, the total current (Il) on the Vr is only ~800uA. In both aspects of voltage and current (4.096V and 800uA), that is less than just the 1k protection resistor alone.

I plan to make good use of your test code tonight if that is the case!

I don't understand what you mean, sorry. A protection resistor could be placed between Vr and AREF. The Vr is the Vr in the drawing that you added.

When you try my sketch with the LM4040 connected to AREF, and accidently select INTERNAL or DEFAULT, that is when the internal shortcut will happen. I'm not sure if that will damage the ATmega2560 chip (I'm not going to try it).

You are going to use the LM4040, so you have to always select EXTERNAL before any analogRead().