Attiny841 draws too much current during sleep mode

Go To Last Post
35 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I've got the next problem with my attiny841 project. I want to use sleep mode to save battery capacity. In my test setup I've got nothing connected to the attiny841 but the TTL adapter for uart output. I'm using ATTinyCore with Arduino-Makefile for ease of use, but I'm not using much of the arduino stuff though.

 

The test code does nothing fancy. It sets up the sleep mode, waits a little while so I can measure current consumption during normal operation, then goes to sleep mode (10x8s). The measured current consumption is 8mA during operation and 1.1mA during sleep mode (power down mode). I'm pretty sure this is way too much.

 

Here's my code (reduced to the absolute minimum, I removed everything but the sleep mode stuff):

 


#include <avr/io.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
#include <util/delay.h>

#define LED           2 //LED_BUILTIN, PORTB2
#define DELAY         5000
#define WDTREPEATS    10

void sleep_setup() {
  // define sleep mode
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  // disable analog comparator 0 and 1
  ACSR0A |= _BV(ACD0);
  ACSR1A |= _BV(ACD1);

  // unlock Watchdog configuration register
  CCP = 0xD8;

  // enable the WD interrupt, set watchdog timeout prescaler value (interrupt period)
  WDTCSR = _BV(WDIE) | (_BV(WDP0) | _BV(WDP3)); // wake up after 8s

  // change clock prescaler to 8
  CLKPR = (_BV(CLKPS0) | _BV(CLKPS1));
}

void sleep_enter() {
  // disable ADC
  ADCSRA &= ~(1<<ADEN);

  // wait a little for the last serial output (if any) to flush
  delay(10);

  // disable SPI
  SPCR   &= ~_BV(SPE);

  // set all bits in power reduction register to one (shutdown everything)
  PRR = 0xFF;

  // actually go to sleep
  // wake up after WDT timeout
  sleep_mode();

  // re-enable all gizmos
  PRR = 0x00;

  // wait a little
  delay(10);

  // re-enable SPI
  SPCR = (1<<SPE);
}

void setup() {
  DDRB  |=  (1 << LED);
  sleep_setup();
  Serial.begin(115200);
  Serial.println("init");
  delay(4000);
}

void loop() {
  uint8_t i;

  // light on, wait for measurement, light off
  PORTB &= ~(1 << LED);
  Serial.println("-- ACTIVE");
  delay(10000);
  PORTB |=  (1 << LED);

  // do some sleep cycles
  for(i=0; i<WDTREPEATS; i++) {
    Serial.print("----- ENTER SLEEP: ");
    Serial.println(i);
    sleep_enter();
    Serial.println("----- LEAVE SLEEP");
  }
}

ISR(WDT_vect){
  // nothing to do
}

Does anyone have an idea what might be wrong?

 

Thanks in advance,

Tom

This topic has a solution.
Last Edited: Fri. Mar 13, 2020 - 06:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tomvr wrote:
Does anyone have an idea what might be wrong?

Possibly the way you are measuring it, can you post a clear picture of your setup.

Also the programmer will change your readings, remove it while measuring.

Arduino does stuff in the background (millis) with the timer, that could also interfere.

Can you post a schematic of your setup?

 

Jim

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

If you want something you've never had...

...you must be willing to do something you've never done!

Lets go Brandon!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can also  get sleep current through IO pins. What do you have connected? Any LEDs on while sleeping?

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you have any potential divider across the supply - eg, for monitoring battery level ?

 

 

Don't forget leakage of capacitors. Shouldn't be a worry around the milliamp range, but can get significant when you're into microamps ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, I have disconnected everything. There's only Vcc and GND from batteries. The LED is off during sleep (see code above).

 

Schematic: https://github.com/watterott/Wattuino/blob/master/hardware/Wattuino-Nanite841_v11.pdf

 

Edit: fixed schematic link.

Attachment(s): 

Last Edited: Thu. Mar 12, 2020 - 02:52 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

That 1k5 and Zener will draw some current.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What voltage are you getting from the batteries?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
What voltage are you getting from the batteries?

 

Currently 5.08V

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use a 2 cell battery and see if that helps as a test, Brian found your issue.

 

Jim

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

If you want something you've never had...

...you must be willing to do something you've never done!

Lets go Brandon!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Tomvr wrote:

Currently 5.08V

 

So the voltage across the 1k5 is (5.08 - 3.6) = 1.5V and the current through it is 1.5V/1k5 = 1mA. How does that compare with your excess current?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, since I don't have a battery pack available I just connected the Attiny board to the lab supply with 3.3V. It now draws 435uA in sleep mode. So if I understood it right, I need to get rid of the whole board and use a 841 chip directly w/o this diode+1k5 circuit?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tomvr wrote:
I need to get rid of the whole board and use a 841 chip directly w/o this diode+1k5 circuit?

You could just remove the diode?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
You could just remove the diode?

Or use a two cell AA battery pack!

 

Jim

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

If you want something you've never had...

...you must be willing to do something you've never done!

Lets go Brandon!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
use a two cell AA battery

which would probably further reduce the current ...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As I already said, I don't have a AA battery pack available here, I'll order some online but this will take time. Meanwhile I tried it with a 3V CR2032 cell, the voltage is the same as 2xAA. Still drawing 434 uA. And I can't remove the diode, this is a board which I've ordered as it is, the schematic is not mine but from the vendor.

 

