Electron DeepSleep Wakeup timer precision

I’m working on a prototype which needs to wake-up once every few minutes to sample sensors and go back to sleep. I aggregate a bunch of data and send it to the cloud later. Basically, I want to timestamp my readings if the wakeup source timer is has sufficient precision(based on the external RTC Xtal).

I have a few questions,

  1. What timer is used in the STM32 to wakeup from DeepSleep? Digging through the STM32 datasheet, I realize there is a IWDG and a RTC Alarm which can wake the chip up. Which is used in the Sleep() routine specified in the Particle OS?

  2. Is the IWDG clocked from the same 32.768KHz RTC crystal?

Wake from sleep uses the RTC alarm. However, you should not rely on the precision of the timer.

While the value passed in is in seconds, there is an indeterminate period of time in System.sleep while pending publishes are sent out and the modem is turned off that may take up to several seconds. This will be in addition to any sleep time specified.

If you need to take measurements at a very specific time the best option is to calculate the sleep time to leave some extra time, say 10 seconds, and wake up earlier and then sample based on the RTC value, not the time you wake. But the RTC has a resolution of 1 second, so you’ll never get more precise than that.

Interesting tid-bit.

Thanks for the recommendation, I’m open to round to the nearest second based on the RTC limitation. That said, due to my sensitivity on power I won’t prefer longer. I don’t usually have cellular connection but I think I can have a condition under which I wait the extra time.

That said, I think it might be easier if I could take over the RTC Alarm interrupt. As in,

  1. Wake-up for Deep Sleep
  2. Setup the RTC alarm interrupt to trigger at present time + x mins
  3. Do my sensor stuff
  4. Publish if necessary
  5. Goto Deep Sleep

In this case, I don’t setup the DeepSleep timer again. The RTC alarm should trigger and wake it up and it’s business as usual.

Do you foresee any problem with this? Anything special I need to do to access the RTC alarm?

Thanks again!

If you are not connecting to cellular on every sleep and wake, you should go to sleep and wake up very quickly, and you should stay accurate within a second.

Even in the case where you make a cellular connection to upload your data, since you want to wake up with cellular off you’ll be required to turn off cellular before going to sleep, so the actual sleep call should be fast there too.

So I think you’ll be fine.

1 Like