> > A trick I've used once before is set a location in RAM to a known > > value, eg. 0xAA, and invert it in the ISR. This way in just one place > > in your program you can reset the WDT being satisifed that BOTH > > the mainline code and ISR are looping as they should > > Hi Brent. Explain please Sure Jinx, I guess you mean explain without making it confusing - I'll try my best ;-) Take a simple program first - mainline code takes a finite time to execute then loops back to the start to do it all again. At the end is a good place to reset the watchdog - if it got to the end of the mainline code then it isn't locked up in an infinite loop anywhere, whole program is "protected". Now add an interrupt function, say one that executes repetetively, such as a timer interrupt that does important stuff like for example switch debouncing, display multiplexing, running system timers etc (I seem to always have one of these in my PIC projects). If you have a crash/infinite loop inside the ISR then the watchdog timer will timeout and trigger a reset - good. But what if a malfunction causes the interrupt to not happen at all? Consider the method... Initialise once only in mainline code: watchcat = 0xAA During ISR: if watchcat = 0xAA watchcat = !watchcat (invert the value) At end of mainline code: if watchcat = 0x55 watchcat = !watchcat reset watchdog The key is the variable "watchcat". If it's 0xAA the ISR inverts it and makes it 0x55. If it's 0x55 then mainline code inverts and makes it 0xAA. If either fails then the watchdog is not reset and a system reset occurs. Thus the watchdog now "protects" all the code - mainline code must complete, ISR must complete. It also adds a degree of protection against corruption in RAM - if "watchcat" value is corrupted then the tests fail and a watchdog reset occurs. You need to consider watchdog period and code timing etc, tweak the method so it suits what you're doing, expand on the idea. Where did I get the idea from? Probably here on the PIC list. The method above complies with the (unwritten?) rule that says the safest number of places in your code to reset the watchdog is 1. -- Brent Brown, Electronic Design Solutions 16 English Street, St Andrews, Hamilton 3200, New Zealand Ph: +64 7 849 0069 Fax: +64 7 849 0071 Cell: +64 27 433 4069 eMail: brent.brown@clear.net.nz -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist