LPC1114 deep sleep wake up

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1114 deep sleep wake up

1,279 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ben302 on Tue Nov 11 07:52:36 MST 2014
Struggling with this one. I've looked at examples : microbuiler and NXP an11069 so I think I have everything correct but yet the WAKEUP_IRQHandler is never entered.
I'm successfully switching to the watchdog osc from the IRC and I can see the Timer waggling the MAT3 pin of Timer32B0 pin 0.11. If I stop the debugger just before it sleeps (so the timer is running) I can flip the NVIC ISPR0 bit (0x800) and my interrupt is entered.
I've tried running in in Release mode with no debugger connected.
Currently I'm just trying to wake up and toggle the LED but eventually I'll reset the clock to IRC and do some activity before returning to deep sleep.

void WAKEUP_IRQHandler(void)
{
  dword dwRegVal;

  LPC_SYSCON->SYSAHBCLKCTRL |= SYSAHBCLKCTRL_IOCON | SYSAHBCLKCTRL_GPIO;  //@TODO: needed???

  dwRegVal = LPC_SYSCON->STARTSRP0;
  if (dwRegVal != 0)
  {
    LPC_SYSCON->STARTRSRP0CLR = dwRegVal;
  }

#if 1
  if ( boGPIODDgetPin( SYS_LED ) )
  {
    vGPIODDsetInactive( SYS_LED ); // off
  }
  else
  {
    vGPIODDsetActive( SYS_LED ); // on
  }
#endif

  /* See tracker for bug report. */
  __asm volatile ("NOP");
  return;
}

static void vDeepSleep( void )
{
  vGPIODDconfigurePin( GPIO_TIMER32_0_MAT3, PIN_IN, FALSE ); // make input but with no pull-up/down

  LPC_SYSCON->STARTAPRP0 &= ~(1<<11);     // rising edge on pin 0_11
  LPC_SYSCON->STARTRSRP0CLR |= (1<<11);  // clear all pending bits
  LPC_SYSCON->STARTERP0 |= (1<<11);      // Enable start logic on pin 0_11
  // - and enable the wake up interrupt
  NVIC_ClearPendingIRQ(WAKEUP11_IRQn);   // P0.11    (CT32B0_MAT3)
  NVIC_EnableIRQ(WAKEUP11_IRQn);         // P0.11    (CT32B0_MAT3) 

  /* Configure watchdog clock */
  LPC_SYSCON->WDTCLKDIV = 0x1;
  /* Freq. = 0.6MHz, div = 64: WDT_OSC = 9375 Hz  */
  LPC_SYSCON->WDTOSCCTRL = 0x3F;
  /* Enable WDT clock  - PDRUNCFG is set bit for power down state */
  LPC_SYSCON->PDRUNCFG &= ~(PDRUNCFG_WDTOSC_PD);

  // peripherals to power up on deep sleep wake
  LPC_SYSCON->PDAWAKECFG = LPC_SYSCON->PDRUNCFG;    // @TODO:  note WD is powered during awake mode - not required in final version
  // wdog osc on, BOD off in deep sleep
  LPC_SYSCON->PDSLEEPCFG = 0x18BF;

  LPC_PMU->PCON &= ~(PCON_DPDEN);  // deep sleep not deep power down mode
  LPC_PMU->PCON |= PCON_DPD;  // clear DPDFLAG in power control register
  LPC_PMU->PCON |= PCON_SLEEP;  // clear SLEEPFLAG in power control register

  // - enable clock for CT32B0 in case not already
  LPC_SYSCON->SYSAHBCLKCTRL |= SYSAHBCLKCTRL_CT32B0;
  LPC_SYSCON->SYSAHBCLKCTRL |= SYSAHBCLKCTRL_IOCON | SYSAHBCLKCTRL_GPIO;

    // - reset and disable the timer
  LPC_TMR32B0->TCR = (0x1 << 1);
  LPC_TMR32B0->TCR = 0x00;

  // - prescale by 1
  LPC_TMR32B0->PR = 0;
  LPC_TMR32B0->PC = 0; // clear prescalar counter
  // - clear timer counter current value
  LPC_TMR32B0->TC = 0;
  // - reset & INT on Match MR0, for next wake
  LPC_TMR32B0->MCR = (0x3);
  // set timer value
  LPC_TMR32B0->MR0 = (937); // @TODO: timer value  - ms at 9375 Hz (600000/64)
  // configure external match register
  LPC_TMR32B0->EMR &= ~(0xFF << 4); // clear all the config
  LPC_TMR32B0->EMR |= (0x3 << 10);   // toggle MAT3 on match

  // Clear match bit on timer
  LPC_TMR32B0->EMR &= ~(1<<3); // MAT3

    // Switch main clock to WDT output
  LPC_SYSCON->MAINCLKSEL = MAINCLKSEL_WDT;
  LPC_SYSCON->MAINCLKUEN |= MAINCLKUEN_ENA;       // Update clock source
  LPC_SYSCON->MAINCLKUEN &= ~MAINCLKUEN_ENA;      // Toggle update register once
  LPC_SYSCON->MAINCLKUEN |= MAINCLKUEN_ENA;
  // Wait until the clock is updated
  while (!(LPC_SYSCON->MAINCLKUEN & MAINCLKUEN_ENA));

  // start wake timer
  LPC_TMR32B0->TCR = 0x01;

  // deep sleep mode
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;

  while(1)
  {
    __WFI();
  }
}

