5
\$\begingroup\$

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...

\$\endgroup\$
8
  • \$\begingroup\$ You mention three different platforms: ATtiny85, ATmega and Arduino. They are closely related, but which one are you using? Please include a link to the appropriate datasheet and the appropriate parts of the code. \$\endgroup\$
    – jippie
    Commented Mar 8, 2013 at 19:31
  • \$\begingroup\$ If you suspect you're assumption about default reference voltage is wrong, why not explicitly force it in your code, it only takes couple of bytes. \$\endgroup\$
    – jippie
    Commented Mar 8, 2013 at 19:32
  • \$\begingroup\$ I am using an ATTiny85 but on the Arduino code platform. I know it only takes up a couple of bytes in code but it takes up a whole I/O pin that I would rather be able to use... \$\endgroup\$
    – Adam Haile
    Commented Mar 8, 2013 at 20:11
  • \$\begingroup\$ You can force it to the (assumed) default Vcc in a few bytes and without sacrificing the pin. \$\endgroup\$
    – jippie
    Commented Mar 8, 2013 at 20:12
  • \$\begingroup\$ Ok... could you tell me how to do that? All I know is to call analogReference() and none of it's options seem to do what you are suggesting. \$\endgroup\$
    – Adam Haile
    Commented Mar 8, 2013 at 20:20

1 Answer 1

2
\$\begingroup\$

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); 
...
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.