|
|
View previous topic :: View next topic |
Author |
Message |
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
Watchdog timer (WDT) usage and docs confusing |
Posted: Mon Apr 21, 2008 9:06 am |
|
|
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
|
|
Posted: Mon Apr 21, 2008 9:14 am |
|
|
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
|
|
Posted: Mon Apr 21, 2008 9:20 am |
|
|
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
|
|
Posted: Mon Apr 21, 2008 9:41 am |
|
|
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. |
|
|
|
|
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
|