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
fstelwagen
PostPosted: Feb 15, 2012 - 02:55 PM
Newbie


Joined: Feb 24, 2011
Posts: 2


Hey guys,

I have a question.

I am trying to implement a watch dog timer with the example codes in AVR1310. But for some reason I cannot set de WDT.CTRL register. I can see that variable “temp” contains value 0x1F. Here is the code:

void WDT_EnableAndSetTimeout( WDT_PER_t period )
{
uint8_t temp = WDT_ENABLE_bm | WDT_CEN_bm | period;
CCP = CCP_IOREG_gc;
WDT.CTRL = temp;

/* Wait for WD to synchronize with new settings. */
while(WDT_IsSyncBusy()){

}
}


Any ideas?

Thanks in advance, Frank.
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: Feb 15, 2012 - 02:59 PM
Moderator


Joined: Jan 23, 2004
Posts: 9826
Location: Trondheim, Norway

What does the resulting assembly look like? You need to write to WDT.CTRL within 4 clock cycles of setting CCP, which that code will probably violate depending on the optimization settings selected and the exact code sequence generated by the compiler.

- Dean Twisted Evil

_________________
Atmel Studio 6.1 is now released, grab it here.
Report AS6/ASF bugs here.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
fstelwagen
PostPosted: Feb 15, 2012 - 03:45 PM
Newbie


Joined: Feb 24, 2011
Posts: 2


Hey Dean,

Thanks for your fast response!
You were right. The resulting assembly revealed that it took 5 clock cycles. After setting the optimization setting to “optimize most” it took only 2 cycles and the problem was solved!

Thanks a lot!

Cheers, Frank.
 
 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