CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Setup_wdt() with WDT_18MS, WDT_ON, WDT_DIV_16

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
alpchen



Joined: 11 Jun 2009
Posts: 3

View user's profile Send private message

Setup_wdt() with WDT_18MS, WDT_ON, WDT_DIV_16
PostPosted: Thu Jun 11, 2009 2:43 pm     Reply with quote

Hi,

16f688.h says:
Code:

#define WDT_18MS        8   
#define WDT_36MS        9   
#define WDT_72MS       10   
#define WDT_144MS      11   
#define WDT_288MS      12   
#define WDT_576MS      13   
#define WDT_1152MS     14   
#define WDT_2304MS     15   

// One of the following may be OR'ed in with the above:

#define WDT_ON             0x4100   
#define WDT_OFF            0       
#define WDT_DIV_16         0x100
#define WDT_DIV_8          0x300
#define WDT_DIV_4          0x500
#define WDT_DIV_2          0x700
#define WDT_TIMES_1        0x900  // Default
#define WDT_TIMES_2        0xB00
#define WDT_TIMES_4        0xD00
#define WDT_TIMES_8        0xF00
#define WDT_TIMES_16      0x1100
#define WDT_TIMES_32      0x1300
#define WDT_TIMES_64      0x1500
#define WDT_TIMES_128     0x1700

but what if I want to turn the watchdog on, set prescaler to DIV_16 and set the duration to WDT_18MS?

can I do
Quote:
SETUP_WDT(WDT_18MS | WDT_ON | WDT_DIV_16);

or can I set the prescaler first, than other later, like
Code:

SETUP_WDT(WDT_DIV_16);
SETUP_WDT(WDT_18MS | WDT_ON);

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 11, 2009 3:00 pm     Reply with quote

Quote:
Can I set the prescaler first, than other later, like

SETUP_WDT(WDT_DIV_16);
SETUP_WDT(WDT_18MS | WDT_ON);

The functions are not additive. The latest call to the function determines
the settings of the module. The settings of any previous calls are
over-written. So, just call it one time.
alpchen



Joined: 11 Jun 2009
Posts: 3

View user's profile Send private message

PostPosted: Thu Jun 11, 2009 3:04 pm     Reply with quote

thanks.

but it's not clear if I can do this

SETUP_WDT(WDT_18MS | WDT_ON | WDT_DIV_16);

it looks like WDT_ON might conflict with WDT_DIV_16. And the header says "ONE of the following"
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 11, 2009 5:23 pm     Reply with quote

Post what you want to do.

There are two prescalers for the Watchdog Timer. There is a
16-bit prescaler with divisors from 1/32 to 1/65536, and there is
an additional prescaler with divisors from 1/1 to 1/128.

What is the final WDT timeout period that you want to get ?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Jun 11, 2009 11:17 pm     Reply with quote

As pointed out by Ttelmah in this previous thread http://www.ccsinfo.com/forum/viewtopic.php?t=38826 CCS C is hiding the actual WDT hardware configuration. This is also the case with 16F688. Instead of possibly fruitless experiments, you may want to set the WDT SFR explicitely in your code.
alpchen



Joined: 11 Jun 2009
Posts: 3

View user's profile Send private message

PostPosted: Fri Jun 12, 2009 12:37 am     Reply with quote

thanks.

I want to turn watchdog on and set the period to as short as possible (1ms) to reset the chip with reset reason == watchdog reset

but you are right, maybe it's easier just to write to registers myself.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 12, 2009 12:53 am     Reply with quote

Quote:
I want to turn watchdog on and set the period to as short as possible (1ms)

This code should do it:
Code:
.................... setup_wdt(WDT_18MS | WDT_ON | WDT_DIV_16); 
0010:  MOVLW  01
0011:  MOVWF  WDTCON      // WDTCON = 0x01
0012:  BSF    STATUS.RP0
0013:  MOVF   OPTION_REG,W
0014:  ANDLW  F0     // Lower 4 bits of OPTION_REG = 0
0015:  MOVWF  OPTION_REG
0016:  CLRWDT

Setting WDTCON to 0x01, turns on the WDT and sets the main prescaler
to 1/32. Setting the lower 4 bits of OPTION_REG to 0 will assign the
2nd prescaler to Timer0 (and not the WDT). So the only divisor is 1/32.
The WDT clock rate then becomes:
Code:
31000 / 32 = 969 Hz

which gives approximately a 1.0 ms WDT period.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group