1
\$\begingroup\$

I have read that watchdog timer pushes microprocessor/controller into reset state whenever it experiences any software anomaly like executing in infinite loop. and after some time a very senior prof told us that after reset the processor resumes operation from the next instruction to the erroneous one.

when watchdog timer resets the processor, from where does the processor start its next execution?

I just wanted to know what is correct or if some other concept is employed?

\$\endgroup\$
4
\$\begingroup\$

It is really down to the designer of the microcontroller. But, in general, a watchdog forces a reset of the processor and typically starts the program from the beginning. It is not always that way though, and the watchdog can also often be used to trigger an interrupt, in which case yes the ISR would return to where it was interrupted with the next instruction to execute.

For instance, a common way to force a software reboot of a chip that doesn't have a reset instruction is to enable the watchdog, then go into a "while(1)" loop, so the watchdog reboots the chip.

The watchdog's interrupt facility is often also used for waking up a microcontroller that has been put to sleep, as most will tick away with their own oscillator. This means the main oscillator can be shut down to conserve power, and the watchdog can then trigger an interrupt that wakes the chip up again.

\$\endgroup\$
3
  • \$\begingroup\$ thanks Majenko, that makes a lot of sense, would you be able to give any example of a controller which implements the interrupt design..? \$\endgroup\$ Jul 13 '14 at 14:06
  • \$\begingroup\$ Most of them do I think. Take a look at the data sheet for your favourite one. \$\endgroup\$
    – Majenko
    Jul 13 '14 at 14:08
  • \$\begingroup\$ @Himu: it doesn't even need to be a dedicated peripheral of the MCU. Technically, you can even use some of the MCU timers and wire it externally to the reset pin. This Wikipedia article has some pretty good information on WDTs. \$\endgroup\$
    – Evan
    Jul 13 '14 at 14:20
3
\$\begingroup\$

Your very senior professor is full of you-know-what. What happens after a WDT reset is (generally) that the processor restarts from where it would start after any hard reset.

The information that a WDT timeout caused the reset is often available (in the form of a bit or bits in a register), and the firmware may treat such a reset differently from a cold start, but in general there is no way to know what instruction was being executed before the WDT timed out, and you would not want to go there anyway. It could be executing data memory or stuck in an infinite loop of some other kind. You do not want to go back there, the WDT is what gets you out of that situation.

You would normally want to do the sort of clean-up and initialization that would take place during a cold start, and make sure that things are in a safe state, and possibly log the event. There is no telling what the processor might have been up to before the WDT reset- it could have corrupted RAM or EEPROM, stuck outputs into unsafe states, re-written port direction controls or clock control registers or just about anything else. That's the reason why it's usually difficult or impossible to disable a WDT with firmware on well-designed processors- you don't want an errant processor to accidentally disable its own WDT.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ thanks Sphero,refreshed and made my concepts more clear :) \$\endgroup\$ Jul 13 '14 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.