Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
5 years, 1 month ago.
How to use sleep and/or low energy solutions
Here is a snip of some code I have been successfully using before all the changes on Mbed, its not complete but enough to explain the issue.
simple sleep example
LowPowerTicker wakeup; void callback(void) { wake = 1; } int main() { while(1){ advance_clock(); while(second==lastsecond){ gettime(); } lastsecond=second; segmentDisplay.Number(displaydate); segmentDisplay.Write(displaytime); wakeup.attach(callback,0.90f); wake = 0; while(!wake) sleep(); } }
If I use early Mbed (version 2, revision 172) libraries it works exactly as I want it to.
however updating to the latest Mbed(2) the low power simply isn't, its normal running power. Okay, so try Mbed-os and exactly the same result.
After searching the Mbed API information, no luck, I still can not see how to get a simple non-RTOS low power solution.
This does work as it says on the tin both Mbed(2) and Mbed-os:
mbed_blinky_low_power
#include "mbed.h" DigitalOut myled(LED1); LowPowerTicker toggleTicker; /** * This is a callback! Do not call frequency-dependent operations here. * * For a more thorough explanation, go here: * https://developer.mbed.org/teams/SiliconLabs/wiki/Using-the-improved-mbed-sleep-API#mixing-sleep-with-synchronous-code **/ void ledToggler(void) { myled = !myled; } int main() { toggleTicker.attach(&ledToggler, 0.2f); while(1) { sleep(); } }
However we all know you can only use minimal code in a ISR call back, so how can I set a flag to jump out of sleep mode and return to sleep when I have finished like I did before.
This question does extend to other platforms not only SiLabs EFM32
Hi Paul,
Does segmentDisplay lock deep sleep?
posted by Desmond Chen 11 Nov 2019No Desmond, it didn't before. LCD display will remain powered(active) at around 6uA whilst the core is shut down. We need to un-depreciate the sleep/deepsleep functions on Mbed so they can also be used manually.
edit...
I have just stumbled on this information that has answered a previous issue I had noticed 'Device wakes up from deep sleep every second (or other period)'
https://os.mbed.com/docs/mbed-os/v5.14/tutorials/power-optimization.html
I'll look at this again and try with the examples shown.
posted by Paul Staron 11 Nov 2019