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
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
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.
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.
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.