Reply by Ray Keefe November 17, 20022002-11-17
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



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

  


  .



  





Beginning Microcontrollers with the MSP430

Reply by Bruce Cannon November 16, 20022002-11-16
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.


Reply by Tom Digby November 16, 20022002-11-16
"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

Reply by GM M November 16, 20022002-11-16
Dear Kris,
What can i say????? you have really helped me alot. All i can say is THANKYOU
VERY MUCH
take care
 Kris De Vos <microbit@micr...> wrote:> Dear Richard,
> Thankyou very much for your reply. I am grateful
for your reply. But I am a beginner and cannot 
> understand why we are adding or applying OR here? Can you just explain this
to me in detail??
> Thankyou Very much

Hi man,

I'll quickly throw in 2 c worth too, but before doing so - 
I think you will find that very basic questions like you are asking will not get
much reply here,
this is a forum where people share findings, toolset issues, and general
"I'm stumped" stuff specific to MSP430.
But you've made a good choice ! You're starting to use MSP430, and
"C" will do a lot of the weird stuff for you,
but it's not a magic wand !!!
Also, this is not a class room forum for binary arithmetic.

Having said that, we all have been new to this - and "newbies" are
always welcome, as long as you don't
constantly "hog" the forum with things you should really learn
off-line.
We all still learn all the time, that's why we're all here.... and
otherwise it'd be boring anyway........

Very briefly :
-------------
The registers you are operating on are typically 8 bits (1 byte)  wide, some 16
bits (1 word).
As you found, at times you want to SET or CLEAR these bits, when they control
something.
The most common way to do so is to use binary operations, such as OR and AND.
(I assume you know that bitwise OR is :
0 OR 0 = 0
0 OR 1 = 1
1 OR 0 = 1
1 OR 1 = 1

and that bitwise AND is :
0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1
)

Consider this OR :
--------------------
1001 = 9 ( 1 * 2^3   + 1 * 2^0 )
Say you want to set bit # 2 in this number made of 4 bits ie. you want to make
1001 ---> into 1101    (bit 3 would be the most significant ie. 2 power 3 or
2^3, bit 0 the least significant ie. 2 power 0 = 2^0 = 1)

The easiest way to do this is to use the number :
0100 (which is 4) - as it has ONLY BIT 2 set to "1".

and OR it to set BIT 2 ->
1001     OR'd with
0100 -----
1101 (see modulo-2 add below)

An AND is typically used to CLEAR (set to 0) a bit :
---------------------
Again, take the number 1001 (9 decimal).
Say you want to clear BIT 3 now :
You work out now where to go from here :
(ie. how to use a "mask" by using the one's complement)

1001   AND
0111    -----
0001    -> bit 3 is now "0".

Maybe one word of caution that we all occasionally can overlook :
--
It is general practice (qwell I do too) to "add" the bits in that you
want set to "1", rather than ORing.
As above :
1001 +
0100 ------
1101 -> 13 decimal - or (9 + 4) which is the same as 

It is important that you understand that you can only use "add" if the
symbols that represent the bits, are made up of
only 1 bit set to "1", and also that the same bit position can only be
used ONCE

Eg :

1001 OR
0001 -----
1001

BUT :
==
1001 +
0001 -----
1010    (10 decimal , 9 + 1)
If the intention was here to set BIT 0 to "1", the add actually caused
it to clear to "0" !!!!!!!!
Keep this in MIND !!...........


In your example before :
WDTCTL= WDTPW + WDTHOLD;

WDTCTL is a register, and WDPTW / WDTHOLD are "symbols" representing
certain bit positions.
If both these bits need to be set, then the statement as above will ONLY set the
WDTPW (Watchdog password) and WDTHOLD (Hold) bits to "1", the others
will be "0".

If you go :
WDTCTL= WDTPW;
after having done the statement above, then you are re-writing to that WDTCTL
register -
this time with only the WDTPW bit set - in effect the WDTHOLD bit has been set
to "0" now.........


Maybe this will give you a "kickstart", but you REALLY will need to
get a good book on C, and preferably
one that starts from the start - ie. the Binary number system, and how to handle
Boolean stuff.

I personally liked Herbert Schildt's "C, the complete reference"
a lot to get a good grasp on the basics
of "C" - but everyone to their own.....
Try and learn these things as you go along, and post questions on things
specific to MSP430 here that
you are stuck with.
Newcomers one day become a source of knowledge too - so have fun / good luck !!!


Kris






.



 



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





Reply by Richard F. Man November 16, 20022002-11-16
At 08:04 PM 11/16/2002 +1100, Kris wrote:
>...
>Very briefly :
>-------------
>...

Kris, that's brief? I hate to see your verbose reply :-)

Nice explanation. May be I can hire you to write help files :-)


