Electronic – ATtiny85 power consumption double expected

atmelattinylow-power

I'm trying to get an ATTiny85 to run off a battery. I have it clocked from a 16.384 MHz crystal, with the divide-by-8 fuse set. Vcc is 3.3 volts. Figure 22-7 in the datasheet says that at idle ( set_sleep_mode(SLEEP_MODE_IDLE); sleep_mode(); ), it should draw around 300 µA. In actual fact, I see it drawing more like 850 µA. I can't figure out why the power consumption is double expected. I've turned off everything in PRR except for timer0, which I've configured to interrupt every 25 ms. So it should spend the vast majority of its time in the idle state, which is the best I can do given that I still want the timers to count.

The fuses are 0x7f, 0xdf, 0xff.

Here's the code it's running for this test:

#include <Arduino.h>
#include <EEPROM.h>
#include <avr/sleep.h>
#include <avr/power.h>

#define P0 0
#define P1 1
#define P_UNUSED 2

ISR(TIMER0_COMPA_vect) {
  // do nothing - just wake up
}

void setup() {
  power_adc_disable();
  power_usi_disable();
  power_timer1_disable();
  //PRR = _BV(PRADC) | _BV(PRTIM1) | _BV(PRUSI); // everything off but timer 0.
  TCCR0A = _BV(WGM01); // mode 2 - CTC
  TCCR0B = _BV(CS02) | _BV(CS00); // prescale = 1024
  // xtal freq = 16.384 MHz.
  // CPU freq = 16.384 MHz / 8 = 2.048 MHz
  // count freq = 2.048 MHz / 1024 = 2000 Hz
  OCR0A = 50; // 25 msec per irq
  TIMSK = _BV(OCIE0A); // OCR0A interrupt only.

  set_sleep_mode(SLEEP_MODE_IDLE);

  pinMode(P_UNUSED, INPUT_PULLUP);
  pinMode(P0, OUTPUT);
  pinMode(P1, OUTPUT);
  digitalWrite(P0, LOW);
  digitalWrite(P1, LOW);

  while(1) { sleep_mode(); }
}
void loop() {}

Best Answer

You say that according to Figure 22-7 in the datasheet it should only draw 300µA, but that graph shows the current draw for operation without clock division. A crystal oscillator running at 16MHz is bound to draw more current than one running at 2MHz, and the 3 stage divider will add a bit more. The question is - how much more?

The datasheet also suggests that idle current can be reduced by dividing the clock down, but again it doesn't say how much it will be reduced. Extrapolating the 3.3V line suggests that it would normally draw about 1.5mA at 16.4MHz, and 850µA is a significant reduction - but should it be less?

If you can't use a lower frequency crystal on the boards you have coming then there may be nothing you can do. However, while you have the circuit on a breadboard you could at least try a 2MHz crystal, to see if that really is the problem.

enter image description here