EmbeddedRelated.com
Forums

Watchdog timer

Started by GM M November 15, 2002
"Richard F. Man" wrote:
> 
> At 08:56 PM 11/15/2002 -0800, GM M wrote:

> >Coming back to the topic again. Thanks for
this additional information
> >which you have given in your reply. Can you specifically tell me why we
> >are adding the password and hold bit
> 
> The reason the add operator is used is that if the operands are bits, then
> adding them is the same as OR'ing them, e.g.
>          WDTCTL= WDTPW | WDTHOLD;
> is the same as
>          WDTCTL= WDTPW + WDTHOLD;

On the other hand, adding logic bits may not be a good habit to get into
because if either operand is a bit pattern and bits in the two operands
happen to overlap, then the column with the overlapping bits will be
cleared and there will be a carry into the next bit column, possibly
doing something you don't want.  So adding logic bits is less safe than
OR'ing, especially with things where you have to go look at a #define to
see what the actual bits are.  


--
                       -- Tom Digby
                       bubbles@bubb...
                       http://www.well.com/~bubbles/
                       http://www.well.com/~bubbles/BblB60DL.gif

Beginning Microcontrollers with the MSP430

Like Tom, AND and OR seem safer to me for such operations: you only need
one habit then, for both intitalizing a register and changing one or more
bits.  But on the other hand, if you assume that the defines are correct
(which would have to be the case else everything falls apart, with either
method) you could use addition for intitalizing a register and AND/OR/NOT
for partially modifying a register.  Then, if you stuck religiously to that
plan, you'd have a quick differentiator between intitalization and
modification, useful perhaps when reviewing code.  But it seems like one
more place for a tricky mistake to creep into your code, if you
accidentally used + when partially modifying a register.

Personally, I prefer macro functions like

WDT(ON); 	/* but I have no doubt that opinion could ignite a small
firestorm on this list. */

;)

Bruce



> On the other hand, adding logic bits may not be a
good habit to get into
> because if either operand is a bit pattern and bits in the two operands
> happen to overlap, then the column with the overlapping bits will be
> cleared and there will be a carry into the next bit column, possibly
> doing something you don't want.  So adding logic bits is less safe
than
> OR'ing, especially with things where you have to go look at a #define
to
> see what the actual bits are.


It may be quite urgent, but it is worth reading the data sheets, user
guides
and  applications notes.  This is a really basic question that can be
answered by downloading the correct user quide and reading the section on
the watchdog timer.

It is also unclear whether you are asking how the hardware works or how the
line of code is interpretted by the compiler.

Go to:
http://focus.ti.com/docs/analog/catalog/announcements/brc.jhtml?path=templat
edata/cm/brc/data/20011218msp430userguides&templateId=1

You will find the 4 guides there and the top section wil provide links to
the other resources.

In general, the watchdog timer works by restarting the processor when you
get a software hang.  After the timeout, the restart occurs.  The only way
to prevent this is to write a specific value to a specific register at
regular and short intervals.  This resets the counter in the watchdog timer
and is commingly referred to as kicking the watchdog.  It shows that the
code is still executing.  The value you must write has been arranged to
reduce the likelihood of a spurious register access from correctly kicking
the watchdog.

For the MSP430F413 the line of code I use is:

#define __watchdog_reset() (WDTCTL = WDT_MRST_32)

The exact value you write depends on what timeout interval you want.
WDT_MRST_32 is defined in the AQ430 header file as:

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

Many people would probably prefer to see this written as:

#define WDT_MRST_32         (WDTPW | WDTCNTCL)
/* 32ms interval (default) */

This is because logically ORing 2 values is closer to selecting which
register bits to set.  In practice, ADDing and ORing give the same result
provided both values don't have a 1 in the same location in the byte or
word
value.  If they do, then you get different outcomes.  EG (all bitwise 8 bit
math):

00000011 | 11000000 = 11000011
00000011 + 11000000 = 11000011

But

00000011 | 11000011 = 11000011
00000011 + 11000011 = 11000110

The header file defines the values as:

#define WDTPW               (0x5A00)
#define WDTCNTCL            (0x0008)

So WDT_MRST_32 = (WDTPW+WDTCNTCL) = (0x5A00 + 0x0008) = 0x5A08 = (WDTPW |
WDTCNTCL) = (0x5A00 | 0x0008) = 0x5A08

There is no substitute for reading through the training materials and really
understanding what you are doing.

Ray



  -----Original Message-----
  From: GM M [mailto:gmm2064@gmm2...]
  Sent: Friday, November 15, 2002 6:24 PM
  To: msp430@msp4...
  Subject: [msp430] Watchdog timer



  Hello All,

  Once again i m caught up with a problem. Can anyone tell me how following
line of code can stop the WatchDog timer??


    WDTCTL= WDTPW + WDTHOLD;

  plz reply as soon as possible as this is quite urgent,,,

  thankyou very much



  ---------------------------------
  

  


  .