First of all, why would you want to do this? For A/D conversion accuracy, of course!

Consider: the normal mode of operating the A/D converter is to use the AVCC pin (nominally 5 Vdc) as a reference voltage. This pin is supplied by either the USB +5 volt input, or by external power (typically 12 Vdc), regulated down to 5 volts on the Arduino board. If you've ever measured the results of the USB power, you'll see that it's not anywhere near 5 volts - it's usually around 4.5 volts, and varies, due to the voltage drop across the USB backfeed protection diode on the Arduino board. Regardless of which source the AVCC voltage comes from, if you put a 'scope on it, you will see it fluctuates all over the place every time the processor switches a load on or off. If you want good A/D accuracy, this just won't do (unless you're using the same voltage as a source to your analog input device [like a potentiometer], where the variations cancel out).

One way of avoiding this problem is to switch the Aref over to the 1.1 Vdc internal reference. This reference is nice and stable, but limits the maximum input voltage that can be converted by the A/D to 1.1 volts. If you can live with this limitation, then you're good to go, using this method. If not, then you need to use a good, stable external reference.

Here's the problem: Inside the processor is a register-controlled switch which can connect the Aref pin to the AVCC input pin (a hard +5.0 vdc source). The Aref pin is connected to the output of the switch, to allow applying an external voltage when the switch is open. Unfortunately, if you tie a hard external reference to the Aref pin and accidentally close the switch with firmware, the Aref pin will hard tie to the hard AVCC pin, much current will flow, and things will burn up, starting with the switch.

You can protect the switch by feeding the Aref pin through a 4.7k resistor, which will limit the current flow. But there will be a voltage drop across the resistor because there's an internal 32k resistor from Aref to ground. Now you could calculate an appropriate applied voltage value which would feed this voltage divider such that the Aref voltage would be correct, but the temperature compensation would be mediocre, with one resistor inside a warm processor, and the other outside in the cold.

There's a better way: feed the Aref pin resistor with an op-amp, and connect the op-amp negative feedback input directly to Aref. The op-amp will generate whatever output voltage is needed (within its limits, of course) to keep its negative input pin the same as its positive input pin (tied to a stable reference voltage), and thus, the Aref voltage the same as the stable reference.

Example Schematic #1

[Click on the figure to get a large version]


Should the AVCC switch accidentally close, the Aref pin will be pulled up to AVCC, the op amp output will swing to its negative rail (assumed to be 0 vdc here), and the 4.7k resistor will limit the current to little over a milliamp, saving the processor from destruction.

If you're operating your op-amps on other than +5 vdc power, consider using this wiring method, which adds clamp diodes to the op-amp output, limiting maximum output swing to processor-safe voltages.

Example Schematic #2

[Click on the figure to get a large version]



(1) Contrary to various notes on the web, a close inspection of the Arduino firmware source code, followed by experimentation with an Uno board shows that the firmware does not automatically tie the Aref pin to AVCC by default on startup. Any Aref connections are made on the first A to D conversion. Setting the analogReference() command to EXTERNAL before any A to D conversions will theoretically avoid unpleasantness with Aref and AVCC. But firmware bugs happen, so some hardware protection is highly desirable.

(2) Arduino boards have a 100nf capacitor tied from the Aref pin to ground on the board. This capacitor will put a pole in the feedback loop of the op-amp, and while at a higher frequeny (388 hz) relative to the major pole in the op-amp loop response and thus possibly insignificant, could lead to feedback loop instability. Do check the phase margin of the feedback loop if you use this technique. You may have to compensate by adding a small capacitor across the 4.7k resistor (approx. 680nf), depending on your op-amp bandwidth.

(3) Arduino boards have very poor processor pin overvoltage or negative voltage protection. I recommend making sure the op-amp can't swing more than 5 Vdc positive or 0 Vdc negative. Using +5 vdc and ground to power the op-amp provides this protection. Otherwise, clamp the op-amp output with diodes. In any event, please test the functionality of your op-amp circuit before connecting it to the Aref pin. This avoids a crispy-critter processor from a wiring mistake...