0
\$\begingroup\$

I'm measuring my standalone Attinty13a (internal 128kHz) current consumption with li-ion accumulator (3.7v, 220mAh). Here is my schema Schema

and code:

#include <avr/interrupt.h>
#include <avr/sleep.h>

ISR(WDT_vect) {
   digitalWrite(4,HIGH);
   delay(1000);
   digitalWrite(4,LOW);
   delay(1000);
}

int main(void) {
    DDRB = 1<<DDB4;
    WDTCR |= (1<<WDP3);
    WDTCR |= (1<<WDTIE);
    sei();  
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    for (;;) {
      sleep_mode();   
   }
}

Everything works fine: when it sleeps ammeter shows 5uA, and when digital pin 4 comes "on" ammeter shows more than 40mA. Nothing is connected to the chip, all pins are empty outside. I wonder could i reduce "pin on" state to 1uA?

Update:

I succeed with current reduction by setting all ports as outputs by using this code.

#include <avr/interrupt.h>
#include <avr/sleep.h>

ISR(WDT_vect) {
    PORTB ^= 1<<PB4;
    PORTB ^= 0<<PB4;
}

int main(void) {
    for (byte i = 0; i <= 20; i++)
    {
        pinMode (i, OUTPUT);    // changed as per below
        digitalWrite (i, LOW);  //     ditto
    }
    WDTCR |= (1<<WDP3);
    WDTCR |= (1<<WDTIE);
    sei();  
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    for (;;) {
        sleep_mode();   
    }
}

I do not quite sure how everything works now, but I added a LED with 1M ohm to pin 4, and 150 ohm resistance to Reset pin <-> Vcc, and my ammeter on scheme now shows 5uA in sleep state, and ≈7uA when pin turns on. ps:

https://www.gammon.com.au/power not all function of this tutorial works with Attiny13a, probably because its for Atmega328

http://brownsofa.org/blog/2011/01/10/the-compleat-attiny13-led-flasher-part-3-low-power-mode/ i used this tutorial to make my Attiny use power down mode.

\$\endgroup\$
  • \$\begingroup\$ Do those empty pins default to "input"? You really shouldn't let input pins float, if you expect low current . \$\endgroup\$ – glen_geek Sep 14 at 21:21
  • 2
    \$\begingroup\$ PB4 is pin 3, immediately adjacent to GND. Are you sure it is not shorted to GND? \$\endgroup\$ – Spehro Pefhany Sep 14 at 21:21
  • 6
    \$\begingroup\$ 40 mA is really a lot even for fully active MCU (note that high/low pin state is not important for power, but busy-loop wait in the ISR likely is). Possible reason for extra consumption could be floating inputs. I am not sure if likely, but it is definitively good idea to either ground all input pins or set them to output. Adding capacitor over power pins is good idea too (minimizing chance your ammeter is showing something not real if nothing else). Also, tell us what the MCU configuration is (clock source and fuse bits). \$\endgroup\$ – Martin Sep 14 at 21:23
  • 3
    \$\begingroup\$ Second what Martin said on the input pins -- CMOS logic inputs that are left open cause high current consumption -- although 40mA for five inputs is startlingly high. \$\endgroup\$ – TimWescott Sep 14 at 21:25
  • 2
    \$\begingroup\$ What else are you not telling here? It should not consume 40mA by itself to begin with. Do you have bypass caps? Try setting pins as outputs or at least inputs with pull-up in order not to consume extra power due to floating pins. \$\endgroup\$ – Justme Sep 14 at 21:26
1
\$\begingroup\$

Typical consumption of the ATtiny13A in the Power-Down mode with WDG timer enabled is between 4 and 5 uA according to the datasheet (see page 131), namely: ATtiny13A power consumption

Your measured value of 5 uA matches pretty well. Additional 2 uA with pin high are quite expected current for LED and 1 MOhm resistor to the ground.

So with the changes you made measured current is what would be expected (note below: the second line, xor with zero, in your ISR has no effect on pin state or anything).


If you want to achieve even lower current consumption with this particular MCU, there is not much more options.

Disabling the WDG timer should leave you with 0.3 uA typical in the power off mode, but then only available wake-up source are external pin change interrupts (see page 30 in the datasheet), but no time-based wakeup. Probably only reasonable option remaining if such low consumption is really necessary would be adding an external low-power RTC circuit with alarm function and routing its alarm signal to AVR pin.

As an example, M41T6x ICs by ST should be able to do timekeeping at less than 0.5 uA. There are for sure other RTC ICs with similar performance. So in theory this is a possibility to reduce current under 1 uA and to have time-based wake-up. If it is a practical solution in your situation is another question.

Note that 1 uA will (neglecting any self-discharge) discharge your accumulator in about 25 years, so 5 uA is still good for 5 years theoretically. So you should carefully check if the MCU power-down current is critical part of your power budget at all.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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