Any gotcha's there? I've check the Errata and nothing seems to apply. Getting to the end of my tether! I wish they wouldn't keep me on a tether.
Labels (1)
0 Kudos
6 Replies

695 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ben302 on Fri Nov 14 05:56:01 MST 2014
I've now got my board down to 46uA which is about right for my board design.
The SYSAHBCLKCTRL setting seemed to account for about 15uA. The last bit was switching SWD port pins to GPIO which I had left to last as I wanted to keep debugging.
A tip for debugging (I'm using Rowley and Crossworks), if you divide down the JTAG clock rate by 32 in the target settings, you can continue debugging while in the wdog osc mode, and see the WAKE interrupt being called. Very useful!

Thanks Paul.
0 Kudos

695 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Paul on Thu Nov 13 08:54:21 MST 2014
The SYSAHBCLKCTRL will probably have much more influence in deep-sleep mode if you are running the watchdog oscillator (which is required for some of the wake-up modes).
I would recommend reviewing the following app note which has some other areas that you may want to look at to reduced power consumption (especially look at the port pins):
http://www.lpcware.com/content/nxpfile/an11027-using-lpc1100-low-power-modes-and-wake-times-lpcxpres...

- Paul
0 Kudos

695 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ben302 on Thu Nov 13 06:54:43 MST 2014
I'm now focusing on reducing the power consumption in the deep sleep state. It's down to about 75uA at the moment which is not bad, but I could do with a little less.

Does SYSAHBCLKCTRL have any effect once you are in Deep Sleep mode? I see it in a lot of code examples being set to various combinations, but I'm not convinced that it has any effect in Deep Sleep. (it can help in non-sleep modes to shutdown bits you are not using).
0 Kudos

695 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ben302 on Wed Nov 12 07:53:48 MST 2014
Well - its working if I use TMR16B0 MR0 MAT0 pin0.8
but not if I use                 TMR32B0 MR0 MAT3 pin0.11 (I have an accessible test point here so I can see the timer working, but it doesn't wake up)

I may have to try some other timer and pin combinations as I'm already using pin0.8 for other things.

Is there something special about TMR32B0 or the TMR32B0 MAT3 pin that I have to look out for? Anyone else used these Timers / pins?


(update: I've got it working on TMR32B0 MR0 MAT2 pin0.1 OK now. So there must be something different about MAT3 pin0.11)
0 Kudos

695 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ben302 on Tue Nov 11 08:37:37 MST 2014
Thanks Paul, I'll check that out.
0 Kudos

695 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Paul on Tue Nov 11 08:28:50 MST 2014
I didn't go through your code, but noticed that you reference AN11069 (low power modes for the LPC12xx).  Please take a look at AN11027 which describes the low power modes for the LPC111x family:

http://www.lpcware.com/content/nxpfile/an11027-using-lpc1100-low-power-modes-and-wake-times-lpcxpres...

Regards
Paul
0 Kudos