Author Topic: Is it possible to sleep the M0 SAMD MCU for less than one second?  (Read 2161 times)

Ryan

  • NewMember
  • *
  • Posts: 5
Is it possible to sleep the M0 SAMD MCU for less than one second?
« on: September 17, 2021, 12:40:38 AM »
I'm trying to see how to put the M0 into RX mode, then sleep the MCU for some period of milliseconds to save power while waiting to receive a transmission. Anyone know if this is possible, e.g. LowPower.idle(SLEEP_15MS, ADC_OFF, BOD_OFF);

It looks like the LowPower library only supports sleep with time-based wakeups for AVR boards, not SAMD boards. It also appears as though the RTCZero library only supports sleep periods of at least one second (i.e. without millisecond support).

ulli

  • Jr. Member
  • **
  • Posts: 87
Re: Is it possible to sleep the M0 SAMD MCU for less than one second?
« Reply #1 on: October 04, 2021, 12:55:49 PM »
Set the M0 to sleep forever (RTC with Alarm 0) and wake up by external interrupt which is wired to the rfm dio0 pin. ;) -> wake up by incomming radio message

Or use the watchdog

arf

  • NewMember
  • *
  • Posts: 20
Re: Is it possible to sleep the M0 SAMD MCU for less than one second?
« Reply #2 on: October 25, 2021, 10:52:25 PM »
That's neat, but what if no message comes and you want to shut the radio off sooner than waiting one second as the original poster asked?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Is it possible to sleep the M0 SAMD MCU for less than one second?
« Reply #3 on: October 26, 2021, 09:55:29 AM »
arf - why would you do that? Trying to manually implement some kind of partial listen mode?

Anyway, there is a sleep function in the RFM69 library. It's called listenModeSleep() and you can pass milliseconds, it has to be used together with endListenModeSleep(), you should take a look at the ListenModeSleep example. It was intended for AVR use mostly but I think it could be used for M0 as well, you will have to sleep the SAMD on your own after calling listenModeSleep() similar to how it's done in the example, here's a quick snippet from an AVR program (the 3 calls to sleep forever are because there are 3 interrupts generated after the sleep call):

Code: [Select]
void listenModeSleep(uint32_t millisInterval) {
  radio.listenModeSleep(millisInterval);
  LowPower.powerDown( SLEEP_FOREVER, ADC_OFF, BOD_OFF );
  LowPower.powerDown( SLEEP_FOREVER, ADC_OFF, BOD_OFF );
  LowPower.powerDown( SLEEP_FOREVER, ADC_OFF, BOD_OFF );
  radio.endListenModeSleep();
}

The only advantage of this method with SAMD is that it might allow you more granular sleep, although I imagine you could do it with SAMD timers as well, I just don't have a straight example to give you right now.
« Last Edit: October 26, 2021, 10:43:45 AM by Felix »

arf

  • NewMember
  • *
  • Posts: 20
Re: Is it possible to sleep the M0 SAMD MCU for less than one second?
« Reply #4 on: October 26, 2021, 07:58:58 PM »
I am trying to make some window blinds that close by themselves.  Very similar to Ryan's other question:

https://lowpowerlab.com/forum/low-power-techniques/low-power-listening-using-rfm69/

Basically, trying to check for a message really quick (few ms) then sleep for a second.  I don't want to go over a second because then the response would be kind of slow.  Ideally I could check once per quarter second or so since that would still be a low ratio of being On to being in Sleep.  I'll check out that listenModeSleep() function you mentioned!

I had another project where I didn't have any radio and just wanted to check a sensor every quarter second or so and sleep in between, but I should probably start another topic for that than hijack ryan's radio-centric question here.

Thank you