2

Arduino quickie: add a watch-dog to your application

Geschrieben von: SES am 03.10.2011 um 19:02 pm

This is a small hint, how to add a watch-dog to your Arduino application.

I’m using the Arduino in 24/7 mode in my weather station. For unknow reason the software sends no data to our host system, it got stucked somewhere. So I added the watch-dog to prevent this.

Adding this functionality is fairly simple.

1. you need to include the wdt.h File:

#include <avr/wdt.h>

2. in the setup routine you add:

wdt_enable(WDTO_2S);

WDT0_2S means, that the time out is 2s. so you have to reset the watch-dog within that period, otherwise it will reset the complete Arduino microcontroller.

other values are also possible: 15 ms, 30 ms, 60 ms, 120 ms, 250 ms, 500 ms, 1 s, 2 s, 4 and 8 s.

3. in the loop routine you add:

wdt_reset(); 

to reset the watch-dog timer within the watch-dog timeout.

see also: http://tushev.org/articles/electronics/48-arduino-and-watchdog-timer for more information.

Ähnliche Artikel:

2 Antworten auf “Arduino quickie: add a watch-dog to your application”

  1. Rainer sagt:

    Nice article but be aware it’s WDTO_xx and not WDT0_xx as typed in here. :)

    Best regards
    Rainer

  2. Sebastian sagt:

    @Rainer:
    thank you Rainer.
    I updated the article. WDT0_xx will cause a compiler error.

    Sebastian

Hinterlasse einen Kommentar