3
\$\begingroup\$

This is what I understand: There is a main loop in the code who's time of execution is say, n ms. Now, the developer needs to configure the watchdog timer for such a time m ms where m < n. This will make sure that none of the function block. If at all the code is stuck somewhere in the for time t, where t > m, the control will perform watchdog reset. Do I understand it well?

\$\endgroup\$

2 Answers 2

7
\$\begingroup\$

Technically, watchdog timer has nothing to do with main loop.

It is just a timer that will reset MCU if it is not restarted in time itself. You can do the restart in the main loop, of course. But you can also use it to monitor any other periodic activity, assuming that the absence of the activity updates justifies the reset of MCU.

Sometimes software watchdog implementations can be useful as well, allowing you to monitor multiple processes and choose the mitigation actions depending on a problem. For example if you have master device collecting data from some sensors you can set up watchdogs with restart on receiving incoming data packet. Resetting just communication periphery hardware may be more sensible approach in this case.

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

Now, the developer needs to configure the watchdog timer for such a time m ms where m < n.

No, it must be m > n.

If the WDT (Watchdog Timer) will be watching the entire main loop then m (WDT counter/timer) must be greater than n (main loop execution time) otherwise there are going to be unwanted resets. However, it's still possible to use the WDT for inner loop(s). In those cases, of course, m can be smaller than n.

The thing is, if the WDT is set up it must be reset. This must be done once the loop is completed. That'll be an indication of proper operation.

If the time of execution of a program is, say, 1 ms at maximum and the WDT is set up for, say, 2 ms then the WDT should not perform a reset during normal operation. But if the program stalls/hangs for some reason and therefore fails to reset the WDT then the WDT's counter will reach 2 ms and perform a reset.

\$\endgroup\$
5
  • \$\begingroup\$ Oh, OK. So you're saying that the value of the timer of the Watchdog timer should ALWAYS be greater than main loop's execution time, correct? \$\endgroup\$ Commented May 21 at 8:19
  • 1
    \$\begingroup\$ @user23335133 Correct ... except for the time when the main program wants to test the correct operation of the WDT. \$\endgroup\$
    – Neil_UK
    Commented May 21 at 8:29
  • 1
    \$\begingroup\$ Or when the watchdog is a windowed variant. Then the reset time needs to be both longer than the lower window limit and shorter than the upper limit. \$\endgroup\$
    – MrGerber
    Commented May 21 at 8:47
  • 1
    \$\begingroup\$ There's no fundamental reason that m must be greater than n. If it's less, you simply need multiple resets per pass through the main loop -- which can be a good thing if you need faster response to a freeze. \$\endgroup\$
    – Mark
    Commented May 22 at 1:18
  • \$\begingroup\$ @user23335133 actually, unless you set up the WDT for an inner loop (i.e. a smaller) WDT period must be greater than the execution time of the main loop. I'm updating my answer accordingly. \$\endgroup\$ Commented May 22 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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