1

I am trying to reduce current consumption on my project. Right now it is using ~1.28mAh, it should be possible to get it much lower (I am using AA batteries as the power source).

The ATtiny85 has its fuses set to run at 1MHZ, with BOD disabled.

I am using this board to mount the CPU. I desoldered the power LED and the regulator, feeding power directly from the batteries to the 5V input.

Nothing was connected to any other pins while measuring, just 5V and GND. The code was running in debug mode, so every 8 seconds it flashed a debug LED. I don't know for how much this could account.

Full code:

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

#define DEBUG (true)
#define INT_PIN (0)
#define OUT_PIN (2)
#define LED_PIN (1)

/***************************************************
 *  Name:        ISR(WDT_vect)
 *
 *  Returns:     Nothing.
 *
 *  Parameters:  None.
 *
 *  Description: Watchdog Interrupt Service. This
 *               is executed when watchdog timed out.
 *
 ***************************************************/
EMPTY_INTERRUPT(WDT_vect);
EMPTY_INTERRUPT(PCINT0_vect);

/***************************************************
 *  Name:        enterSleep
 *
 *  Returns:     Nothing.
 *
 *  Parameters:  None.
 *
 *  Description: Enters the arduino into sleep mode.
 *
 ***************************************************/
void enterSleep() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_cpu();
  sleep_disable(); /* First thing to do is disable sleep. */

  #if DEBUG
    digitalWrite(LED_PIN, HIGH);
    for (uint16_t dbg = 0; dbg < 65535; dbg++);
    digitalWrite(LED_PIN, LOW);
  #endif
}

/***************************************************
 *  Name:        setup
 *
 *  Returns:     Nothing.
 *
 *  Parameters:  None.
 *
 *  Description: Setup for the serial comms and the
 *                Watch dog timeout. 
 *
 ***************************************************/
void setup() {
  pinMode(INT_PIN,INPUT);
  pinMode(OUT_PIN,OUTPUT);
  pinMode(LED_PIN,OUTPUT);
  ADCSRA &= ~_BV(ADEN); // ADC off
  power_all_disable();
}

/***************************************************
 *  Name:        enterSleep
 *
 *  Returns:     Nothing.
 *
 *  Parameters:  None.
 *
 *  Description: Main application loop.
 *
 ***************************************************/
void loop() {
  digitalWrite(OUT_PIN, LOW);
  digitalWrite(LED_PIN, LOW);
  /*** Setup the WDT ***/
  wdt_reset();
  /* In order to change WDE or the prescaler, we need to
   * set WDCE (This will allow updates for 4 clock cycles).
   * WDTCR on ATTINY85 / WDTCSR on ATMEGA
   */
  WDTCR |= (1<<WDCE) | (1<<WDE);
  /* set new watchdog timeout prescaler value */
  WDTCR = 1<<WDP0 | 1<<WDP3; /* 8.0 seconds */
  /* Enable the WD interrupt (note no reset). */
  WDTCR |= _BV(WDIE);
  // sleep for 8 seconds x 43200 = 96 hours = 4 days
  for (uint16_t i = 0; i < 43200; i++)
    enterSleep();
  wdt_reset();
  wdt_disable();
  GIMSK |= _BV(PCIE); // Enable Pin Change Interrupts
  PCMSK |= _BV(PCINT0); // Use PB0 as interrupt pin
  enterSleep();

  #if DEBUG
    digitalWrite(LED_PIN, HIGH);
  #else
    digitalWrite(OUT_PIN, HIGH);
  #endif
  enterSleep();
  PCMSK &= ~_BV(PCINT0); // Turn off PB0 as interrupt pin
}
  • I forgot something important: when measuring I wasn't using batteries as the power source, but an FTDI serial USB cable like this link, routing 5V to a breadboard where I put my multimeter. Was I measuring the consumption of the FTDI adapter too? – j'ordos Jan 16 '17 at 13:06
  • A sleeping ATTINY uses only microamps, so something else is pulling your power. You might want to enable the pull-up on the INT_PIN - floating pins can waste some power when they drift between high and low voltages. You also want to do power measurements carefully with nothing attached to circuit (like you ftdi). Power can easily flow both into and out of any pin on the chip and mess up your measurements. – bigjosh Jan 16 '17 at 14:34
  • @bigjosh as far as I know floating pins doesn't matter in powerdown sleepmode. – Gerben Jan 16 '17 at 16:05
  • I'd remove the attiny from that board, and place it directly into a breadboard. Try and simplify thing, and disabling the watchdog timer for now. 1.28mAh; I assume that h at the end is just a typo. Are you sure your multimeter is accurate in this low range? – Gerben Jan 16 '17 at 16:09
  • Why is it waking every 8 seconds when (according to the comments) you expect the the loop() function's for() loop to renew sleeps for 4 days before continuing? – JRobert Jan 16 '17 at 16:13
1

Today I measured again without the development board. Just the CPU, same setup otherwise (original code, using the FTDI cable as power source) and I got a reading of about 6-8µA. I guess that answers it! Thanks everyone for your help!

  • Since you have answered your own question in a positive way, you should accept your own answer. :) – Nick Gammon Jul 18 '17 at 8:15
-3

Putting it to sleep is the best approach.

You can configure various sources to wake up the MCU.

  • I am already using sleep mode. I'm using the watchdog timer to sleep for a specified amount of time in 8 second intervals. After that it goes to sleep and waits for a pin interrupt to wake up and repeat the cycle. At least if my code works... – j'ordos Jan 16 '17 at 13:09

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.