Watchdog Timing

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Watchdog Timing

2,293件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mohsin on Tue Dec 21 10:16:47 MST 2010
Hi All,

          I am using LPC114 in my project and trying to get the watchdog working. I am trying to set the watchdog timer to 50ms and I am feeding it every 5 ms.  I am getting random resets using the code below

void
Watchdog_Init(
    void
) {
    /*
    ** Make sure WDT config clock is turned on
    */
    LPC_SYSCON->SYSAHBCLKCTRL |= 0x08000;

    /*
    **  Enable internal RC clock
    */
    LPC_SYSCON->PDRUNCFG &= ~(1);

    /*
    ** Select internal RC for watchdog
    */
    LPC_SYSCON->WDTCLKSEL = 0;
     
    /*
    **  Toggle WDTCLKUEN to latch clock selection
    */
    LPC_SYSCON->WDTCLKUEN = 0;
    LPC_SYSCON->WDTCLKUEN = 1;

    /*
    ** We are using the internal RC clock to drive the watchdog because it is
    ** independent of PLL settings. The "System Clock" option routes the clock
    ** after the PLL to the watchdog. The "System Clock" could vary depending
    ** on what CPU speed is configured with the PLL.
    */

    /*
    **  Set watchdog counter value to timeout 50 ms
    */
    LPC_WDT->TC = (unsigned int) (((unsigned int) 12000000/4)/1000) * (unsigned int) 50;

    /*
    ** Set up watchdog clock "divide" by one (default state is gated off)
    */
    LPC_SYSCON->WDTCLKDIV = 1;
     
    /*
    ** Enable watchdog, and arm it to generate a reset upon timeout
    */
    LPC_WDT->MOD = 0x3;

    /*
    **  Send watchdog "feed" sequence- final step to begin the timeout
    */
    LPC_WDT->FEED = MHM_WD_FEED1;
    LPC_WDT->FEED = MHM_WD_FEED2;
}

Can anyone let me know if anything is wrong?
   Thanks,
   Mohsin
0 件の賞賛
返信
9 返答(返信)

1,994件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by marcossmart on Fri Jun 29 09:47:02 MST 2012
Lock-up problem when I return from Deep power down with the WatchDog enabled, when I disable the WatchDog have no problem locking, you know what can be?
0 件の賞賛
返信

1,994件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Jun 29 09:40:21 MST 2012

Quote: marcossmart
which the correct sequence to disable the WDT after you have started?



:confused:

It's a WatchDog :eek:

User manual:

Quote:

...the WDT cannot be disabled.

0 件の賞賛
返信

1,994件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by marcossmart on Fri Jun 29 09:34:11 MST 2012
which the correct sequence to disable the WDT after you have started?
0 件の賞賛
返信

1,994件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Dec 22 16:12:23 MST 2010
UM10398 17.7.3 Watchdog Feed register (WDFEED - 0x4000 4008)

Quote:
... After writing 0xAA to WDFEED, access to any Watchdog register other than writing 0x55 to WDFEED causes an immediate reset/interrupt when the Watchdog is enabled.


[LEFT]So, if an ISR is executed between this 2 feeding commands, WDT interrupt is executed.:mad:[/LEFT]

[LEFT]To avoid this, you can[/LEFT]

[LEFT]1. disable/enable interrupts before/after WDT Feed[/LEFT]

[LEFT]2. use this 2 commands within ISR (e.g. SysTick) with higher interrupt priority. So UART ISR (with lower priority) can't interrupt them.[/LEFT]
0 件の賞賛
返信

1,994件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mohsin on Wed Dec 22 04:22:08 MST 2010
OK Finaly found what was causing the watchdog to behave in the odd way.


The code for watchdog initialisation which I posted earlier seems to be correct. The probem was I had to disable the interrupts when feeding the watchdog. I have got interrupts going on in the background from the UART.

void WDTFeed( void )
{
[COLOR=Red]    __disable_irq();[/COLOR]
  LPC_WDT->FEED = 0xAA;        /* Feeding sequence */
  LPC_WDT->FEED = 0x55;
[COLOR=Red]     __enable_irq();[/COLOR]
}
Did anyone noticed this behaviour ?

  Regards,
Mohsin
0 件の賞賛
返信

1,994件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Dec 21 12:48:24 MST 2010
Just found my WDT Sample (LPC1114/301) :):)

It enables WDT (with IRC). Each WDT Interrupt (1 second) toggles a LED and WDT interrupt is enabled again.
Without commented out WDTFeed() (in while loop) WDT interrupt is toggling LED continuously.
With WDTFeed() LED stays ON without WDT interrupt.

[ATTACH]266[/ATTACH]
0 件の賞賛
返信

1,994件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Dec 21 11:22:06 MST 2010
While debugging WDT isn't stopped, so that's no surprise :)
So use an output (LED or scope) to see how fast WDT_IRQ is called while your program is running.
Are you sure your WDT is reloaded?
0 件の賞賛
返信

1,994件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mohsin on Tue Dec 21 11:02:00 MST 2010
Thanks for the reply. I have tried using the interrupt while in debug and it goes into the WDT_IRQHandler()

I have also tried using big delays like the one below and it still goes into WDT_IRQHandler()
/*
    **  Set watchdog counter value to timeout 5000 ms
    */
    LPC_WDT->TC = (unsigned int) (((unsigned int) 12000000/4)/1000) * (unsigned int) 5000;

Any clues what could be wrong ?
Thanks,
Mohsin
0 件の賞賛
返信

1,994件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Dec 21 10:47:25 MST 2010
AFAIR it's a problem to set Enable & Reset in LPC_WDT->MOD while trying to debug. So try setting just LPC_WDT->MOD = 1; (= enable) and use something to count in WDT_IRQ.

void WDT_IRQHandler(void)
[LEFT]{
LPC_WDT->MOD &= ~WDTOF; /* clear the time-out interrupt flag */[/LEFT]
 wdt_counter++;
 
[LEFT]}[/LEFT]
0 件の賞賛
返信