Page 1 of 1

Simple Watch Dog with 8 bit PIC

Posted: Wed Sep 10, 2025 5:31 pm
by jay_dee
I recently had a problematic project that would lock up from random excessive noise.
Whilst we sorted out the root problem, I wanted to enable a Hardware Watchdog in the embedded project.
If the PIC crashed, the PIC would automatically reset and probalby run fine again.

I thought implmenting a WatchDog would be quite involved but it turned out to be really simple.

I have put together a little FC program for a PIC18F that flashed an LED and after 200 cycles, it fakes a Lock Up.
The WatchDog is triggered and reset the PIC, starting the process all over again.

The WatchDog is Enabled in the FC Configuration setting, same place you set the PIC version your using.
File > Project Options > For my PIC is was in section 0x2
The WatchDog Time-Out is 4mS x the PreScaler Value, which is also set in the Configuration settings.

You just need to consistantly run a single C command to stop the Watch Dog Triggering.

Code: Select all

CLRWDT();
I used a C component and placed it in a the main loop. Also made sure the main loop would never take longer than the WatchDog timer to cycle.

J.

Re: Simple Watch Dog with 8 bit PIC

Posted: Thu Sep 11, 2025 10:29 am
by chipfryer27
Hi

There is an interesting story involving NASA and WDT. Basically years ago someone decided to save a few cents by not implementing. You can guess the rest... how much did that part we didn't fit cost?????

In the options screen you also have a check box you can enable to auto clear watchdog, so FC does it for you in delays etc.

If implementing, whilst testing it is a good idea to have some form of visual indication your code is starting, such as an LED (or a line in a display) perhaps disabling it further along. If strange things are happening and your LED is on you know WDT has kicked in.

It can also be used to wake up from sleep, which doesn't cause a reset, it just continues again from where it went to sleep (good idea to throw in a NOP after sleep too).

Really good feature.

Regards