watchdog reseting problem

Hi there, I am trying to use the MSP430 watchdog in watchdog mode but am currently having no success.

I have this little program to demostrate. It is meant to prove that I can correctly reset the Watchdog counter before it resets the device, but it failes and is always resetting.

#include <msp430x16x.h>

void flash_led(void);

int main( void )

{

WDTCTL = WDTPW + WDTHOLD; /* Stop watchdog timer */

P3OUT &= ~BIT3; /* Set pin input LOW */

P3DIR |= BIT3; /* Set pin direction to output */

flash_led(); /* Flashing indicates MC start */

IFG1 &= ~WDTIFG;

WDTCTL = WDT_MRST_32 + ~WDTHOLD; /* Enable watchdog */

for(;:wink:

{

WDTCTL |= WDTPW + WDTCNTCL;

}

return 0;

}

void flash_led(void)

{

unsigned int a,b;

for (a = 0; a < 8; a++)

{

for (b = 0; b < 25000;)

{

b++;

}

P3OUT ^= BIT3; /* Toggle output */

}

}

Any help would be great.

Thanks

The problem is in the line:

WDTCTL = WDT_MRST_32 + ~WDTHOLD; /* Enable watchdog */

WDTHOLD is defined (by the header file) to be 0x0080

thus ~WDTHOLD is 0xFF7F

Thanks but I could not understand bcoz 0xFF7F change the bits of WDTCTL register…

WDTHOLD=1(watchdog timer is not stopped)

WDTNMIES=1(NMI on falling edge)

WDTNMI=1 (NMI function)

I understand the WDTHOLD but does not clearly understand the purpose of settting other two bits…thxx…

Your intention at that point is (I think) to send the WDTCTL the password 0x5A00 plus the bit pattern so that (a) the WDT will use the SMCLK and generate a RST after 32768 counts, (b) with the WDT couner cleared, (c) without NMI enabled, (d) without NMI edge select, and (e) without holding the WDT. Thus what you need to do is:

WDTCTL = 0x5A08;

If you look at the TI header file, WDT_MRST_32 is defined to be 0x5A08. So:

WDTCTL = WDT_MRST_32;

is the same as:

WDTCTL = 0x5A08;

and will have exactly the same effect. It does not include the WDTHOLD bit. It does not include the WDTNMI bit or the WDTNMIES bit.

BUT, the actual code you used include the additional term +~WDTHOLD.

This, means +0xFF7F and you get the same effect as:

WDTCTL = 0x5A08 + 0xFF7F;

which is the same as:

WDTCTL = 0x5987;

This is not what you wanted and the password part is wrong too!

(I think) in your mind, ~WDTHOLD means without the WDTHOLD bit. But the c-compiler took it as “all the other bits except the WDTHOLD bit”. When you add that, the you changed everything!

YES: I want that WDT will use the SMCLK and generate a RST after 32768 counts…

As you mentioned in (e)

WDTCTL = 0x7A08 I think it would be 0x5A08…

In the TI header file it is as,

#define WDT_MDLY_32 (WDTPW+WDTTMSEL+WDTCNTCL) /* 32ms interval (default) */

WDTHOLD=0x0080

WDTPW=0x5A00

WDTCNTCL=0x0008

WDTTMSEL=0x0010

I try to enable watchdog mode but still could not able to enable watchdog timer mode.

could you please comments on that…thanks for help…

Sorry, I had typos in the hex numbers in my previous reply. They are corrected now. Please go back and check it.

With that setting, you will get a RST when it expires. That is, the entire code will start all over again.

If you want the WDT to generate an interrupt (instead of a RST), you should have used WDT_MDLY_32 (instead of WDT_MRST_32).

if I use this one instead of interrupt …as u mentioned it will reset the device after 32ms…but it is not reseting the code again…

WDTCTL=WDT_MDLY_32;

could you please little bit more guide me how can i reset the timer? thanks for you comments…