// richard <http://www.imagecraft.com> 
<http://www.dragonsgate.net/mailman/listinfo>
On-line orders, support, and listservers available on web site.
[ For technical support on ImageCraft products, please include all previous 
replies in your msgs. ] 


Reply by Kris De Vos November 16, 20022002-11-16
> Dear Richard,
> Thankyou very much for your reply. I am grateful
for your reply. But I am a beginner and cannot 
> understand why we are adding or applying OR here? Can you just explain this
to me in detail??
> Thankyou Very much

Hi man,

I'll quickly throw in 2 c worth too, but before doing so - 
I think you will find that very basic questions like you are asking will not get
much reply here,
this is a forum where people share findings, toolset issues, and general
"I'm stumped" stuff specific to MSP430.
But you've made a good choice ! You're starting to use MSP430, and
"C" will do a lot of the weird stuff for you,
but it's not a magic wand !!!
Also, this is not a class room forum for binary arithmetic.

Having said that, we all have been new to this - and "newbies" are
always welcome, as long as you don't
constantly "hog" the forum with things you should really learn
off-line.
We all still learn all the time, that's why we're all here.... and
otherwise it'd be boring anyway........

Very briefly :
-------------
The registers you are operating on are typically 8 bits (1 byte)  wide, some 16
bits (1 word).
As you found, at times you want to SET or CLEAR these bits, when they control
something.
The most common way to do so is to use binary operations, such as OR and AND.
(I assume you know that bitwise OR is :
0 OR 0 = 0
0 OR 1 = 1
1 OR 0 = 1
1 OR 1 = 1

and that bitwise AND is :
0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1
)

Consider this OR :
--------------------
1001 = 9 ( 1 * 2^3   + 1 * 2^0 )
Say you want to set bit # 2 in this number made of 4 bits ie. you want to make
1001 ---> into 1101    (bit 3 would be the most significant ie. 2 power 3 or
2^3, bit 0 the least significant ie. 2 power 0 = 2^0 = 1)

The easiest way to do this is to use the number :
0100 (which is 4) - as it has ONLY BIT 2 set to "1".

and OR it to set BIT 2 ->
1001     OR'd with
0100 -----
1101 (see modulo-2 add below)

