Support for SLEEP_MODE_IDLE on Teensy 3

Status
Not open for further replies.
Hi,

I would like to implement support for low power sleep (similar to SLEEP_MODE_IDLE of the Arduino) on Teensy to make it part of the TaskScheduler library
(https://github.com/arkhipenko/TaskScheduler)
The Teensy "avr/sleep.h" does not seem to have have any code actually, and "avr/power.h" is simply empty.
I have looked at the Snooze library and tried to use the Timer initiated power sleep, but it seems to be working differently then Arduino.

TaskScheduler uses SLEEP_MODE_IDLE to place Arduino into low power mode for approximately 1 ms. It is awaken back by the timer interrupt responsible for updating millis() counter. This way I am achieving 1ms scheduling resolution. Arduino does not power down any peripherals while in SLEEP_MODE_IDLE, so USB and other communications continue to run normal.

Teensy seems to be behaving differently.

Code:
class definition:
#ifdef CORE_TEENSY
	SnoozeTimer *timer;
	SnoozeBlock *config;
#endif //CORE_TEENSY

constructor:
#ifdef CORE_TEENSY
	timer = new SnoozeTimer;
	config = new SnoozeBlock(*timer);
	timer->setTimer(1);
#endif //CORE_TEENSY

actual sleep:
#ifdef CORE_TEENSY
	Snooze.sleep(*config);
#endif //CORE_TEENSY

causes my Tennsy 3.5 periodically connect and disconnect, so I can't even monitor what is going on with the device.

Is there a sleep function that is close to AVR's SLEEP_MODE_IDLE mode?

Your help is greatly appreciated.
Thanks.
Anatoli
 
I've not used it, but the user DUFF created a snooze library that supports the Teensy LC/3.1/3.2/3.5/3.6 processors:

Thanks. I looked at it and tried to use it, but it works differently than I need (I suspect turning off peripherals while I don't need it to).
Anyway, I posted a question to the author of Snooze already in hope to get some better understanding of Teensy power saving modes.
 
Thank you. This is great. I think it works. It definitely produced different loop counts with and without the statement, Serial continued to work and USB didn't disconnect.
Looks like you found your answer? Just remember that the sleep timing is not going to be consistent because any interrupt (systick, usb, etc..) will wake the core. Also the power savings of just going into "idle" sleep are minimal but if you just want to pause the processor than just calling wifi will work given you haven't configured the LLWU for any other type of sleep modes.
 
Looks like you found your answer? Just remember that the sleep timing is not going to be consistent because any interrupt (systick, usb, etc..) will wake the core. Also the power savings of just going into "idle" sleep are minimal but if you just want to pause the processor than just calling wifi will work given you haven't configured the LLWU for any other type of sleep modes.

Yes, thank you. The sleep timing does not really matter in this case because the actual scheduling is going against values of millis(). The IDLE sleep is enabled for a short period of time if no tasks are scheduled to run in the next millisecond. As we are pretty sure it will be a lot of empty loops, I save a little bit of energy. For any other more involved sleep modes special care should be taken.

Very exciting! TaskScheduler works on Teensies. Woo Hoo! Will update the README soon with this great news.
 
@arkhipenko the great TaskScheduler refuses to work with Teensy 4.0. It worked great with Teensy 3.2 and Teensy 3.6 but the same code doesn't execute a task in Teensy 4.0.
Anyone got the great lib to run on a Teensy 4.0?
 
Status
Not open for further replies.
Back
Top