How to use Arduino WatchDog
Step1. Include Library
#include <avr/wdt.h>
Step2. Enable it
wdt_enable (WDTO_1S);//Put this in setup
You can change the times .
The times list.
Threshold
value
|
Constant
name
|
Supported on
|
15 ms
|
WDTO_15MS
|
ATMega 8,
168, 328, 1280, 2560
|
30 ms
|
WDTO_30MS
|
ATMega 8,
168, 328, 1280, 2560
|
60 ms
|
WDTO_60MS
|
ATMega 8,
168, 328, 1280, 2560
|
120 ms
|
WDTO_120MS
|
ATMega 8,
168, 328, 1280, 2560
|
250 ms
|
WDTO_250MS
|
ATMega 8,
168, 328, 1280, 2560
|
500 ms
|
WDTO_500MS
|
ATMega 8,
168, 328, 1280, 2560
|
1 s
|
WDTO_1S
|
ATMega 8,
168, 328, 1280, 2560
|
2 s
|
WDTO_2S
|
ATMega 8,
168, 328, 1280, 2560
|
4 s
|
WDTO_4S
|
ATMega 168,
328, 1280, 2560
|
8 s
|
WDTO_8S
|
ATMega 168,
328, 1280, 2560
|
Step3. Rember reset it in the limit
times.
Like this example.
#include <avr/wdt.h>
void setup() {
Serial.begin(9600);
wdt_enable(WDTO_4S);
Serial.println("restart");
}
void loop() {
Serial.println("First");
delay(1000);
wdt_reset();
}
|
Step4. Upload and test it.
沒有留言:
發佈留言