An AND is typically used to CLEAR (set to 0) a bit :
---------------------
Again, take the number 1001 (9 decimal).
Say you want to clear BIT 3 now :
You work out now where to go from here :
(ie. how to use a "mask" by using the one's complement)

1001   AND
0111    -----
0001    -> bit 3 is now "0".

Maybe one word of caution that we all occasionally can overlook :
--
It is general practice (qwell I do too) to "add" the bits in that you
want set to "1", rather than ORing.
As above :
1001 +
0100 ------
1101 -> 13 decimal - or (9 + 4) which is the same as 

It is important that you understand that you can only use "add" if the
symbols that represent the bits, are made up of
only 1 bit set to "1", and also that the same bit position can only be
used ONCE

Eg :

1001 OR
0001 -----
1001

BUT :
==
1001 +
0001 -----
1010    (10 decimal , 9 + 1)
If the intention was here to set BIT 0 to "1", the add actually caused
it to clear to "0" !!!!!!!!
Keep this in MIND !!...........


In your example before :
WDTCTL= WDTPW + WDTHOLD;

WDTCTL is a register, and WDPTW / WDTHOLD are "symbols" representing
certain bit positions.
If both these bits need to be set, then the statement as above will ONLY set the
WDTPW (Watchdog password) and WDTHOLD (Hold) bits to "1", the others
will be "0".

If you go :
WDTCTL= WDTPW;
after having done the statement above, then you are re-writing to that WDTCTL
register -
this time with only the WDTPW bit set - in effect the WDTHOLD bit has been set
to "0" now.........


Maybe this will give you a "kickstart", but you REALLY will need to
get a good book on C, and preferably
one that starts from the start - ie. the Binary number system, and how to handle
Boolean stuff.

I personally liked Herbert Schildt's "C, the complete reference"
a lot to get a good grasp on the basics
of "C" - but everyone to their own.....
Try and learn these things as you go along, and post questions on things
specific to MSP430 here that
you are stuck with.
Newcomers one day become a source of knowledge too - so have fun / good luck !!!


Kris






Reply by GM M November 16, 20022002-11-16
Dear Richard,
Thankyou very much for your reply. I am grateful for your reply. But I am a
beginner and cannot understand why we are adding or applying OR here? Can you
just explain this to me in detail??
Thankyou Very much
 "Richard F. Man" <richard@rich...> wrote:At 08:56 PM 11/15/2002
-0800, GM M wrote:

>Dear Jardar,
>Thankyou very much for your reply. I am sorry if my typing style bothered 
>you. You will never see it again.
>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;

>thankyou Very much
>Waiting for your reply
>  Jardar Johannes Maatje <maatje@maat...> wrote:This is superbasic 
> programming stuf so I recommend you to get a beginners
>book on programming C.
>
>In the example with the watchdogtimer we are setting bits so instead of
>adding values, we could or then together:
>
>WDTCTL= WDTPW | WDTHOLD;
>
>If you dont want the WDTHOLD bit set just do:
>
>WDTCTL= WDTPW;
>
>In general if there is just a single bit that you want to change you can
>do:
>
>REG &= ~BITMASK;
>
>Setting is done by:
>
>REG |= BITMASK;
>
>And once again it looks much more civilised if you try to write proper
>english instead of ( ur, plz, thankx and just a lot of
>..................,,,,,,,,,,). It realy look stupid. And as another guy
>pointed out, read the manual.
>
>Jardar
>
>On Fri, 15 Nov 2002, GM M wrote:
>
> >
> > thankyou very much for ur reply....yes i have that guide and i have
> > studied about 10 times......what i cannot understand is ... why are
the
> > two values added??? and this line stops the watchdog timer.... i.e.
sets
> > the HOLD bit to 1... if i want to set the bit back to zeroo... how can
i
> > do it??? thankx once again
> >  vikebo <vikebo@vike...> wrote:Hi.
> >
> > Do you have the "MSP430x1xx Family User's Guide"? You
will find it as 
> SLAU049B.
> >
> > The Watchdog Timer Control Register is explained on page 9-3. Bit 7 is

> called "HOLD", and on the next page you will see that this bit
stops the 
> operation of the watchdog counter.
> >
> > You also need to write the correct password to the register.
> >
> > Eivind
> >
> > --- In msp430@y..., GM M <gmm2064@y...> wrote:
> > >
> > > 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
> > >
> > >
> > >
> > > ---------------------------------
> > > 
> >
> >
>
>
>.
>
>
>
>
>
>
>
>---------------------------------
>

// richard <http://www.imagecraft.com> 
<http://www.dragonsgate.net/mailman/listinfo>
On-line orders, support, and listservers available on web site.
[ For technical support on ImageCraft products, please include all previous 
replies in your msgs. ] 


.



 



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





Reply by Richard F. Man November 16, 20022002-11-16
At 08:56 PM 11/15/2002 -0800, GM M wrote:

>Dear Jardar,
>Thankyou very much for your reply. I am sorry if my typing style bothered 
>you. You will never see it again.
>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;

>thankyou Very much
>Waiting for your reply
>  Jardar Johannes Maatje <maatje@maat...> wrote:This is superbasic 
> programming stuf so I recommend you to get a beginners
>book on programming C.
>
>In the example with the watchdogtimer we are setting bits so instead of
>adding values, we could or then together:
>
>WDTCTL= WDTPW | WDTHOLD;
>
>If you dont want the WDTHOLD bit set just do:
>
>WDTCTL= WDTPW;
>
>In general if there is just a single bit that you want to change you can
>do:
>
>REG &= ~BITMASK;
>
>Setting is done by:
>
>REG |= BITMASK;
>
>And once again it looks much more civilised if you try to write proper
>english instead of ( ur, plz, thankx and just a lot of
>..................,,,,,,,,,,). It realy look stupid. And as another guy
>pointed out, read the manual.
>
>Jardar
>
>On Fri, 15 Nov 2002, GM M wrote:
>
> >
> > thankyou very much for ur reply....yes i have that guide and i have
> > studied about 10 times......what i cannot understand is ... why are
the
> > two values added??? and this line stops the watchdog timer.... i.e.
sets
> > the HOLD bit to 1... if i want to set the bit back to zeroo... how can
i
> > do it??? thankx once again
> >  vikebo <vikebo@vike...> wrote:Hi.
> >
> > Do you have the "MSP430x1xx Family User's Guide"? You
will find it as 
> SLAU049B.
> >
> > The Watchdog Timer Control Register is explained on page 9-3. Bit 7 is

> called "HOLD", and on the next page you will see that this bit
stops the 
> operation of the watchdog counter.
> >
> > You also need to write the correct password to the register.
> >
> > Eivind
> >
> > --- In msp430@y..., GM M <gmm2064@y...> wrote:
> > >
> > > 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
> > >
> > >
> > >
> > > ---------------------------------
> > > 
> >
> >
>
>
>.
>
>
>
>
>
>
>
>---------------------------------
>

// richard <http://www.imagecraft.com> 
<http://www.dragonsgate.net/mailman/listinfo>
On-line orders, support, and listservers available on web site.
[ For technical support on ImageCraft products, please include all previous 
replies in your msgs. ] 


Reply by GM M November 16, 20022002-11-16
Dear Jardar,
Thankyou very much for your reply. I am sorry if my typing style bothered you.
You will never see it again.
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
thankyou Very much
Waiting for your reply
 Jardar Johannes Maatje <maatje@maat...> wrote:This is superbasic
programming stuf so I recommend you to get a beginners
book on programming C.

In the example with the watchdogtimer we are setting bits so instead of
adding values, we could or then together:

WDTCTL= WDTPW | WDTHOLD;

If you dont want the WDTHOLD bit set just do:

WDTCTL= WDTPW;

In general if there is just a single bit that you want to change you can
do:

REG &= ~BITMASK;

Setting is done by:

REG |= BITMASK;

And once again it looks much more civilised if you try to write proper
english instead of ( ur, plz, thankx and just a lot of
..................,,,,,,,,,,). It realy look stupid. And as another guy
pointed out, read the manual.

Jardar

On Fri, 15 Nov 2002, GM M wrote:

>
> thankyou very much for ur reply....yes i have that guide and i have
> studied about 10 times......what i cannot understand is ... why are the
> two values added??? and this line stops the watchdog timer.... i.e. sets
> the HOLD bit to 1... if i want to set the bit back to zeroo... how can i
> do it??? thankx once again
>  vikebo <vikebo@vike...> wrote:Hi.
>
> Do you have the "MSP430x1xx Family User's Guide"? You will
find it as SLAU049B.
>
> The Watchdog Timer Control Register is explained on page 9-3. Bit 7 is
called "HOLD", and on the next page you will see that this bit stops
the operation of the watchdog counter.
>
> You also need to write the correct password to the register.
>
> Eivind
>
> --- In msp430@y..., GM M <gmm2064@y...> wrote:
> >
> > 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
> >
> >
> >
> > ---------------------------------
> > 
>
>


.



 



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





Reply by Jardar Johannes Maatje November 15, 20022002-11-15
This is superbasic programming stuf so I recommend you to get a beginners
book on programming C.

In the example with the watchdogtimer we are setting bits so instead of
adding values, we could or then together:

WDTCTL= WDTPW | WDTHOLD;

If you dont want the WDTHOLD bit set just do:

WDTCTL= WDTPW;

In general if there is just a single bit that you want to change you can
do:

REG &= ~BITMASK;

Setting is done by:

REG |= BITMASK;

And once again it looks much more civilised if you try to write proper
english instead of ( ur, plz, thankx and just a lot of
..................,,,,,,,,,,). It realy look stupid. And as another guy
pointed out, read the manual.

Jardar

On Fri, 15 Nov 2002, GM M wrote:

>
> thankyou very much for ur reply....yes i have that guide and i have
> studied about 10 times......what i cannot understand is ... why are the
> two values added??? and this line stops the watchdog timer.... i.e. sets
> the HOLD bit to 1... if i want to set the bit back to zeroo... how can i
> do it??? thankx once again
>  vikebo <vikebo@vike...> wrote:Hi.
>
> Do you have the "MSP430x1xx Family User's Guide"? You will
find it as SLAU049B.
>
> The Watchdog Timer Control Register is explained on page 9-3. Bit 7 is
called "HOLD", and on the next page you will see that this bit stops
the operation of the watchdog counter.
>
> You also need to write the correct password to the register.
>
> Eivind
>
> --- In msp430@y..., GM M <gmm2064@y...> wrote:
> >
> > 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
> >
> >
> >
> > ---------------------------------
> > 
>
>