Enables lower power Sleep and power down modes for LPC11U24 systems than the mbed API supports directly.

Dependents:   mBuDice SleepyCounting

You are viewing an older revision! See the latest version

Homepage

Provides a clean method to put the mBuino into various power save modes while minimizing power draw. This code is specifically for the mBuino, for other LPC11U24 based systems use this version.

The system will pause in a power saving state until it receives an interrupt at which point things carry on as before.

The basic use is

#include "mBuinoSleep.h"

main() {
mBuinoSleep(PowerDown);
}

In order to shut off the LEDs the library will create a BusOut object called LEDs containing all 7 mBuino LEDs in order. When entering sleep mode the LEDs will be turned off, when waking the previous state will be restored. Within your code you can set individual LEDs using LEDs[n] where n is 0-6 or set them all by setting the value of LEDs directly e.g. LEDs = 0x7f would turn them all on. See BusOut for more details.

Similarly a DigitalIn called progMode is created on port pin 0_3 in order to disable the pullup on this pin (required to reduce power consumption).

If either of these cause a problem in your code then use the mBuino_Sleep_Minimal library which has the same sleep code but without any IO control.

Finally if you add the line

sleep_CleanShutdown = true;

to your code anywhere before entering sleep mode then the system clock will be switched from the PLL to the IRC before entering deepSleep or PowerDown and switched back after waking up. This is recommended by the CPU user manual in order to avoid clock glitches but in practice doesn't seem necessary. The down side to doing this is that any code in the interrupt routine that wakes the system up again will run at the IRC frequency not the normal clock frequency.

The supported sleep modes are:

  • Sleep - About a 50% power saving.
  • DeepSleep - Power consumption in the 350uA region (a few weeks or so on a watch battery). Timers won't be as accurate.
  • PowerDown - Power consumption in the 3uA region (Battery life in the decades range, in practice battery life will be determined by other factors). Similar to DeepSleep but takes a few ms longer to wake up.
  • DeepPowerDown - Sub uA power consumption but can only wake from the reset or wakeup pin (which also causes a reset).

Warning DO NOT enter sleep mode from within an interrupt (that includes Timers, Tickers, Timeouts etc...) unless your wakeup interrupt is higher priority (if you aren't sure or don't know what I'm talking about then it isn't). If you do this you will never wake up.

NOTE: DeepPowerDown requires an external pullup on the wakeup pin.


All wikipages