Waking up issues with watchdog timer and wake-up timer

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

Waking up issues with watchdog timer and wake-up timer

Jump to solution
2,254 Views
kamranfarhangi
Contributor II

Hi all,

I am using an LPC 824, and I'm trying to wake it up 250 ms after going to DeepSleep (or Power-Down mode). I tried using the Wake-up timer and the watchdog timer to wake it up, but for some reason it does not work.

This is the init part of the code for using the WDT:

//Setting watchdog timer up

/* Freq = 0.6Mhz, divided by 64. WDT_OSC should be 9.375khz */
Chip_Clock_SetWDTOSC(WDTLFO_OSC_0_60, 64);

/* Enable the power to the WDT */
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_WDTOSC_PD);

/* Initialize WWDT (also enables WWDT clock) */
Chip_WWDT_Init(LPC_WWDT);

and this is the interrupt handler:


void WDT_IRQHandler(void)
{
   uint32_t wdtStatus = Chip_WWDT_GetStatus(LPC_WWDT);

   if (wdtStatus & WWDT_WDMOD_WDTOF) {
      //printf("Inside watchdog timer handler\n");
      /* A watchdog feed didn't occur prior to window timeout */
      Chip_WWDT_UnsetOption(LPC_WWDT, WWDT_WDMOD_WDEN); /* Stop WDT */
      Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDTOF);
   }
}

and this is the main code putting the MCU in DeepSleep mode:

if(goToSleep) { 
   #define WAKE_UP_EVERY_MS 250

   /* The WDT divides the input frequency into it by 4 */
   uint32_t wdtFreq = Chip_Clock_GetWDTOSCRate() / 4;
   Chip_WWDT_SetTimeOut(LPC_WWDT, wdtFreq * WAKE_UP_EVERY_MS / 1000);
   Chip_WWDT_Feed(LPC_WWDT);
   /* Clear watchdog warning and timeout interrupts */
   Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDTOF | WWDT_WDMOD_WDINT);
   /* Clear and enable watchdog interrupt */
   NVIC_ClearPendingIRQ(WDT_IRQn);
   NVIC_EnableIRQ(WDT_IRQn);

   /* Start watchdog */
   Chip_WWDT_Start(LPC_WWDT);


   Chip_PMU_DeepSleepState(LPC_PMU);
   //LPC is now in DeepSleep state


   timems += WAKE_UP_EVERY_MS;

}

When I uncomment the printf, and don't put the MCU in sleep, I can see that the interrupt is called as it should. But for some reason it is either does not interrupt or does not wake the MCU up while it is in sleep mode.

I also tried using wake-up timer and the result was exactly the same. Works good then MCU is awake, but does not work in sleep mode!

Thank you in advance for your help.

1 Solution
2,007 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Kamran Farhangi,

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
To provide the fastest possible support, I'd highly recommend you to refer to the attachment.
Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

3 Replies
2,007 Views
kamranfarhangi
Contributor II

I also tried a clean project and it is again the same. It interrupts only while the MCU is awake. This is the enire clean project I tried:

#include "chip.h"

void WDT_IRQHandler(void)
{
uint32_t wdtStatus = Chip_WWDT_GetStatus(LPC_WWDT);

/* The chip will reset before this happens, but if the WDT doesn't
have WWDT_WDMOD_WDRESET enabled, this will hit once */
if (wdtStatus & WWDT_WDMOD_WDTOF) {
/* A watchdog feed didn't occur prior to window timeout */
Chip_WWDT_UnsetOption(LPC_WWDT, WWDT_WDMOD_WDEN); /* Stop WDT */
Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDTOF);
Chip_WWDT_Start(LPC_WWDT); /* Needs restart */
}

/* Handle warning interrupt */
if (wdtStatus & WWDT_WDMOD_WDINT) {
/* A watchdog feed didn't occur prior to warning timeout */
Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDINT);
Chip_WWDT_Feed(LPC_WWDT);
}
}


int main(void)
{

//Blink an LED for a short time (to indicate a restart)
Chip_GPIO_Init(LPC_GPIO_PORT);
Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 14);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 14, 1);
for(uint32_t i=0;i<0xFFFFF;i++); //busy wait loop
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 14, 0);


uint32_t wdtFreq;

SystemCoreClockUpdate();

/* Freq = 0.6Mhz, divided by 64. WDT_OSC should be 9.375khz */
Chip_Clock_SetWDTOSC(WDTLFO_OSC_0_60, 64);

/* Enable the power to the WDT */
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_WDTOSC_PD);

/* The WDT divides the input frequency into it by 4 */
wdtFreq = Chip_Clock_GetWDTOSCRate() / 4;


/* Initialize WWDT (also enables WWDT clock) */
Chip_WWDT_Init(LPC_WWDT);

/* Set watchdog feed time constant to approximately 2s
Set watchdog warning time to 512 ticks after feed time constant
Set watchdog window time to 3s */
Chip_WWDT_SetTimeOut(LPC_WWDT, wdtFreq * 2);
Chip_WWDT_Feed(LPC_WWDT);
Chip_WWDT_SetWarning(LPC_WWDT, 512);
Chip_WWDT_SetWindow(LPC_WWDT, wdtFreq * 3);

/* Configure WWDT to reset on timeout */
Chip_WWDT_SetOption(LPC_WWDT, WWDT_WDMOD_WDRESET);

/* Clear watchdog warning and timeout interrupts */
Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDTOF | WWDT_WDMOD_WDINT);

/* Clear and enable watchdog interrupt */
NVIC_ClearPendingIRQ(WDT_IRQn);
NVIC_EnableIRQ(WDT_IRQn);

/* Start watchdog */
Chip_WWDT_Start(LPC_WWDT);

Chip_PMU_DeepSleepState(LPC_PMU);
}

0 Kudos
Reply
2,008 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Kamran Farhangi,

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
To provide the fastest possible support, I'd highly recommend you to refer to the attachment.
Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

2,007 Views
kamranfarhangi
Contributor II

Hi jeremyzhou,

Thank you. I used the example in the attachment and it is working fine.

0 Kudos
Reply