How to shut down ATMega1284p internal VREF at bootloader level?

I need to “shut down” the internal Vref of the ATMega1284p, because I have an external precision Vref. I’m looking for a valid method to shut it down as default BEFORE any other “activity”, because, according to my current options, it’s too easy to forget a simple line of code. The goal is to avoid this little mistake that results in increasing power consumption and heating of both vref and voltage regulator chips.

My options are:

  1. in sketch setup
  • analogReference(EXTERNAL);


  • ADMUX &= ~((1<<REFS1) | (1<<REFS0)); (does the same as above)
  1. or, in Wiring_analog.c, setting analog_reference to EXTERNAL.
  • uint8_t analog_reference = EXTERNAL;

All above solutions work perfectly, but I’m wondering if there’s another way to do it (e.g. in the bootloader, in fuses etc.). I spent a lot of time reading Atmel documentation and searching on the internet, but I haven’t found a way to do it.

I think I could exclude fuses setting because there’s no specific bit affecting internal voltage reference. I also think that through the bootloader I could implement something in order to reach the goal. Unfortunately this looks, at the moment, above my comprehension.

Why not just add it as the first line of setup() ?
Or you could add it to your local copy of main() code. Search your IDE for main.cpp or main.h.

What Crossroads' said +1

Isn't this much adue over nothing? I disagree that it is too easy to forget a line of code. Once it's there, it just doesn't magically go away, you have to purposely delete it. It simply does not warrant the additional trouble of a custom bootloader or some other equally time expensive method to "set and forget" about the reference.

Set it once in your Setup block and you're forever done with it. Move on. You've got far more important things to investigate and test in a low power app. Seriously, it's just tiny spec of noise in a very noisy environment.

CrossRoads: Why not just add it as the first line of setup() ? Or you could add it to your local copy of main() code. Search your IDE for main.cpp or main.h.

(Thank you, CrossRoads, I got so much inspiration from your works) (and thank you, avr_fred)

The problem starts when the controller is far from my... control. If a customer try to write his own sketch, and if he forget to turn off the internal reference, even though the board keeps working, the drawn current increases as well as the heat. I guess it's not so good for vreg/vref chips' health. Furthermore, the risk of thermal shutdown of the 1117-5 is high, with unpleasant consequences.

You could add a low Rds MOSFET that only lets the external reference connect when the MOSFET is enabled. With the MOSFET being turned off, I imagine the readings returned would off be a fair bit with Aref at 5V instead of 2.65V?

Yes I could, but not at this moment. The board is already made, certified and working on many environments. I just wished to avoid some weird calls like "Hey, I wrote my sketch, everything runs like a charm but the board shuts down on its own". But probably it's just me and my utopian need of building zero-worries solutions.

So, under this perspective, you are probably telling me that analogReference(EXTERNAL) in the setup it's like "Dude, LED does not blink" - "Have you set the pinMode to output?" - "Oh..." ;) And yes, it makes sense.

Thank you.

Why not put a resistor between the external reference and the VRef pin? That would at least limit the current that could flow between them, (ie, so they wouldn't fight as hard -> less chance for damage).

Ofc, if you want me to build a version of the bootloader that will set ADMUX as you specified, I'd be happy to do so for a nominal fee. I see no particular complications to doing so - though I don't really think it's the ideal approach.

And if they replace the '1284P with a new one and put a standard bootloader from here or here 'cause the users always know enough to be dangerous, and then they're right back they started, no Aref control. I