0

M4 Low Power Sketch?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

M4 Low Power Sketch?

by rickpeterson on Thu Jan 03, 2019 11:23 pm

Does anyone have a sketch example of how to put the M4 (IstyBitsy M4 Express board) into a low power sleep mode and then wake up X seconds later using the watchdog timer?

rickpeterson
 
Posts: 16
Joined: Wed Dec 05, 2018 11:54 pm

Re: M4 Low Power Sketch?

by adafruit_support_mike on Fri Jan 04, 2019 6:11 am

I'm afraid not. Our SleepyDog library still hasn't been ported to the SAMD51.

adafruit_support_mike
 
Posts: 54732
Joined: Thu Feb 11, 2010 2:51 pm

Re: M4 Low Power Sketch?

by rickpeterson on Fri Jan 04, 2019 10:24 pm

Has anyone created any inline assembly code to invoke the sleep modes? It should only require 3-10 lines. Here is the data sheet: http://ww1.microchip.com/downloads/en/DeviceDoc/60001507C.pdf:

rickpeterson
 
Posts: 16
Joined: Wed Dec 05, 2018 11:54 pm

Re: M4 Low Power Sketch?

by adafruit_support_mike on Sun Jan 06, 2019 3:24 am

Not that we know about.. go ahead and give it a shot!

adafruit_support_mike
 
Posts: 54732
Joined: Thu Feb 11, 2010 2:51 pm

Re: M4 Low Power Sketch?

by westfw on Mon Jan 07, 2019 9:26 pm

Has anyone created any inline assembly code

It shouldn't require assembly, but sleep modes are notoriously fussy - sometimes requiring that peripherals be individually disabled so that they don't cause SLEEP mode to immediately exit, and similar.

Note that the sleepdog library has some code for the SAMD51, but it says "still not working" (with no open issues saying exactly how it's not working. Grr.) If you feel like fiddling, that might be a good starting point.
User avatar
westfw
 
Posts: 1473
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: M4 Low Power Sketch?

by Casey10110 on Wed Jan 09, 2019 9:25 pm

I'd like to see that too!

Casey

Casey10110
 
Posts: 43
Joined: Tue May 10, 2016 9:48 am

Re: M4 Low Power Sketch?

by westfw on Thu Jan 10, 2019 4:12 am

It looks like the lowest power modes would involve stopping peripheral clocks as well as the CPU clock (I don't think that the SAMD21 SleepyDog code does this, either.) Shutting down peripheral clocks is somewhat strong implied to require re-initialization of the peripheral after wakeup.

Would you be happy with a low-power mode that was only exited by resetting the chip? That seems a lot easier.
User avatar
westfw
 
Posts: 1473
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: M4 Low Power Sketch?

by Casey10110 on Thu Jan 10, 2019 12:56 pm

Personally, I was looking into the possibility of using the new "OFF" sleep mode of the SAMD51, and then waking it up after ... say ... 10 seconds using an external watchdog timer pulling the RST low, which apparently wakes it up even if it is "OFF". This would have the advantage that it could monitor for unexpected states as well:

MAX6374 (see https://www.maximintegrated.com/en/prod ... ml/tb_tab1)

Does that sound doable to you? It's just an idea ...

Casey

Casey10110
 
Posts: 43
Joined: Tue May 10, 2016 9:48 am

Re: M4 Low Power Sketch?

by mckenney on Thu Jan 10, 2019 8:09 pm

When I was experimenting with this a few weeks ago, I encountered an asymptote at around 1.75mA (@3V). This is after dealing with all the Usual Suspects: Slowing the clocks way down, muzzling the unused pins, turning off everything I could get away with, bypassing the regulator. I was working with Idle mode, but that's still 20x what I would expect, so I didn't try the more aggressive sleep modes.

Since it appeared asymptotic, I don't think it was something proportional, rather some fixed consumer. It might be something I don't know about inside the SAMD51, but my prime suspect is the DotStar chip, which as far as I know still runs even with the LEDs off.

mckenney
 
Posts: 10
Joined: Sun Sep 30, 2018 11:09 pm

Re: M4 Low Power Sketch?

by Casey10110 on Fri Jan 11, 2019 12:40 am

For sure. It would be interesting to see what the current drops to when in the "OFF" mode. From my experience, the Feather's aren't really made for optimizing power, but can be excellent starting points for projects and require only minor hardware modifications to achieve just that. Would be cool if they would put up some code for putting these boards into low power modes as they have for some of their other boards.

Casey10110
 
Posts: 43
Joined: Tue May 10, 2016 9:48 am

Re: M4 Low Power Sketch?

by mckenney on Fri Jan 11, 2019 12:09 pm

Based on my observations, I predict that if you were to reduce the MCU consumption to 0uA (down from 81uA) the consumption for the board overall would be around 1.7mA, since the proverbial elephant would still be in the room. All the same, that's down from the 22+mA I was measuring initially (with no WFI in sight).

In your design, I expect you could use the watchdog chip to cut power to the entire board.

mckenney
 
Posts: 10
Joined: Sun Sep 30, 2018 11:09 pm

Re: M4 Low Power Sketch?

by rickpeterson on Fri Jan 11, 2019 4:15 pm

Since Express boards have an SPI FLASH chip, rebooting the board would be acceptable; because we can write state information to FLASH and then read it back during setup() to resume operations. For my application (which is not battery powered), getting the board down to 2ma would be acceptable. I need to periodically free up the drain on my external 100ma power supply to run another current hungry circuit while the Arduino is sleeping/off.

rickpeterson
 
Posts: 16
Joined: Wed Dec 05, 2018 11:54 pm

Re: M4 Low Power Sketch?

by Casey10110 on Fri Jan 11, 2019 11:25 pm

I was thinking about exactly that scenario. You could write the flash data of whatever you are measuring and then transition to off. You'd need to make sure you are using a type of memory that can be overwritten often enough for your applications, as some memory would be burned through really quickly. I'm interested to see what the Cortex-M4 can offer in terms of low power options for wearable devices.

Casey10110
 
Posts: 43
Joined: Tue May 10, 2016 9:48 am

Re: M4 Low Power Sketch?

by Casey10110 on Mon Jan 14, 2019 10:22 pm

The SleepyDog library works for those who are trying to get this to work. You can modify the WatchdogSAMD.cpp file in the utility folder of the library.

This line:


#if defined(__SAMD51__)
PM->SLEEPCFG.bit.SLEEPMODE = 0x4; // Standby sleep mode
while(PM->SLEEPCFG.bit.SLEEPMODE != 0x4); // Wait for it to take
#else

Can be changed to

#if defined(__SAMD51__)
PM->SLEEPCFG.bit.SLEEPMODE = 0x7; // OFF sleep mode
while(PM->SLEEPCFG.bit.SLEEPMODE != 0x7); // Wait for it to take
#else

Casey10110
 
Posts: 43
Joined: Tue May 10, 2016 9:48 am

Re: M4 Low Power Sketch?

by rickpeterson on Wed Jan 16, 2019 2:31 am

Fantastic contribution. I am anxious to try out your suggestion of patching the .cpp file.

rickpeterson
 
Posts: 16
Joined: Wed Dec 05, 2018 11:54 pm

Please be positive and constructive with your questions and comments.


cron