EmbeddedRelated.com
Forums

LPC2104 Watchdog timer

Started by i will tell u if u ask January 5, 2007
Hello,
Trying to use the watchdog timer on the LPC2104 so it will
automaticlly reset if my software is ESD zapped and causes a lockup.
running on 10Mhz external oscillator. I have read the watchdog portion
in the datasheet but, i am getting resets all the time after i boot my
hardware everytime now. I feed the WDFEED very very often right now, a
crude way of troubleshooting the watchdog reset probelm that i have
and it still resets all the time. Can some one help please.
Here is a small peice of the code;

void feed_watchdog(){
WDFEED = 0xAA;
WDFEED = 0x55;
}

void main(){
//
.
.
.
Declarations and assignint Timer0 and EXT0 interrupts
.
.
.
if ( WDMOD & 0x04 ) {
WDMOD &= ~0x04;
}
WDTC = 0x000fffff;
WDMOD = 0x03; //enable and restart??

feed_watchdog(); //to start my WDT

while (1){ //my program tasks and frequently feeding }

}

Am i doing something wrong with the WDrest bit? Is it something i set
or does the ARM set it when it needs to reset? My understanding
WDreset bit is a bit to enable the WDT reset when the timer overflows,
and not to initial a reset everytime the program exects that command
(WDMOD = 0x03; //enable and restart??).
thanks
Sam

An Engineer's Guide to the LPC2100 Series

You need to keep in mind that the feed of the watchdog needs to be an atomic
instruction, ie if you're IRQ's are firing after you write 0xAA you'll
effectively reset the board.
So first off you need to ensure you're not going to get interrupted mid
feed... sort that first and then if you're still having problems post back
again.

Andy
-----Original Message-----
From: l... [mailto:l...]On Behalf Of
i will tell u if u ask
Sent: 05 January 2007 16:53
To: l...
Subject: [lpc2000] LPC2104 Watchdog timer
Hello,
Trying to use the watchdog timer on the LPC2104 so it will
automaticlly reset if my software is ESD zapped and causes a lockup.
running on 10Mhz external oscillator. I have read the watchdog portion
in the datasheet but, i am getting resets all the time after i boot my
hardware everytime now. I feed the WDFEED very very often right now, a
crude way of troubleshooting the watchdog reset probelm that i have
and it still resets all the time. Can some one help please.
Here is a small peice of the code;

void feed_watchdog(){
WDFEED = 0xAA;
WDFEED = 0x55;
}

void main(){
//
.
.
.
Declarations and assignint Timer0 and EXT0 interrupts
.
.
.
if ( WDMOD & 0x04 ) {
WDMOD &= ~0x04;
}
WDTC = 0x000fffff;
WDMOD = 0x03; //enable and restart??

feed_watchdog(); //to start my WDT

while (1){ //my program tasks and frequently feeding }

}

Am i doing something wrong with the WDrest bit? Is it something i set
or does the ARM set it when it needs to reset? My understanding
WDreset bit is a bit to enable the WDT reset when the timer overflows,
and not to initial a reset everytime the program exects that command
(WDMOD = 0x03; //enable and restart??).
thanks
Sam
> if ( WDMOD & 0x04 ) {
> WDMOD &= ~0x04;
> }
> WDTC = 0x000fffff;
> WDMOD = 0x03; //enable and restart??
>
> feed_watchdog(); //to start my WDT
>
> while (1){ //my program tasks and frequently feeding }
>
> }

It could be that the timeout value is a tad short?
Here's mine ..

WDTC = (_u32)(((_u64)pclk * WatchdogPeriodMS) / 4000); // set timeout
WDMOD = WDMOD_WDEN | WDMOD_WDRESET; // enable the watchdog
WDFEED = 0xAA;
WDFEED = 0x55;

Above is equal too.

WDTC = 0x007270E0; .... this is for a pclk of 30Mhz and a 2sec timeout
WDMOD = 0x03; .. enable watchdog & reset if timeout (no ints)
C.
I dont think you are making something wrong.
My setup for WDT here, running at 59MHZ (14.7MHZ * 4) and pclk =1 is like:

WDTC = 0x04650000; /* WDT for 5 seconds */
WDMOD = 0x03; /* Enable WDT */
clear_wdt();

void clear_wdt(void) {
WDFEED = 0xAA;
WDFEED = 0x55;
}

To test it, I made a simple routine that sends a character over serial port,
and hangs. WDT resets the uC and sends the caracter again, and hangs, and so
on. With that, I could look if it really hangs at 5 seconds or no.
I have two suggest to you: first, is a recommendation from the book The Art of
Designing Embedded Systems, where he suggests to have a hardware way to check
if the WDT restarted the system sometime. You cand make this using a GPIO,
for example, if you can connect a led to it on the development/testing time,
its even better. In my case, as my board uses serial port intensively, with a
protocol I made, when the fw boots I set a bit on a byte showing that I had a
WDT reset. And I have a command on my protocol to read that byte (I send
another flags from the system in this byte too). Its a good way to check from
time to time if the fw is running fine.
Second, I suggest you to try with longer WDT times if it is runnig as
expected, and after that, use a better time as you are trying.
Em Sex 05 Jan 2007 14:52, i will tell u if u ask escreveu:
> Hello,
> Trying to use the watchdog timer on the LPC2104 so it will
> automaticlly reset if my software is ESD zapped and causes a lockup.
> running on 10Mhz external oscillator. I have read the watchdog portion
> in the datasheet but, i am getting resets all the time after i boot my
> hardware everytime now. I feed the WDFEED very very often right now, a
> crude way of troubleshooting the watchdog reset probelm that i have
> and it still resets all the time. Can some one help please.
> Here is a small peice of the code;
>
> void feed_watchdog(){
> WDFEED = 0xAA;
> WDFEED = 0x55;
> }
>
> void main(){
> //
> .
> .
> .
> Declarations and assignint Timer0 and EXT0 interrupts
> .
> .
> .
> if ( WDMOD & 0x04 ) {
> WDMOD &= ~0x04;
> }
> WDTC = 0x000fffff;
> WDMOD = 0x03; //enable and restart??
>
> feed_watchdog(); //to start my WDT
>
> while (1){ //my program tasks and frequently feeding }
>
> }
>
> Am i doing something wrong with the WDrest bit? Is it something i set
> or does the ARM set it when it needs to reset? My understanding
> WDreset bit is a bit to enable the WDT reset when the timer overflows,
> and not to initial a reset everytime the program exects that command
> (WDMOD = 0x03; //enable and restart??).
> thanks
> Sam
Andrew Berney, cm296pip and Xtian Xultz thanks a lot guys, i have
solved the problem. All your comments and resposes were very valuable
whether informational or a reconforming. The problem i had was the wdt
feed routine was most likely being interrupted as Andrew said (Thanks
Andrew). So the quick fix for it was to change the watchdog_feed()
routine to;

void feed_watchdog(){
__disable_interrupt();
WDFEED = 0xAA;
WDFEED = 0x55;
__enable_interrupt();
}
All else is the same.

I hope this will be useful in future if someone shall run into the
same issue.

> thanks
> Sam
>