[AVR]Best place to place Watchdog Timer Reset

zohair wrote on Monday, July 23, 2007:

I’m working on an ATMega32 and am trying to add a watchdog timer to the project.

I wanna know, what would be the best place to place the timer reset command. Since FreeRTOS uses multi-threading, I guess threads would continue to operate even if one of them hung up. I’m guessing I’ll need to create a task to occasionally reset the Watchdog, but what should I set the priority to?

Since we’re on the topic, how many tasks can I create on my system?

rtel wrote on Monday, July 23, 2007:

The number of tasks you can create is dependent on the amount of RAM available and the size of the stack allocated to each task.

There is no simple answer to your watchdog question.  It depends on how secure you want it to be.  There are lots of papers available on watchdog design, it can get quite an academic subject.  One approach is to have each task perform some form of self check and send a message to a watchdog task.  The watchdog task then needs to run within a time window, and receive "I am ok" messages from all the other tasks before it kicks the dog.


zohair wrote on Monday, July 23, 2007:

I’m guessing the number of tasks isn’t simply (Available RAM / configMINIMAL_STACK_SIZE), right?

I was thinking of a simple watchdog and kick it at the lowest priority. That way if any higher priority task hangs, we get a reset. Any possible problems with this?

adarkar9 wrote on Monday, July 23, 2007:

That depends on the type of "hang".  A higher priority task can "hang" by blocking on a resource that will not become available for whatever reason.  The higher priority task will be left blocked and the lower priority watchdog reset task will be allowed to run.  The watchdog will continue to operate even though a higher priority task is stuck.  It is due to this kind of interaction that watchdog design can become an "academic subject" as Richard said.

Your simple watchdog will detect some failures, and maybe that is good enough for you.  It is not fool-proof, however.