watchdog timer interrupt in atmega1280

Last post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
I am trying to enable the watchdog timer in Atmega1280. The code is as follows:
int main(void)
{
while(1)
{
wdt_reset();
WDTCSR = _BV(WDIF) | _BV(WDIE) |_BV(WDCE) | _BV(WDE) | WDTO_1S;
WDTCSR = _BV(WDIF) | _BV(WDIE) | WDTO_1S;
MCUSR = 0;
sei();

}
}

ISR(WDT_vect )
{
// Do something
}

but the interrupt routime is not getting started.. any idea.. Please help :(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Keep resetting the watchdog in the while loop won't help.

int main(void){
	MCUSR = 0;
	WDTCSR = (1<<WDCE)|(1<<WDE);
	WDTCSR = (1<<WDIF)|(1<<WDIE)|WDTO_1S;
	sei();
	while(1);
}

ISR(WDT_vect ){
	// Do something
} 

The wdce/wde part is only needed to change the prescale in this case.

my (mostly untested) watchdog header for irq modes-
http://www.mtcnet.net/~henryvm/wdt/

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can u plz suggest me the code... I am new to AVR programming...
I need a watchdog which will wake up the processor every one minute... using atmega1280...
Thanks in advance :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can u plz suggest me the code... I am new to AVR programming...
I need a watchdog which will wake up the processor every one minute... using atmega1280...
Thanks in advance

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All,
Following is my code snippet.. need to have a watchdog which will wake up the controller from sleep every one minute.. Right now trying for 8 sec.
int main(void)
{

MCUCR &= ~_BV(PUD);
WDT_Initialization_as_Wakeup_Source();
while(1)
{

// Some src here

wdt_reset();
WDTCSR |= (1<<WDIE);
sleep_enable();
for(;;)
{
fun_xyz1(); // Some src
}

}
}

ISR(WDT_vect)
{
fun_xyz2();// Some src
}

void WDT_Initialization_as_Wakeup_Source( void )
{
/* Setup Watchdog */
// Use Timed Sequence for disabling Watchdog System Reset Mode if it has been enabled unintentionally.
MCUSR &= ~(1<<WDRF); // Clear WDRF if it has been unintentionally set.
WDTCSR = (1<<WDCE )|(1<<WDE ); // Enable configuration change.
WDTCSR = (1<<WDIF)|(1<<WDIE)| // Enable Watchdog Interrupt Mode.
(1<<WDCE )|(0<<WDE )| // Disable Watchdog System Reset Mode if unintentionally enabled.
(1<<WDP3 )|(0<<WDP2 )|(0<<WDP1)|(1<<WDP0); // Set Watchdog Timeout period to 4.0 sec.

/* Enable Power Down Sleep Mode */
MCUCR |= (1<<SM1) | (1<<SE);
}

but comehow the interrupt routine is not getting called at all... Pelase help me... bit urgent..

-PM

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As pointed out above, leaving

wdt_reset(); 

in the while routine will keep the WDT from getting called. Comment it out and the WDT should trigger. I think - I don't use GCC).

BTW - I'm not an expert, but I don't see where you are 'putting the AVR to sleep'. Does sleep_enable() do that? - if so it would seem that your while loop operates rather strangely .. at least to me. The function call within the While would never get called, at least until after the WDT triggered. Doesn't a wdt reset NOT execute a rti at the end, and instead return to program main start??

And SOME compilers automatically sprinkle 'wdt_reset' calls throughout the code unless you specifically tell it not to.
Steve

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

And SOME compilers automatically sprinkle 'wdt_reset' calls throughout the code unless you specifically tell it not to.

OK, I'll bite--could you list these SOME compilers that "put words into your mouth"? [that would pretty much defeat the purpose of using the watchdog]

Lee

You can put lipstick on a pig, but it is still a pig.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm well aware of that well-defined situation--note that it was my post. I'm looking for "sprinkle" examples.

Lee

You can put lipstick on a pig, but it is still a pig.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
note that it was my post
That's why it was so 'juicy' (I thought maybe you were losing your memory). I guess delays sprinkled through the code, would be well defined sprinkles, not automatic compiler sprinkles.

I need to find me some Christmas cookies. For some reason.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I need to find me some Christmas cookies. For some reason.

LOL

Using a library routine, that >>you<< choose to use, that has documented behaviour of doing a WDR is enitely different than "compilers automatically sprinkle 'wdt_reset' calls throughout the code unless you specifically tell it not to". I'm asking for an example of that.

You can put lipstick on a pig, but it is still a pig.