Electronic – arduino – ATTiny Default AREF

arduinoattinyvoltage-reference

I am trying to get the Adafruit Electret Microphone Amplifier to work with an ATTiny85 but am having some trouble with the reference voltage.
I am using a 5V circuit because I am also powering a strip of LEDs and I am trying to avoid making the circuit too complicated with a bunch of extra regulators.
Since the chip should use the supply voltage as reference by default I figured I would be fine in using 5V across the board. But I get basically no response out of the mic when doing this. However, if I hook up 5V to AREF and then call analogReference(EXTERNAL), everything works fine.

Any thoughts as to why this would be the case? This completely goes against my understanding (and experience) of the default AREF on the ATMega chips.

It would be nice to be able to use that AREF pin for something else ๐Ÿ™‚

Side Note: I am going to be powering this with batteries so maybe I just need it anyways? But again, I thought the default mode was to use VCC as the reference…

Best Answer

Perhaps you are changing the A/D reference mode somewhere else in your code? You can double check this by adding a call to analogReference(DEFAULT) just before your call to analogRead(). This should select Vcc as the input to the A/D Mux on the ATTINY85 just as you expected.

Here is the ADMUX register from the ATTINY85 datasheet... ATTINY85 ADMUX Register

Here is the relevant code excerpted from the Arduino library....

#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
65  #define DEFAULT 0
66  #define EXTERNAL 1
67  #define INTERNAL 2

uint8_t analog_reference = DEFAULT;

void analogReference(uint8_t mode)
{
        // can't actually set the register here because the default setting
        // will connect AVCC and the AREF pin, which would cause a short if
        // there's something connected to AREF.
        analog_reference = mode;
}

int analogRead(uint8_t pin)
{
        uint8_t low, high;

        if (pin >= 14) pin -= 14; // allow for channel or pin numbers

        // set the analog reference (high two bits of ADMUX) and select the
        // channel (low 4 bits).  this also sets ADLAR (left-adjust result)
        // to 0 (the default).
        ADMUX = (analog_reference << 6) | (pin & 0x07); 
...