Tom

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you cannot remove the diode or the resistor, then you are stuck with that current drain. Seems like a design without much thought for battery operation.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Tomvr wrote:
I don't have a AA battery pack available here

So what's this, then:

 

 I can't remove the diode, this is a board which I've ordered as it is

So? You've got the board; you can take the diode off it - surely?

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:

Seems like a design without much thought for battery operation.

 

Yes, that's right.

 

awneil wrote:

So what's this, then

 

That's a 4xAAA (triple not double A) pack which I need for other things as well. And what's the point of modifying this battery pack when I have a lab power supply? The board draws too much current whether I run it with 2xAA's or 1xCR2032 or the supply tuned to 3v.

 

awneil wrote:

So? You've got the board; you can take the diode off it - surely?

 

Just to make this clear: I have this board for prototyping and doing experiments (and I think that's the intended purpose it's being designed for). I've already learned from you guys here that I can't use it in my production device. I am absolutely happy with this.

 

Tom

Last Edited: Thu. Mar 12, 2020 - 08:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AA = 2500mA/hr

435uA draw....  lets see, that comes out to ~5747 hours, or 239 days, appx 7 months or so.  

How long are you wanting your device to last on one set of batteries?

 

Jim

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

If you want something you've never had...

...you must be willing to do something you've never done!

Lets go Brandon!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

AA = 2500mA/hr

435uA draw....  lets see, that comes out to ~5747 hours, or 239 days, appx 7 months or so.

 

I know (now), so I will use AA's, but that was not the question. I've just wondered why the actual Nanite draws more current than I expected.

 

ki0bk wrote:

How long are you wanting your device to last on one set of batteries?

 

As long as possible of course. Save the planet, you know :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Tomvr wrote:
Ok, since I don't have a battery pack available...

So just remove two cells from your 4 pack and jumper across the two empty slots.  Voila, two cell pack!

Letting the smoke out since 1978

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

digitalDan wrote:

So just remove two cells from your 4 pack and jumper across the two empty slots.  Voila, two cell pack!

 

Yes - a two cell pack of AAA's with 2.4V which is not even enough voltage to power up the board. Why are you all suggesting this?

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

In case anyone doesn't know... You can buy dummy batteries designed to short out the location where a regular cell should go. Useful to turn a 4-cell holder into a 3-cell one.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tomvr wrote:
what's the point of modifying this battery

No need to modify anything - just take a "tap" from 2 of the cells.

 

I have a lab power supply?

It seemed you were making an issue of the fact you didn't have a 2-cell pack, and that using the lab supply was some sort of an inconvenience.

 

Of course it makes no difference to the current draw!

 

Sorry for the misunderstanding.

 

 I have this board for prototyping and doing experiments

So, as an experiment, remove the diode - and confirm if that does give the required result!

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tomvr wrote:
a two cell pack of AAA's with 2.4V which is not even enough voltage to power up the board. Why are you all suggesting this?

It's not entirely clear that you're using NiCd or NiMH batteries !

 

Espectially as you said that 4 of them were giving  5.08V

 

Obviously, people are assuming primary cells to give 3V !

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tomvr wrote:
2.4V which is not even enough voltage to power up the board.

Eh ?

 

An ATtiny85 runs down to 1.8V !

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
2500mA/hr

Not mA/h - that'd be milliamps per hour.

 

You mean mAh - product of current & time = energy (at a given voltage).

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

awneil wrote:
You mean mAh - product of current & time = energy (at a given voltage).

Yes, you are correct, I must not have had enough diet coke yet when I wrote that!  Thanks for the correction.

 

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

If you want something you've never had...

...you must be willing to do something you've never done!

Lets go Brandon!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

awneil wrote:

An ATtiny85 runs down to 1.8V !

 

Yeah, but the board doesn't work below 2.8, I measured it.

 

awneil wrote:

So, as an experiment, remove the diode - and confirm if that does give the required result!

 

Ok, so I tried to locate D2 and managed to remove it without destroying anything else, and repeat the measurement. Here's the result:

 

 

Tata! 19.4uA - very nice :)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Jolly good - now see Tip #5 (in my signature)

 

I think a key lesson from all this is that achieving low-power is not just about software - it requires very careful attention to the hardware details, too!

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Indeed. I am very very grateful for the help here, really amazing. I'll also notify the vendor about this, maybe they want to modify the design.

 

Many Thanks!

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At the least, suggest that they make the board with an easy scratch-away disconnect. Both Adafruit and Sparkfun seem to do that routinely.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tomvr wrote:
maybe they want to modify the design.

Looks like it is designed for USB - so the diode is probably required for that.

 

When selecting hardware, it is your job to ensure that it is suitable for your intended application !

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Looks like it is designed for USB - so the diode is probably required for that.

 

Of course, according to the datasheet it's there to protect the USB D- and D+ data lines from transients. 

 

awneil wrote:

When selecting hardware, it is your job to ensure that it is suitable for your intended application !

 

I know, and this thread is part of the process.

Last Edited: Sat. Mar 14, 2020 - 04:43 PM