Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

WDT in Atmega16 Settings

Status
Not open for further replies.

Wafeeq

Member level 3
Joined
Jul 26, 2010
Messages
61
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Pakistan
Activity points
1,728
Hi All
i want to use watch dog timer in atmega16. please help me how to set it also i want to know its working procedure. i am using 1MHz internal crystal.
 

The Watchdog Timer is clocked from a separate On-chip Oscillator which runs at 1 MHz
In the codewizard you can set the clock prescaler (division factor) of the watchdog in the tab with the timers, it is the last tab, you get a code like

Code:
// Watchdog Timer initialization
// Watchdog Timer Prescaler: OSC/32k
#pragma optsize-
WDTCR=0x19;
WDTCR=0x09;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

Then you need to call #asm("wdr") from your code to reset the watchdog periodically
There is a table in page 33 of the datasheet http://www.atmel.com/atmel/acrobat/doc2466.pdf
that explains the timeout period depending on the division factor

Alex
 

IS THE MAIN FUNCTION OF WDT IS THAT WHEN CONTROLLER HANG OR STOPPED IS THE WDT RESET THE CONTROLLER , WHEN I USE WDT THE MICRO CONTROLLER RESTART FOR EVER FOR THAT YOU USE #asm("wdr") BUT WHAT THIS INSTUCATION MEAN
 

First of all don't use capital letters because it is the equivalent of shouting...

Yes the purpose of the watchdog is to restart the code execution (reser mcu) if something happens and the code execution stuck in some point.
In normal operation you reset the watchdog timer before the time-out, the #asm("wdr") resets the watchdog counter and restarts the count.

Alex
 
sorry for shouting:),
in my opinion, i think the best way to use WDT is to use it with interrupt overflow for any timer(0 or 1) and adjust the timer to time smaller than the WDT and in interrupt #asm("wdr") to resets the watchdog counter because in large code you need to #asm("wdr") forever
 

And how will you overcome the case where something is wrong in the main loop of the application and the code stucks in a specific line?
You will still get the timer interrupts , you will execute the watchdog reset and then return to the same stucked line without any chance to get out of this situation.

Alex
 

in your opinion what is the the best method to use WDT ? is the best to use external WDT but i think that if the system hang but the WDT reset in this case it not work as we need and the system will not restart in this bag
 

I haven't made any critical design that needed a watchdog but the only place I consider proper is within the main loop, not an interrupt.
The execution times of the loop have to be strict and calculated so that you can set the watchdog according to the max expected execution time, if this execution time frame is exceed then the mcu will be reset by the watchdog.

Alex
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top