#include <LowPower.h>
#include <RH_RF69.h>
#include <SPI.h>
RH_RF69 radio;
void setup() {
// put your setup code here, to run once:
}
void loop()
{
// ATmega328P, ATmega168
radio.sleep();
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}
HeyLet's see...
I tested the current and I have some problems with what other people have said about power consumption.
Right now I have everything powered off and the Moteino measures 8 mA. whereas some people have said they manage to get 3 uA.
What am I doing wrong?Code: [Select]#include <LowPower.h>
#include <RH_RF69.h>
#include <SPI.h>
RH_RF69 radio;
void setup() {
// put your setup code here, to run once:
}
void loop()
{
// ATmega328P, ATmega168
radio.sleep();
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}
Tom,With that kind of combination, assuming that you're using the VR and running at 16MHz, I'd expect the current to be in the mid 20s (uA that is), maybe 30s (it's been so long since I ran a 328P at 16MHz I don't remember the current consumption).
He is using the RFM69 drivers from RadioHead. I haven't compared their sleep() function to the LowPower sleep() function so I can't say how comparable they are.
I can say that just today my partner and I connected up a Moteino and initialized and put to sleep both the radio and the flash. With a "SLEEP_FOREVER" parameter and a reed switch to wake up the Moteino, we were able to get the current down to 180 uA without really trying any of the fancier options. I wouldn't swear to it but it seemed from our limited testing that initializing and then sleeping both the radio and the flash chip seemed to work the best.
With that kind of combination, assuming that you're using the VR and running at 16MHz, I'd expect the current to be in the mid 20s (uA that is), maybe 30s (it's been so long since I ran a 328P at 16MHz I don't remember the current consumption).
Within that framework, am I right that the only reason for running at 8mhz (or 4mhz) is to be able to run reliably without a voltage regulator down to the lower voltages?
@obeard, I think you need to initialize the flash before you can put it to sleep. That could be the remaining problem. I use LowPower.powerDown, so I can't comment on the specific measures you took in your loop();I agree with Joe about initializing the flash before doing flash.sleep(). Also, try LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF) and see if that gives you different results.
Joe
Thanks for all the advice guys.Did the flash chip ID match that coded in the SPIflash library? If not, it won't initialize properly. I've been using a flash chip from Adesto AT25XE041B that has pretty good ultra-low power down current (200nA) but you'll have to make changes to SPIFlash library to use it.
I have solved the issue now and am consuming around 2.3uA, as expected.
The issue I found was that the flash was not sleeping properly. Even when I initialize and then sleep the flash I was still getting an additional ~28uA current draw for some unknown reason. When I removed the flash chip the consumption was at the level I expected it to be.
Do any of you use the flash chip, or is it something to avoid for low power? I think I must not have been setting it up correctly, but I based my code on the examples which I assume could sleep the flash memory.
I've also found that when I use LowPower.powerDown the BOD isn't turned off (get around 19uA more current drawn) than when I do it at a lower level, as in the attachment I provided. Very strange, but I do seem to have found a way around these problems now!
Thanks again for all your help
I've been using a flash chip from Adesto AT25XE041B that has pretty good ultra-low power down current (200nA) but you'll have to make changes to SPIFlash library to use it.Tom, nice power down current on that chip, I noticed it has the extra ultra power down mode, which gives the .2uA.
Sorry, I should have added that I'm not using this chip on a Moteino project. I'm using it on another project that has a very aggressive power budget and requires flash. There are others that claim to be lower but, as you say, not stocked...I've been using a flash chip from Adesto AT25XE041B that has pretty good ultra-low power down current (200nA) but you'll have to make changes to SPIFlash library to use it.Tom, nice power down current on that chip, I noticed it has the extra ultra power down mode, which gives the .2uA.
Unfortunately it's low count or not stocked at the major distros, also more pricey.
When I initially did my testing between different chips, the windbond came out as a clear winner in terms of speed of various operations also.
The windbond chip is abundant and still pretty good at 1uA in power down. I have yet to find a better alternative that is really worth to switch over to.
For those of us relying on listen-mode to wake up the atmega328p, it occurs to me that if I were using the Moteino's regulator (as in the example under discussion), I'd be better off running at 16mhz instead of 8mhz.
@obeard, I think you need to initialize the flash before you can put it to sleep. That could be the remaining problem. I use LowPower.powerDown, so I can't comment on the specific measures you took in your loop();
Joe
Tom,
You've said here that you're running the Moteino at a lower speed than 16 MHz. Have you done this by changing the fuses on the 328P, or in software (such as some kind of clock prescalar)? I'm trying to implement this but I don't want to lock up my Moteino by messing with the fuses if I don't have to! Any advice you can give would be really helpful.
Cheers
You know it strikes me that if you have a Moteino with regulator removed, and thus the external 16mhz clock it might be best to keep using it but program the CKDIV8 fuse to start up at 2mhz. You can then measure VCC on startup to select the lowest clock prescaler compatible with your current battery conditions and thus optimize performance.I like this, especially if you have a Moteino with the 16MHz crystal already attached. Many of my motes run on 2 Lithium AA/AAA with the voltage nominally 3.4 V. Having the option to tic up to 16MHz or down to 1 is very useful.
Drawback is some of the Arduino library functions (e.g. delay()) won't work correctly since they're hard coded for a given CPU speed.
Tom,Sorry I missed this earlier... Yes, I've changed the fuses to operate with internal 8MHz RC oscillator but will probably change future designs (at least those with 16MHz crystal - my own designs don't use a crystal) based on the suggestion Joe made: https://lowpowerlab.com/forum/index.php/topic,1431.msg10360.html#msg10360
You've said here that you're running the Moteino at a lower speed than 16 MHz. Have you done this by changing the fuses on the 328P, or in software (such as some kind of clock prescalar)? I'm trying to implement this but I don't want to lock up my Moteino by messing with the fuses if I don't have to! Any advice you can give would be really helpful.
Cheers
I use a Pocket AVR Programmer (https://www.sparkfun.com/products/9825) to program fuses and haven't trashed a processor yet. It's fairly easy to program the fuses (Sparkfun's tutorial is useful). If you use this on a Moteino, be sure to put a 10K pullup resistor on D10.FYI this programmer cannot program an atmega1284p (MoteinoMEGA) or anything that has more than 64k flash.
Why not?I use a Pocket AVR Programmer (https://www.sparkfun.com/products/9825) to program fuses and haven't trashed a processor yet. It's fairly easy to program the fuses (Sparkfun's tutorial is useful). If you use this on a Moteino, be sure to put a 10K pullup resistor on D10.FYI this programmer cannot program an atmega1284p (MoteinoMEGA) or anything that has more than 64k flash.
I read into the guide (https://learn.sparkfun.com/tutorials/pocket-avr-programmer-hookup-guide) a little and they specify that it can't program anything above 64k.FYI this programmer cannot program an atmega1284p (MoteinoMEGA) or anything that has more than 64k flash.Why not?
Well I don't understand why a serial programmer would have an addressing limitation unless it was writtenI read into the guide (https://learn.sparkfun.com/tutorials/pocket-avr-programmer-hookup-guide) a little and they specify that it can't program anything above 64k.FYI this programmer cannot program an atmega1284p (MoteinoMEGA) or anything that has more than 64k flash.Why not?
QuoteFor those of us relying on listen-mode to wake up the atmega328p, it occurs to me that if I were using the Moteino's regulator (as in the example under discussion), I'd be better off running at 16mhz instead of 8mhz.
You know it strikes me that if you have a Moteino with regulator removed, and thus the external 16mhz clock it might be best to keep using it but program the CKDIV8 fuse to start up at 2mhz. You can then measure VCC on startup to select the lowest clock prescaler compatible with your current battery conditions and thus optimize performance.
Drawback is some of the Arduino library functions (e.g. delay()) won't work correctly since they're hard coded for a given CPU speed.
The ability to change frequency "on-the-fly" also seems like it may be necessary if you want the option of utilizing every bit of available energy all the way down to 1.8v, especially in your coincell scenario where the voltage might nosedive while in use and not recover until later.
Has anybody thought about how a moteino could measure it's own power consumption?