Watchdog Timer – WDT

Watch Dog Timer (WDT)

Watch Dog Timer (WDT) is a timer which makes micro controller program work properly without freezing. Its basic working principle is to make microcontroller reset when WDT overflows. To prevent this, we have to clear WDT register periodically in the program flow.

Actually, WDT is a standart 8 bit timer that counts continously. However, when overflow takes place, it reset microcontroller instead of interrupting.

WDT must be enabled while programming microcontroller. It is done by setting WDT bit of configuration word. On programmer software, there is an enable bit to do that.

It uses a built in RC oscillator which is apart from any other oscillators. That makes it run independent from general oscillator. So, even when oscillator is not running (for example in SLEEP mode), it will continue to work and produce time-out reset or wake-up.

WDT period

WDT overflow takes aproximately 18ms. It is aproximate value because it depends on variables such as voltage level, temperature, production, etc.

WDT period can be expanded up to 2.3 seconds by using max. prescaler value.

Prescaler configuration can be made by using OPTION register. PS<2:0> bits sets prescaler value. PSA bit determines who will use prescaler value, WDT or Timer0. See Timers section for further information.


PS«2:0» – prescaler
000 – 1:1
001 – 1:2
010 – 1:4
011 – 1:8
100 – 1:16
101 – 1:32
110 – 1:64
111 – 1:128

To understand reason of reset

When WDT reset occured, TO’ bit of the STATUS register will be cleared. We can check this bit at the begining of the program to understand if the reset is caused by WDT time out.

WDT example :

#define <>

ORG 0×00
GOTO main

main: ;Program will flow here when Power-Up or WDT overflow
CLRWDT ;Clear WDT, prevent WDT overflow for now
;PORTB is output
;Check if the reset is caused by WDT Time out
BSF PORTB,0 ;WDT Time out has occured, set PORTB.0
MOVLW b’00001000′ ;Prescaler = 000 => 1:1 prescaler,
MOVWF OPTION_REG ‘ PSA=1 => WDT will use the prescaler
CLRWDT ;Clear WDT, prevent WDT overflow for now
LOOP: ;Continous loop
GOTO LOOP ;We don’t clear WDT, WDT will reset program


In a professional program, use Watch Dog Timer to make your application more robust. It will prevent crashes in your program.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Reddit
  • Add to favorites
  • Email
  • RSS

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>