Author Topic: Measure current Moteino  (Read 7822 times)

TomWS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1837
Re: Measure current Moteino
« Reply #15 on: December 16, 2015, 09:36:10 AM »
Thanks for all the advice guys.

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
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. 

Tom

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5630
  • Country: us
    • LowPowerLab
Re: Measure current Moteino
« Reply #16 on: December 16, 2015, 10:01:33 AM »
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.

TomWS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1837
Re: Measure current Moteino
« Reply #17 on: December 16, 2015, 06:03:54 PM »
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.
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...

Tom

joelucid

  • Hero Member
  • *****
  • Posts: 869
Re: Measure current Moteino
« Reply #18 on: December 17, 2015, 04:13:56 AM »
Quote
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.

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.

syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
Re: Measure current Moteino
« Reply #19 on: December 17, 2015, 05:34:13 AM »
@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

@joelucid, I agree.  I have found that first initializing the flash before putting it to sleep does help a little in current savings.

syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
Re: Measure current Moteino
« Reply #20 on: December 17, 2015, 05:41:35 AM »
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

@obeard, when I want to drop down the clock speed I use the following code:

#include <avr/power.h>

CLKPR = 0x80;               // enable clock prescalar change
CLKPR = 0x4;                 // clock division = 16, 1 MHz

you can replace the 0x4 in the second line above to set the prescalar to whatever value you want

TomWS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1837
Re: Measure current Moteino
« Reply #21 on: December 17, 2015, 08:07:54 AM »
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.
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. 

And, if you know you're doing this, selecting a Divisor specific delay factor shouldn't be an issue (as long as you know WHERE the adjustments need to be made.)

Good suggestion!  Of course, the startup with CKDIV8 is essential for this to work reliably.

Tom

syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
Re: Measure current Moteino
« Reply #22 on: December 17, 2015, 08:11:33 AM »
@TomWS, you make a good point because the clock speed is used for timing with millis() and if you change the clock speed you need to adjust any appropriate timing routines.

I don't have any hard numbers but I know I've measured a drop in current usage as I go down in speed.  Particularly for motes like the mailbox, who needs a super-fast processor for one packet?

TomWS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1837
Re: Measure current Moteino
« Reply #23 on: December 17, 2015, 08:19:31 AM »
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
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

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.

Tom

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5630
  • Country: us
    • LowPowerLab
Re: Measure current Moteino
« Reply #24 on: December 17, 2015, 09:55:31 AM »
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.

TomWS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1837
Re: Measure current Moteino
« Reply #25 on: December 17, 2015, 11:54:41 AM »
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?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5630
  • Country: us
    • LowPowerLab
Re: Measure current Moteino
« Reply #26 on: December 17, 2015, 12:58:23 PM »
FYI this programmer cannot program an atmega1284p (MoteinoMEGA) or anything that has more than 64k flash.
Why not?
I read into the guide a little and they specify that it can't program anything above 64k.

TomWS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1837
Re: Measure current Moteino
« Reply #27 on: December 17, 2015, 06:41:59 PM »
FYI this programmer cannot program an atmega1284p (MoteinoMEGA) or anything that has more than 64k flash.
Why not?
I read into the guide a little and they specify that it can't program anything above 64k.
Well I don't understand why a serial programmer would have an addressing limitation unless it was written by a bone-head programmer ((or short sighted) or both)  9 years ago when I was a little kid  ::)

In any case...
Sounds to me like a software issue/challenge!

Tom
« Last Edit: December 17, 2015, 06:55:03 PM by TomWS »

WhiteHare

  • Hero Member
  • *****
  • Posts: 1297
  • Country: us
Re: Measure current Moteino
« Reply #28 on: December 17, 2015, 07:36:59 PM »
Quote
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.

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.  I guess you could sample the voltage from time to time and if the voltage is running low at the current frequency, force a reboot and then do as you suggest above.  Or maybe there's a more elegant way to transition from one frequency to another?

Somewhat related: I get the impression the bootloader is  hardcoded to run at a particular clock speed (mostly 16mhz or 8mhz on this forum).  Is that true?  If so, maybe it should be harcoded to run at 4mhz (or perhaps even less) if you want to maintain the option to do wireless programming all the way down to rock bottom 1.8v?

Anyhow, sorry for my ignorance, or if this has already been covered in depth somewhere else, but I'm just trying to visualize the final target so I can better steer my development toward it.

joelucid

  • Hero Member
  • *****
  • Posts: 869
Re: Measure current Moteino
« Reply #29 on: December 18, 2015, 01:18:46 AM »
Quote
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.

Not really. Voltage dives when the load is greatest, and that's during rx/tx. During rx/rx the power consumption of the 328p can be pretty much neglected. So coin cell optimization is primarily about deciding if and when to use the radio and to introduce recovery periods before using it when vcc comes down. Obviously you also can't just sit in a busy loop forever but that's a secondary problem.

Btw the clock prescaler can be selected at runtime no problem. No reboot necessary. Check out the data sheet.

I do have my fuses set so I boot at 1mhz. My boot loader the pauses until voltage recovers. But that's for the case where something has gone wrong and the BOD caused a reset because battery voltage declined too much. Eg a never ending busy loop. Then the boot loader changes to 8mhz and does a careful dance of using the radio, sleeping until voltage comes back up etc until an updated version is completely installed.