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 CCS Technical Support

Watchdog timer (WDT) usage and docs confusing

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



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

Watchdog timer (WDT) usage and docs confusing
PostPosted: Mon Apr 21, 2008 9:06 am     Reply with quote

Hello,

I find the CCS docs not very good as far as watchdog timer explanation. I am using a PIC18F4620. The fuses in my .h file are as follows:

#fuses HS, WDT, NOPROTECT, NOLVP, PUT, FCMEN

In my .c file, I have the following line:

setup_wdt(WDT_OFF);

The WDT seems to work because I can voluntarily cause the PIC to freeze and if I wait about 2 minutes, it reboots, which is fine. The only problem is that I find 2 minutes too long. I'd like to make this much shorter. I'm trying to understand the CCS documentation but like most of their documentation, it's not very clear.

In setup_wdt(), it says:

#fuses WDT_18MS // PIC18 example, See restart_wdt for a PIC18 example

The you go to restart_wdt() and it says:

// See setup_wdt for a PIC18 example

Huh??

In the 18F4620.h file that I include in my project, there are several places that seem to make use of "WDT":

The top of the file where it shows the different fuses although nowhere in there or in the docs does it say what each value is;

Then a little bit further there's a section about the WDT:

////////////////////////////////////////////////////////////////// WDT
// Watch Dog Timer Functions: SETUP_WDT() or SETUP_COUNTERS()
// RESTART_WDT()
//
#define WDT_ON 0x100
#define WDT_OFF 0

So, "what" do I use "where" and how do I configure "what" to make it do a restart of the WDT after about 5 seconds??

In my C code, do I say "SETUP_WDT( WDT_ON)" but in the fuses I indicate the length in milliseconds using the different WDT_x fuses?

Can someone please clarify?
Matro
Guest







PostPosted: Mon Apr 21, 2008 9:14 am     Reply with quote

My advice is to read the Microchip datasheet of your part to understand how does the watchdog work. After that you should be able to set it up correctly.

Matro
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Mon Apr 21, 2008 9:20 am     Reply with quote

Well, I *know* what's the purpose of the WDT so the Microchip docs won't help here. I think you missed my point: what I'm saying is that the CCS docs aren't clear and both related functions make you jump from one to the other and back wihtout further explanations. Their documentation is not clear as to how to use the fuses and the functions based on the PIC type.

Anyhow, I think I got it to work after I posted this. It's now just a matter of testing.

From what I understand, for the PIC18 series, you either set the WDT on or off using SETUP_WDT( WDT_ON ) or SETUP_WDT( WDT_OFF ) but in the .h file, you specify what delay of WDT you want using the WDTxxx fuse e.g. WDT128 or WDT256. The number value in the fuse name seems to be milliseconds based on the quick test I did.

Can anyonw tell me if my explanation/observation above is correct?
Matro
Guest







PostPosted: Mon Apr 21, 2008 9:41 am     Reply with quote

With PIC 18, you have to enable the watchdog in the fuses and also to set the timeout in the fuses.
When you say WDT128 or WDT256, the value is the one of the prescaler that is applied to the watchdog oscillator.
After you have to enable watchdog by software with setup_wdt(WDT_ON).
The best is to look in the .h file of the part or in the datasheet to know which prescaler value corresponds to which timeout.

Matro.
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