Watchdog timer in Atmegam328p?

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is watchdog timer? Please explain in layman language.

What is the need of it?

How to use it?

I am a begineer in Assembly language. Explain in pure assembly language. No C based code( no use of avr-gcc).

I have gone through the manual. But I am not able to understand it. Totally confused.sad

Raj

Last Edited: Mon. Nov 6, 2017 - 01:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Its a timer you start running that counts down from N to 0. If it reaches 0 the chip resets. You then add code that keeps starting it back at N in your program where you think it is "busy". If the program ever goes off into a long loop you hadn't expected then there'll be no chance to do those "resets to N" so the timer will count on down to 0 and reset the AVR this breaking it out of the unplanned loop.

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

Still not able to implement it. I have not completely  yet understood its working.frown

Raj

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

I googled "wiki watchdog timer"

A watchdog timer (sometimes called a computer operating properly or COP timer, or simply a watchdog) is an electronic timer that is used to detect and recover from computer malfunctions. During normal operation, the computer regularly resets the watchdog timer to prevent it from elapsing, or "timing out". If, due to a hardware fault or program error, the computer fails to reset the watchdog, the timer will elapse and generate a timeout signal. The timeout signal is used to initiate corrective action or actions. The corrective actions typically include placing the computer system in a safe state and restoring normal system operation.

 

In the M328p, the watchdog timer has two possible functions, one way it will cause a system reset, this is used in the traditional way listed above.

The second way to use it, is as a normal timer for non critical timing function, such as a periodic wake up source. 

 

See the data sheet for both C and ASM examples of its use.

 

Jim

 

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

Raj666 wrote:
I am a begineer in Assembly language.

Note that it has nothing to do with Assembly language - or any other programming language.

 

It is a well-established, standard feature of (almost?) every microcontroller today.

 

And it's not limited to microcontrollers, or even just computers - the concept is widely applied in many areas.

 

As noted, googling[1] "watchdog timer" should get you plenty of information

 

eg, http://www.ganssle.com/watchdogs...

 

 

[1] other search engines are available.

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

awneil wrote:
As noted, googling[1] "watchdog timer" should get you plenty of information

Isn't there an article about

Raj666 wrote:
What is watchdog timer? Please explain in layman language.

Can't seem to find it.

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

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:
Isn't there an article 

You mean one specifically about the AVR's watchdog? On this site?

 

The linked Ganssle article should answer the OP's general question, "What is watchdog timer?"

 

EDIT

 

Actually, two questions:

 

  • What is watchdog timer?
  • What is the need of it?
Last Edited: Mon. Nov 6, 2017 - 03:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Raj666 wrote:
I have not completely  yet understood its working.

Think of it as an "egg timer" - the ones used in kitchens.

 

It is a counding down trimer. It is wound up to a certain time and starts ticking towards zero. If not wound up periodically it will eventually reach zero and sound the alarm.

 

The WDT is similar, but rather than sounding the alarm, it resets the AVR so that the application starts "from scratch".

 

The job of the application is to prove that it is still "alive" (e.g. not "hanging" in some endless loop) by periodically "winding the WDT up" again. This is done by the programmer inserting "watch dog timer reset" instructions at strategic places in the application code (the assembler instruction is wdr).

 

If the WDT reaches zero this means that it has not been "wound up" regularly, and the assumption is that the application is not "responsive", hanging and not working reliably anymore.

 

The WDT can be configured to reset the AVR in that configuration.

 

To conclude: The WDT is a piece of hardware to ensure that the software is working with some degree of integrity (i.e. not hanging).

 


 

What is the use of the WDT?

 

Example: 

 

Imagine an AVR that is controlling something critical, e.g. that an oven temperature does not exceed a safe value. It does so by reading a temperature and turn off the heat if it exceeds the safe value.

 

If, by a fault in the software, the application would "hang" so that it does not continually read temperature and possibly turn off heat, then the temperature in the oven would continue rising above the safe value. It could have catastrophic consequences.

 

By using the watchdog timer the "hanging" state of the application will cause the AVR to reset, and the program restarts from scratch. It thus comes out of the "hang" situation and can continue regulating the temperature in the oven.

 


 

Raj666 wrote:
Still not able to implement it.

Show us what you've tried, then...

 


 

If you don't understand what the WDT does, and don't know how to use it, why are you so eager to program for it?

 

Is this a school assignment, by any chance?

 

Could you also tell what is wrong with the example in the data sheet? (You have read the WDT section in the data sheet, right?)

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Mon. Nov 6, 2017 - 05:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
why are you so eager to program for it?
+10

 

I'm always intrigued by threads like this "don't know what it is by I want/must use it!".

 

Anyway as OP needs to know how to use it in Asm I would suggest www.avrbeginners.net is a good place to start. Perhaps no surprise that it has a couple of pages about WDT too:

 

http://www.avrbeginners.net/arch...

http://www.avrbeginners.net/arch...

 

the latter is presumably everything required?

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

awneil wrote:
And it's not limited to microcontrollers, or even just computers - the concept is widely applied in many areas.

 

Are you familiar with the concept of the Dead Man's Handle (or "switch" or whatever) - as found, for example, on railway locomotives?

 

Image result for Dead Man's Handle

 

The Watchdog allows you to implement a kind of Dead Man's (sotware's?) Switch for your code ...

 

 

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

Following 'awneil's link above it will be revealed that there (of-course) is a separate Wikipedia article on "Watchdog timer". That might serve as an explanation "in laymans terms".

 

https://en.wikipedia.org/wiki/Wa...

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

ok i GOT IT

Raj