Can't wakeup MBED from DeepSleep

23 Jan 2010 . Edited: 23 Jan 2010

 

Based on Michael's code (http://mbed.org/users/no2chem/notebook/mbed-power-controlconsumption/) which I fixed for myself, I played a little bit with various sleep modes. I did not do any power measurements (not near the lab today), but I was able to send MBED LPC1768 into every given mode (Sleep, Deep Sleep, PowerDown, Deep PowerDown).

I was able to wakeup MBED from Sleep using GPIO interrupt (switch on MBED_BoB2). For the Deep Sleep and Power Down, however, I cannot wake MBED up (Deep PowerDown is said to wakeup only upon reset or RTC interrupt). I tried p9 through p12 and p21 to no avail.

I've read LPC1768 user manual back and forth, and there is no indication of any black magic involved around sleep/wakeup. The only relevant information I was able to google out is that LPC1768 has problems waking up if SWD was ever used (see http://www.embeddedrelated.com/groups/lpc2000/show/44945.php). I think it may be what happens on MBED. Can anyone shed some light on this - does the little MBED chip always open JTAG port on the LPC1768? If that's the case, then we can forget about using Deep Sleep or PowerDown modes on MBED, unless it is fixed with firmware update of course.

 

24 Jan 2010

Yes, I think a way to turn off the mbed mcu would be great and would probably fix this problem. The other way is to write the copy protection bits, which I think turns off JTAG at level 1... but it'd be much easier to just "kill" the mbed mcu...

one way to do it...
create file on mbed called "settings.ini"
inside, add lines like,
jtagoff=1
ledoff=1
mbedchipsleep=1

mbed goes to sleep until you hold reset button for 10 seconds. good way to save on power as well!

we're at 120 mA with the 1768 in deep sleep.... turning off the led should drop us 10-20mA, and I'm not sure how much the mbed mcu takes active...

then again, maybe its time for me to recalibrate my power supply,...  ~100 mA with just mbed mcu seems a bit high, no?

25 Jan 2010 . Edited: 25 Jan 2010

 

Michael Wei wrote:
The other way is to write the copy protection bits

Will MBED be reprogrammable after that? And how would writing copy protection bits be done?

 

I've tried "settings.ini" as you suggest, but there is no difference. I recall some discussion of "settings.ini" being not used anymore with newer firmware... any ideas?

25 Jan 2010
Ilya I wrote:

 

Michael Wei wrote:
The other way is to write the copy protection bits

Will MBED be reprogrammable after that? And how would writing copy protection bits be done?

 

I've tried "settings.ini" as you suggest, but there is no difference. I recall some discussion of "settings.ini" being not used anymore with newer firmware... any ideas?

Oh no, the settings.ini was a suggestion... For the mbed team to implement...

I'm not exactly sure how to write the copy protection bits, I think it's done during ISP. It would turn off JTAG, but leave ISP open at level 1 (write only). At level 3, I think you can't even write to it anymore.

But it'd be easier for them to just add a way to turn off SWD.

25 Jan 2010

 

Michael Wei wrote:
Oh no, the settings.ini was a suggestion... For the mbed team to implement...

Thanks for the clarification - I misunderstood you in the previous post. Would it be great if there was such a control?

MBED is very powerful tool for mains-powered projects (and I have few of them queued), but for battery applications 140mA is a no-starter. It will take 240mAh battery out in under 2 hours. LPC1768 is positioned as a very-low power capable device. In non-related projects based on other low-power micros I routinely get 5-10 days operation time on 240mAh Li-Po battery. The key to that is keeping device in IDLE (Deep Sleep, PowerDown or any other name) and have absolute lowest current (<100uA). Device should only wake up when there is a task, and go back to sleep immediately after completing every task. LPC1768 supports that mode using interrupts and DeepSleep/PowerDown modes.

What was interesting to find out is while reset button is pressed, the current drops some, but stays quite high at 90mA. That's a lot higher than one would expect. I measured the blue LED current - it takes only around 2mA, so it is not the culprit. The 140mA is probably divided 30/70% between MBED chip and LPC1768, but based on very high reset current I would think that MBED chip takes around 80mA on its own.

Worst case I want to see below 10-40mA IDLE current. That will allow running up to 12 hours - it is good enough for proof of concept. With that battery-powered applications will make sense to prototype with MBED.

 

Simon,

Can you chime in here on the subject (supporting power savings modes wakeup on MBED, such as DeepSleep and PowerDown)? And also plans to make it lower-power overall?

 

 

26 Jan 2010 . Edited: 26 Jan 2010
Ilya I wrote:

 

Michael Wei wrote:
Oh no, the settings.ini was a suggestion... For the mbed team to implement...

Thanks for the clarification - I misunderstood you in the previous post. Would it be great if there was such a control?

MBED is very powerful tool for mains-powered projects (and I have few of them queued), but for battery applications 140mA is a no-starter. It will take 240mAh battery out in under 2 hours. LPC1768 is positioned as a very-low power capable device. In non-related projects based on other low-power micros I routinely get 5-10 days operation time on 240mAh Li-Po battery. The key to that is keeping device in IDLE (Deep Sleep, PowerDown or any other name) and have absolute lowest current (<100uA). Device should only wake up when there is a task, and go back to sleep immediately after completing every task. LPC1768 supports that mode using interrupts and DeepSleep/PowerDown modes.

What was interesting to find out is while reset button is pressed, the current drops some, but stays quite high at 90mA. That's a lot higher than one would expect. I measured the blue LED current - it takes only around 2mA, so it is not the culprit. The 140mA is probably divided 30/70% between MBED chip and LPC1768, but based on very high reset current I would think that MBED chip takes around 80mA on its own.

Worst case I want to see below 10-40mA IDLE current. That will allow running up to 12 hours - it is good enough for proof of concept. With that battery-powered applications will make sense to prototype with MBED.

 

Simon,

Can you chime in here on the subject (supporting power savings modes wakeup on MBED, such as DeepSleep and PowerDown)? And also plans to make it lower-power overall?

 

 

Ilya,

I was able to save about 80mA thanks to a suggestion to turn off the PHY by Paul... My mbed is running in normal operation at 112 mA right now... and 57.6 mA in DeepPowerDown... we're getting somewhere! =). Just need to turn off that 2mA LED and the mbed micro now...

I'll update the PowerControl library with new code soon... you have to turn ON ethernet to get access to the MII interface though.

04 Nov 2010

Hi,

Has anyone managed to get the mbed to wake up from Deep Sleep?

I see in the LPC1768 manual that setting CRP1/2/3 bits should disable debug mode and allow the CPU to enter lower power states, but I don't want to do anything that might prevent the chip from being reprogrammed.

I'm using the offline compiler, so changing the CRP bits shouldn't be a problem.

06 Dec 2010 . Edited: 03 Feb 2011

http://mbed.org/users/simon/notebook/interface-powerdown/ also states that it disconnects the debugger - so it might help the DeepSleep and Power Down wake up problems some people are having. Section 33.5 of the LPC1768 user manual says not to try to wakeup from DeepSleep and PowerDown modes during a debug. The normal operation mode of mbed keeps it in debug mode.

09 Oct 2011

I seem to have an example now that wakes up from deep sleep mode. My meter shows a 27MA current draw with one LED on. I used the watchdog timer clocked by the RTC and the new Beta firmware to powerdown the USB interface and recall that it needs external power on Vin. After powerdown I reset the processor in software (NXP manual said you should do a reset? or cycle power after exiting debug mode (on mbed via USB powerdown) for wakeup to work). So far, I can only get it to reset from DeepSleep. A watchdog interrupt did not seem to work. I enabled the interrupt and set up an interrupt handler with NVIC commands, but no wakeup resulted.

Here is what I have:

#include "mbed.h"
#include "PowerControl/PowerControl.h"
#include "PowerControl/EthernetPowerControl.h"
// Need PowerControl *.h files from this URL
// http://mbed.org/users/no2chem/notebook/mbed-power-controlconsumption/
// and new Beta library from http://mbed.org/handbook/Beta

DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);


int volatile count;

// Simon's Watchdog code from
// http://mbed.org/forum/mbed/topic/508/
class Watchdog {
public:
// Load timeout value in watchdog timer and enable
    void kick(float s) {
        LPC_WDT->WDCLKSEL = 0x02;               // Set CLK src to RTC for DeepSleep wakeup
        LPC_WDT->WDTC = (s/4.0)*32768;
        LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset
        kick();
    }
// "kick" or "feed" the dog - reset the watchdog timer
// by writing this required bit pattern
    void kick() {
        LPC_WDT->WDFEED = 0xAA;
        LPC_WDT->WDFEED = 0x55;
    }
};

// Setup the watchdog timer
Watchdog wdt;

// Blink LED
void blink() {
    myled4 = 0;
    myled1 = 1;
}

int main() {
    int result;
    Watchdog wdt;

// On reset, determine if a watchdog, power on reset or a pushbutton caused reset and display on LED 4 or 3
// Check reset source register
    result = LPC_SC->RSID;
    if ((result & 0x03 )==0) {
// was not POR or reset pushbutton so
// Mbed is out of debug mode and reset so can enter DeepSleep now and wakeup using watchdog
        myled4 = 1;
        wait(.00625);
        wdt.kick(2);
        blink();
// Power level in DeepSleep around 135mW (27MA at 5VDC)
// LED1 is several MAs of this
        DeepSleep();
// Watch dog timer wakes it up with a reset
//
    } else {
// Was an initial manual or Power on Reset
// This codes only executes the first time after initial POR or button reset
        LPC_SC->RSID = 0x0F;
// Clear reset source register bits for next reset
        myled3 = 1;
// LED3 on to indicate initial reset at full power level
// Normal mbed power level for this setup is around 690mW
// assuming 5V used on Vin pin
// If you don't need networking...
// Power down Ethernet interface - saves around 175mW
// Also need to unplug network cable - just a cable sucks power
        PHY_PowerDown();
// If you don't need the PC host USB interface....
// Power down magic USB interface chip - saves around 150mW
// Needs new firmware (URL below) and USB cable not connected
// Power coming from Vin pin
// http://mbed.org/handbook/Beta
// Must supply power to mbed using Vin pin for powerdown
// Also exits debug mode - must not be in debug mode
// for deep power down modes
        result = mbed_interface_powerdown();
// Power consumption is now around half
// Turn off clock enables on unused I/O Peripherals (UARTs, Timers, PWM, SPI, CAN, I2C, A/D...)
// To save just a tiny bit more power - most are already off by default in this short code example
// See PowerControl.h for I/O device bit assignments
// Don't turn off GPIO - it is needed to blink the LEDs
        Peripheral_PowerDown(0xFFFF7FFF);
// Now can do a reset to free mbed of debug mode
// NXP manual says must exit debug mode and reset for DeepSleep or lower power levels to wakeup
        wait(1);
        NVIC_SystemReset();
    }
}

You need to log in to post a reply