issue with avr watchdog

Status
Not open for further replies.

movie_freak

Member level 5
Joined
Mar 20, 2007
Messages
89
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,286
Activity points
1,943
using avr watchdog

Hi,

I've tried something like this:
Code:
Code:
void WATCH_DOG_INIT(void)
{
         watch_dog_F =1;
      // Start timed equence
      WDTCR |= (1<<WDCE) | (1<<WDE);
      // Set new prescaler(time-out)
      WDTCR = (1<<WDE) | (1<<WDP2) | (1<<WDP1)|(1<<WDP0) |(0<<WDCE);

}


void RSET_WATCH_DOG(void)
{
  wdt_reset();            // reset watch dog
  watch_dog_counter = 10;
}


ISR()          // 1ms isr
{
  if(watch_dog_F ==1)
  {
     watch_dog_mili--;
     if(watch_dog_mili==0)
       {
       watch_dog_mili=1500;
      if(watch_dog_counter > 0)
       {
            watch_dog_counter--;
            wdt_reset();
       }
      
       }

   }   
}


int main(void)
 {
      WATCH_DOG_INIT();
       
      while(1)
       {
       
            /* Some work done over here */

           RSET_WATCH_DOG();
       }

     

 }


What i am trying to do:
initial values of watch_dog_mili =1500; watch_dog_F =0;watch_dog_counter=10;

set the watchdog timeout to ~ 2secs
calling wdt_reset every 1500ms in interrupt
In the mean time calling RST_WATCH_DOG() in main to check the software hang in every 10*1500 =15secs..

In my code there are no routines which take more than 10secs..still the watchdog resets the controller as soon as it is initialized..

So need help in this regard

Surya
 

avr watchdog

Hi guys,

Now my watchdog is working fine..

The change I made is

Code:
Code:
void WATCH_DOG_INIT()
{
      wdt_enable(WDTO_2S);
   watch_dog_F =1;   

}
instead of

Code:
Code:
void WATCH_DOG_INIT(void)
{
         watch_dog_F =1;
      // Start timed equence
      WDTCR |= (1<<WDCE) | (1<<WDE);
      // Set new prescaler(time-out)
      WDTCR = (1<<WDE) | (1<<WDP2) | (1<<WDP1)|(1<<WDP0) |(0<<WDCE);

}

So i believe that i've done the initialization wrong..
Can any one tell me the mistake that i have done in the latter case??


Many Thanks,
Surya
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…