Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
pmitruka
PostPosted: Dec 05, 2008 - 11:51 AM
Newbie


Joined: Oct 17, 2008
Posts: 4


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 Sad
 
 View user's profile Send private message  
Reply with quote Back to top
curtvm
PostPosted: Dec 05, 2008 - 12:26 PM
Raving lunatic


Joined: Sep 21, 2005
Posts: 2318


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

Code:
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/


Last edited by curtvm on Dec 05, 2008 - 12:29 PM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
pmitruka
PostPosted: Dec 05, 2008 - 12:28 PM
Newbie


Joined: Oct 17, 2008
Posts: 4


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 Smile
 
 View user's profile Send private message  
Reply with quote Back to top
pmitruka
PostPosted: Dec 05, 2008 - 12:30 PM
Newbie


Joined: Oct 17, 2008
Posts: 4


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
 
 View user's profile Send private message  
Reply with quote Back to top
pmitruka
PostPosted: Dec 08, 2008 - 09:41 AM
Newbie


Joined: Oct 17, 2008
Posts: 4


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(;Wink
{
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
 
 View user's profile Send private message  
Reply with quote Back to top
sadavis80
PostPosted: Dec 08, 2008 - 02:27 PM
Newbie


Joined: Nov 15, 2008
Posts: 14


As pointed out above, leaving
Code:
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
 
 View user's profile Send private message  
Reply with quote Back to top
theusch
PostPosted: Dec 08, 2008 - 02:57 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 28228
Location: Wisconsin USA

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
 
 View user's profile Send private message  
Reply with quote Back to top
curtvm
PostPosted: Dec 08, 2008 - 04:51 PM
Raving lunatic


Joined: Sep 21, 2005
Posts: 2318


Here's one example, I guess-
http://www.avrfreaks.net/index.php?name ... 990#514990
 
 View user's profile Send private message  
Reply with quote Back to top
theusch
PostPosted: Dec 08, 2008 - 05:38 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 28228
Location: Wisconsin USA

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

Lee
 
 View user's profile Send private message  
Reply with quote Back to top
curtvm
PostPosted: Dec 08, 2008 - 06:30 PM
Raving lunatic


Joined: Sep 21, 2005
Posts: 2318


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.
 
 View user's profile Send private message  
Reply with quote Back to top
theusch
PostPosted: Dec 08, 2008 - 06:35 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 28228
Location: Wisconsin USA

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.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits