-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Problem
While reviewing an update to the AYAB shield, it appeared the original AYAB schematic connected the 5V pin from the Arduino (coming from USB), known as VCC
, to the Arduino's AREF
pin.
Looking at the schematics of previous and current versions of the shield, and the schematic of the EMSL Interface board, it seems this design has been copied in all existing versions of the AYAB hardware.
However, when driving the AREF
pin with an external voltage like this, both the Arduino documentation and the ATmega328P datasheet warn that the ADC should not be used without first being configured to disconnect the internal voltage reference from 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().
Because the AREF
pin is also an output pin that exposes the internal voltage reference when it is used, enabling the 1.1V internal reference while supplying 5V to the pin could damage the microcontroller.
But the AYAB firmware does not call analogReference
at any point, so it is in violation of the specification of the microcontroller and could in theory damage it.
How to fix this
This is clearly an oversight in the AYAB hardware design; however, since the existing hardware cannot be globally replaced, changing the hardware design now would not affect the existing AYAB installations. Instead, we can modify the AYAB firmware to call analogReference(EXTERNAL)
upon initialization. Testing on actual hardware is required however, in case calling analogReference(EXTERNAL)
has an unforeseen effect on the values read from the ADC.
Why this might not be a real problem
First off, as far as I can tell no issue has ever been reported with the AYAB hardware that could be attributed to this problem.
In practice, what the Arduino libraries do by default is to use the ADC in a mode that uses the AVCC
as a voltage reference (REFSn = 1
). The AVCC
pin is connected to VCC
on the Arduino board as recommended in the ATmega328P datasheet. So, according to the datasheet, this would mean the AVCC
pin is internally connected to the AREF
pin in that mode:

Looking at this diagram, it seems relatively harmless to short AVCC
and AREF
externally as long as the 1.1V reference is never selected, which the AYAB firmware never does?