0

suppose a project with Arduino that we should save battery power, so we use sleep mode and also avoiding the Arduino of hanging and use watchdog timer. But the problem is here that when the Arduino goes to sleep the watchdog timer never(or cant be) reset again because of sleep and it will overflow over and over and reset the Arduino over and over. so what do you suggest to solve this problem, I mean running sleep mode and watchdog timer at the same time in a code?

  • 1
    Please show us the sketch you're using. – VE7JRO Mar 17 at 19:59
0

When you sleep the Arduino is locked up. So yes, the watchdog timer will time out and reset the Arduino.

But, since you're in sleep mode, it's not so much a "reboot" as a "wakeup".

The watchdog timer is one of the normal ways of waking up periodically to do things. If you want to use the watchdog for its other "anti-lockup" purpose then you will have to arrange some other way of waking up before the watchdog is due to expire so you can "kick" it.

Or you disable the watchdog entirely before going to sleep so that the only wakeup source is whatever source you have configured. Then you can turn the watchdog on again when you wake up.

However that probably means that the watchdog is useless, since chances are you won't be awake for long enough periods for the watchdog to have any effect.

Sleeping and using the internal watchdog as a watchdog are pretty much mutually exclusive. If you sleep, then the watchdog is a periodic wake-up source.

| improve this answer | |
  • If you set the arduino to sleep while the watchdog is running, the arduino will reset after the set amount of time. Unless you set the watchdog to trigger an interrupt. The watchdog isn't a wake-up source, unless you set it up as one. Also note that the watchdog unsets the interrupt when triggered. This is so that, if the program hangs, the first timeout it will call the interrupt, and the second timeout will cause a reset. – Gerben Mar 18 at 13:20
0

Either set the watchdog to 8s, and setup the WDT interrupt. And deal with the fact that the MCU wakes up every 8s. You could have it go back to sleep, unless a button is pressed, or something. The extra power usage for these short wakeups is negligible in most cases.

Or disable the watchdog right before sleeping, and enable right after waking up. And hope the MCU never hangs in between.

| improve this answer | |
  • the periodically reset(or reboot) doesn't hurt the MCU? – sepehr Mar 19 at 16:36
  • No. Won't hurt the MCU. – Gerben Mar 21 at 16:14

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.