Saturday, June 22, 2013

Watchdog Timer Hung Up Eliminator

First time when I start to work with micro-controller the first I did is to look at the feature summary usually on the first few pages of the datasheet or product manual.  For a beginner, the first word that I came across and a little strange though, "Watchdog".  The first impression to me it is some feature built-in to the micro-controller to watch after the micro-controller to prevent hacker or protect against any theft.  NOT! My impression is way off from the actual usage of "Watchdog".  What is "Watchdog" anyway?

"Watchdog" is a feature built-in to most or all micro-controller / processor to prevent any software hung up in case the code can't get out from an infinite loop.  Once it is enabled, Watchdog timer is running on the background using either the internal oscillator or external oscillator connected to the processor.  Depending on which micro-controller or processor the Watchdog timer can be configured to expire at certain time period.  In case of code hung up the Watchdog timer will expire and force the micro-controller or processor to Reset and start the code from beginning.  Due to this the programmer requires to reset the Watchdog timer in the software to prevent from unintentional Reset.   

For Microchip micro-controller the extended Watchdog timer is programmable from as short as 4 millisecond to as long as 2 minutes.  In order to enable the Watchdog timer in a Microchip micro-controller one just set a bit in the Configuration Bit.  For PIC18F2XK22, the Watchdog timer configuration is resided in CONFIG2H (different Microchip micro-controller will have different location for the Watchdog timer configuration).  For resetting the Watchdog timer, the Assembly code is "CLRWDT" that will takes 1 instruction cycle to execute and if you are using Hi-Tech C-compiler just write "CLRWDT();" to reset the Watchdog timer.

That's all about Watchdog timer.  To know more about Watchdog timer, you can get a general definition from Wikipedia (http://en.wikipedia.org/wiki/Watchdog_timer).  Next time I will share with you on Timer module in a micro-controller.

No comments:

Post a Comment