Go Down

Topic: Preserve battery with Sleep ? (Read 3880 times) previous topic - next topic

48X24X48X

#30
Nov 01, 2011, 04:33 am Last Edit: Nov 01, 2011, 05:47 am by 48X24X48X Reason: 1
I would suggest if you start from the Pro Mini/Fio alone without any external peripheral.
It will be very hard to pin point where the current consumption is going into when you have several possible contributors.
Then, once the main board is low in current, start adding the external peripheral one by one.
Eventually you'll get there. :)

You can disable the BOD on the fly but with strict timing and sequence.
You might want to check a simple library I wrote some time ago:
http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/

Nick Gammon

There's something wrong with that URL, I can't load it by clicking.

Anyway, working around that, the BOD disable doesn't seem as effective as setting the fuse. I still measure 61 uA using the test sketch compared to 6 uA with setting the fuse.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

48X24X48X


There's something wrong with that URL, I can't load it by clicking.

Anyway, working around that, the BOD disable doesn't seem as effective as setting the fuse. I still measure 61 uA using the test sketch compared to 6 uA with setting the fuse.


Fixed the link!

The software BOD disable works in my case. I always get a reduce of ~17 uA when disabling them through software. I also started using the hard coded way of disabling the fuse but I thought the BOD is an important feature to keep. So, I went with the software method and only disabling them when needed.

Yeast

I am actually using pro mini and arduino fio but the diagram I posted is from the example I find on IR sensor.
Sorry for the confusion.  :smiley-sweat:
I have already solder everything together so removing everything and adding them back one by one doesn't seem like a preferable choice.  :smiley-roll-sweat:

Yeast


You can disable the BOD on the fly but with strict timing and sequence.
You might want to check a simple library I wrote some time ago:
http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/


I check out for library by loading the current hardware setting with your "Wake External Interrupt" example and it is still 4mA.
So it is definitely something to do with the hardware setting !!!!

Nick Gammon


I have already solder everything together so removing everything and adding them back one by one doesn't seem like a preferable choice.  :smiley-roll-sweat:


You can make, as a test, a "bare bones" board, even on a breadboard. Also there are cheap circuit boards, for example this one for $US 3:

http://evilmadscience.com/productsmenu/tinykitlist/74-atmegaxx8

Then solder on a chip header (eg. the ZIF socket they have on the page), a couple of decoupling caps, a resonator, and then the wires leading to your circuit.

Then you are in a position to test the sketch/hardware combination. You can power it, for testing, from an external 5V supply. For example, I powered my test board by simply connecting to the 5V/Gnd pins on an Arduino Uno, which supplies me with regulated 5V.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

wayneft

I know this is an old thread but I can tell you where your extra 4 mA is coming from because I've spent the last few hours trying to figure out the exact same problem.  NewSoftSerial adds 4mA of extra current to all of your sleep mode settings.  I was following some of Nick's code to use as a baseline.  Try the simple sketch below with and without creating an instance of NSS and you'll see a 4mA difference. The numbers on the left are without NSS and on the right with NSS.  Now my question is can you delete an instance of NewSoftSerial after you've created one?

Code: [Select]
#include <avr/sleep.h>
#include <NewSoftSerial.h>

//NewSoftSerial ThisIsKillingME(8,9);


void setup ()
{
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);  //480uA  4.35mA
//  set_sleep_mode (SLEEP_MODE_STANDBY);  //636uA  4.5mA
//  set_sleep_mode (SLEEP_MODE_EXT_STANDBY);  //775uA  4.65mA
//  set_sleep_mode (SLEEP_MODE_PWR_SAVE);  //775uA  4.648mA
//  set_sleep_mode (SLEEP_MODE_ADC);  //967uA  4.84mA
//  set_sleep_mode (SLEEP_MODE_IDLE);  //1.16mA  5.03mA
  sleep_enable();
  // disable ADC
  ADCSRA = 0; 
  // turn off various modules
  PRR = 0xFF;
  // turn off brown-out enable in software
  MCUCR = _BV (BODS) | _BV (BODSE);  // turn on brown-out enable select
  MCUCR = _BV (BODS);        // this must be done within 4 clock cycles of above
  sleep_cpu ();              // sleep within 3 clock cycles of above
}  // end of setup

void loop () { }
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Nick Gammon

You could do new and delete rather than statically allocating it. But that may or may not return the power consumed. There would be an underlying reason (it has configured an interrupt to fire for example). So unless it has a destructor, and the destructor is designed to undo whatever the constructor does, you may not achieve much.

I'm sure it can be done, but you will need to figure out exactly what, in NewSoftSerial, is consuming the power.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

A quick browse indicates the constructor doesn't do much apart from configuring the input and output pins (although that might have a small effect, eg. the pull-ups).

But it does link in the pin change interrupts, possibly activating the pin change interrupts causes a higher power consumption. I'm guessing a bit here. Probably best to make a copy of NewSoftSerial, use that, and then comment out stuff until the current consumption drops.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

wayneft

Thanks Nick.  I had a different response but just found the problem so I deleted it. 

It looks like NSS is using (or not) Timer0 and that is what is consuming all the power.  If you look through the code there's actually a public function to enable Timer0 so if you send this:
Code: [Select]
ThisIsKillingME.enable_timer0(1);
it seems to knock out the 4mA  :) .  I'll have to test further to see if setting back to 0 after wake up causes any problems.
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Nick Gammon

I thought sleep mode "power down" stopped timer 0? There are some figures on page 404 of the datasheet that show the consumption of various modules. At 5V Timer 0 apparently consumes around 61 uA. However a side-effect of it running is it cancels sleep mode (because of the interrupt).

I would be starting to wonder if your code stays asleep. Try flashing an LED or something in loop() to see if you exit sleep mode when you don't think you do.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

wayneft

I did confirm it was staying asleep, I set it up to toggle a pin in a loop and it didn't toggle.  I also need to rescind the observation I made about calling that function.  I was making multiple changes in the sketches before finishing up at work and the last change I made before calling that function was create an instance using pins 0 and 1 instead of 8 and 9 just to see what would happen.  I think that in combination with the function dropped the power.  I'm going to try it again after dinner but if that's the case it may be related to the pin change interrupts.  Which kind of sucks because I wanted to use one to be able to wake up from a low battery alert.
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Coding Badly


I don't see where you are enabling the internal pullups on unused pins.

Nick Gammon

If pin change interrupts were enabled, which I didn't think the constructor did, then they would probably fire like crazy if there were floating voltages on the pins.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

Actually I can't reproduce your problem.

Running this exact code:

Code: [Select]
#include <avr/sleep.h>
#include <NewSoftSerial.h>

NewSoftSerial ThisIsKillingME(8,9);


void setup ()
{
  pinMode (9, OUTPUT);
  digitalWrite (9, HIGH);
  delay (1000);
  digitalWrite (9, LOW);
 
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);  //480uA  4.35mA
//  set_sleep_mode (SLEEP_MODE_STANDBY);  //636uA  4.5mA
//  set_sleep_mode (SLEEP_MODE_EXT_STANDBY);  //775uA  4.65mA
//  set_sleep_mode (SLEEP_MODE_PWR_SAVE);  //775uA  4.648mA
//  set_sleep_mode (SLEEP_MODE_ADC);  //967uA  4.84mA
//  set_sleep_mode (SLEEP_MODE_IDLE);  //1.16mA  5.03mA
  sleep_enable();
  // disable ADC
  ADCSRA = 0; 
  // turn off various modules
  PRR = 0xFF;
  // turn off brown-out enable in software
  MCUCR = _BV (BODS) | _BV (BODSE);  // turn on brown-out enable select
  MCUCR = _BV (BODS);        // this must be done within 4 clock cycles of above
  sleep_cpu ();              // sleep within 3 clock cycles of above
}  // end of setup

void loop () { }


I got a reading of 0.42 uA (420 nA). And that was with the NewSoftSerial object there.



I added the stuff to flash an LED because I could hardly believe my eyes. But yes, the LED comes on for one second, and then the current drops to that reading.

Oh, wait. Pin 9 is what you are using for NSS. Well anyway there is the proof.

But this is interesting. I commented out the 4 lines that flashed the LED. And now look what happens:



Not only is it now using 4.345 mA (a big jump!) but the LED lights up! Well that's where your power is going.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up