You are not logged in

Log in into our community

Log in so you acess some hidden content

* Fields are required.

Register into our community!

Sign up now for some good content

* Fields are required.

Lost something?

Enter your username or email to reset your password.

* Fields are required.

Watchdog Timer

Posted on : Sun , 03 2014 by : virusi

THEORY ON WATCHDOG TIMER :


A watchdog timer (WDT; sometimes called a computer operating properly or COP timer, or simply a watchdog) is an electronic timer that is used to detect and recover from computer malfunctions. During normal operation, the computer regularly restarts the watchdog timer to prevent it from elapsing, or “timing out”. If, due to a hardware fault or program error, the computer fails to restart the watchdog, the timer will elapse and generate a timeout signal. The timeout signal is used to initiate corrective action or actions. The corrective actions typically include placing the computer system in a safe state and restoring normal system operation. The act of restarting a watchdog timer is commonly referred to as “kicking the dog” or other similar terms; this is typically done by writing to a watchdog control port. Watchdog timers may have either fixed or programmable time intervals. Some watchdog timers allow the time interval to be programmed by selecting from among a few selectable, discrete values. In others, the interval can be programmed to arbitrary values. Typically, watchdog time intervals range from ten milliseconds to a minute or more. In a multistage watchdog, each timer may have its own, unique time interval. A watchdog timer may initiate any of several types of corrective action, including processor reset, non-maskable interrupt, maskable interrupt, power cycling, fail-safe state activation, or combinations of these.

Basically they are two types of watchdogs, internal and external watchdogs. Internal watchdogs are those that are built into the processor chip. Internal units offer minimal protection from rogue code. Runaway software may reprogram the WDT controller, many internal watchdogs will not generate a proper reset, and any failure of the processor will make it impossible to put the hardware into a safe state.

External watchdog are external chips that are triggered by the micronctoller, if micronctoller is not triggering the external watchdog for a certain time than it is reseted by external watchdog.

In embedded systems and control systems, watchdog timers are often used to activate fail-safe circuitry. When activated, the fail-safe circuitry forces all control outputs to safe states (e.g., turns off motors, heaters, and high-voltages) to prevent injuries and equipment damage while the fault persists.

What’s the rationale behind an awesome watchdog timer? The perfect WDT should detect all erratic and insane software modes.It should leave breadcrumbs behind, generating debug information for the developers.A really effective watchdog cannot use the CPU’s clock, which may fail. Under no circumstances should the software be able to reprogram the WDT or any of its necessary components.

In some application you may use more watchdogs that operate in different ways ,this is called multistage watchdog. In a multistage watchdog, only the first stage is kicked by the processor. If first stage could not recover the system from the fail state , upon final stage timeout a corrective action is initiated. Typically, single-stage watchdog timers are used to simply restart the computer, whereas multistage watchdog timers will sequentially trigger a series of corrective actions, with the final stage triggering a computer restart.

LPC1768 PRACTICAL EXAMPLE :


Will build an small application. Will have a global variable that after some operation will stuck in a endless loop. After a configured time watchdog interrupt will occur and will make a watchdog reset. Of course this is will form the same an endless loop but this program is just to get used to watchdog.

SystemTickTimerApplication
Fig.1 Watchdog timer application

AT INITIALIZATION :

1. Configure MCU clock

/* initialize clocks */
SystemInit();  

2. Configure LED’s port as output.

/* Configure P 2.00... P 2.07 as output */
LPC_GPIO2->FIODIR   = ((1UL<< 0)|(1UL<< 1)|
			  (1UL<< 2)|(1UL<< 3)|
                          (1UL<< 4)|(1UL<< 5)|
                          (1UL<< 6)|(1UL<< 7)) ;
/* turn off all the LEDs */            
LPC_GPIO2->FIOCLR = 0x000000FF 

3. Configure Watchdog timer.

/* watchdog timer configuration */
 void ConfigureWDT()
 {
 	/* enable WDT interrupt */
	NVIC_EnableIRQ(WDT_IRQn);
        /* Watchdog Timer Constantregister */
	LPC_WDT->WDTC = WDCOUNT;
	/* WDEN Watchdog enable bit  */
	LPC_WDT->WDMOD = WDEN;
	/* Watchdog Feed register */
	/* Feed value should be 0xAA 
	followed by 0x55. */ 
	LPC_WDT->WDFEED = 0xAA;		
  	LPC_WDT->WDFEED = 0x55;
 } 

IN INTERRUPT :

1. In watchdog interrupt reset global variable.

/* WDT interrupt handler */
 void WDT_IRQHandler(void)
 {
    currentLed = 0x01;	
    /* make a watchdog reset */
    LPC_WDT->WDMOD = WDRESET;
 } 

AT RUNTIME :

1. Depending on the variable state turn on a different LED

 void kickWDT(void)
 {
 	/* Watchdog Feed register */
	/* Feed value should be 0xAA 
	followed by 0x55. */ 
	LPC_WDT->WDFEED = 0xAA;		
  	LPC_WDT->WDFEED = 0x55;
 }
/* set LED and kick the WDT */
 void setLED( uint8_t val)
 {
 	LPC_GPIO2->FIOPIN = (val>>1);
	Delay(60);
	currentLed = val;
	kickWDT(); 
 }
 int main (void) 
 {
	ConfigureMCU();
	/* Setup SysTick Timer for 1 msec interrupts  */
	if( SysTick_Config(SystemCoreClock / 1000) )
	{ 	/* Capture error */
    	   while (1);                              
 	}
	while(1)
	{
		/* do nothing */
		switch(currentLed)
		{
			case 0x01:
			{
				setLED(0x03);
			}
			break;
			case 0x03:
			{
			  setLED(0x07); 
			}
			break;
			case 0x07:
			{
			  setLED(0x0F); 
			}
			break;
			case 0x0F:
			{
			   setLED(0x1F); 	
			}
			break;
			case 0x1F:
			{
			   setLED(0x3F); 
			}
			break;
			case 0x3F:
			{
			   setLED(0x7F); 
			}
			break;
			case 0x7F:
			{
			  setLED(0xFF);
			}
			break; 	
			default:
			{
			  LPC_GPIO2->FIOPIN = (0xFF);
			  currentLed = 0xFF;
			  Delay(1000);
			}
		}
	}
 } 

Download :


If you are interested in the full example then download watchdog timer example .
Last updated on Mon , 03 2014
SHARE THIS PAGE :

This page is waiting for your comment.

Share and Leave a comment.

You must be logged in to post a comment.

Back to Top