gbgb 0 Posted March 6, 2013 Report Share Posted March 6, 2013 I am using the 18F6527 (18F8722 family) I want to implement a watchdog timer This seems simple enough: enable the WDT either by enabling WDTEN in CONFIG2H, or keep WDTEN disabled and do it in code by manipulating SWDTEN in WDTCON. However some things are not clear to me: 1. How do I reset the watchdog? is it simply an asm CLRWDT within the c code? 2. It says in the maual that reseting the watchdog also clears the prescaler. Does this mean that after each clear I have to reload the prescaler? 3. Which brings me to - can the configuration registers be manipulated at run time via c code? I think that for the 18 family it is possible but am not sure. If so - is it simply writing to them like any other SFR or is there a special procedure? And if not - how do you reload the prescaler if it is cleared at runtime (or prevent form clearing)? Quote Link to post Share on other sites
Reynard 0 Posted March 6, 2013 Report Share Posted March 6, 2013 Use the function "clear_wdt()" as on page 76 of the manual. The prescaler will retain its value after resetting the watchdog. The counter may get reset. Cheers Reynard Quote Link to post Share on other sites
gbgb 0 Posted March 7, 2013 Author Report Share Posted March 7, 2013 Thanks, Although I am using SourceBoost C I am trying to keep my code as clean as possible from "vendor specific" libraries in case a switch to a different compiler will be required. So the question still remains - is it simply and inline asm CLRWDT? I will try, but your statement about the prescaler is opposed to what is written in the device datasheet. Quote Link to post Share on other sites
Reynard 0 Posted March 7, 2013 Report Share Posted March 7, 2013 The manual says you can do it these ways: clear_wdt(); 006C 0064 CLRWDT asm CLRWDT 006D 0064 CLRWDT asm { CLRWDT } 006E 0064 CLRWDT All product the same machine code instruction. The prescaler value is set in the config 2H byte and therefore fixed. The watchdog counter increments until it meets the prescaler value then resets the chip. It is the counter that is reset on watchdog clear and sleep not the prescaler. The prescaler is a multiplexor which taps off the counter outputs. Cheers Reynard Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.