# Low power mode when scheduler idle

**URL:** <https://forums.freertos.org/t/low-power-mode-when-scheduler-idle/353>\
**Category:** Kernel\
**Created:** [January 26, 2012, 7:45am UTC](https://forums.freertos.org/t/low-power-mode-when-scheduler-idle/353 "2012-01-26T07:45:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 26, 2012, 7:45am UTC](https://forums.freertos.org/t/low-power-mode-when-scheduler-idle/353/1 "2012-01-26T07:45:34Z")

</div>

**anonymous** wrote on [Thursday, January 26, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/0d50c3e8/#e50d):

I would like to be able to switch my dsPIC33F into a low power mode when there are no tasks running (or all are suspended or blocking). The idea is to use the core doze mode to reduce power to 1/4 normal operation when idle by underclocking the CPU (but peripherals and timers run on the main clock, so it still keeps time.)

The simplest way of implementing this, I thought, would be to look for a vGetNumRunningTasks function; but there doesn’t seem to be one. I’d need to access the internal RTOS data structures to get the task list, which is probably a bad idea.

Any ideas?

Thanks for a great RTOS!

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [January 26, 2012, 8:04am UTC](https://forums.freertos.org/t/low-power-mode-when-scheduler-idle/353/2 "2012-01-26T08:04:02Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, January 26, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/0d50c3e8/#13f3):

The normal way of doing this is to use the idle hook.&nbsp; Assuming your application tasks run at a priority above the idle priority, the idle task will only run when no application tasks can run.&nbsp; Set configUSE\_IDLE\_HOOK to 1 in FreeRTOSConfig.h, then define a function called vApplicationIdleHook(), and put your sleep code in that.

[http://www.freertos.org/a00016.html](http://www.freertos.org/a00016.html)

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 26, 2012, 8:07am UTC](https://forums.freertos.org/t/low-power-mode-when-scheduler-idle/353/3 "2012-01-26T08:07:42Z")

</div>

**anonymous** wrote on [Thursday, January 26, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/0d50c3e8/#c541):

Hi Richard

That looks useful - thanks. I would need to enter and exit low power mode several times a second though (at least); is there some function (aside from any of my tasks) that would run a callback when tasks are started so I can exit the low power mode I entered in the idle hook?

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [January 26, 2012, 4:51pm UTC](https://forums.freertos.org/t/low-power-mode-when-scheduler-idle/353/4 "2012-01-26T16:51:35Z")

</div>

**[richard\_damon](https://sourceforge.net/u/richard_damon/)** wrote on [Thursday, January 26, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/0d50c3e8/#91eb):

I tend to just execute an Idle instruction in the idle hook to stop the processor when there is nothing to be done.

If you want to actually a clock change for lower power, you could add that code before the idle, then define a handler for  
traceTASK\_SWITCH\_IN() that checks if you are in that low power mode, and are switching to a task besides the idle task, switches back into full speed mode.
