6
6
This example demonstrates how to modify the configuration of the Artemis
7
7
Watchdog Timer (WDT).
8
8
9
- The watchdog timer is controlled by a clock divider, interrupt ticks and
9
+ The watchdog timer is controlled by a clock divider, interrupt ticks and
10
10
reset ticks. To achieve desired watchdog timing, a simple calculation can be made:
11
11
12
- period = # ticks / clock divider frequency
12
+ period = # ticks / clock divider frequency
13
13
14
- Examples:
14
+ Examples:
15
15
128 interrupt ticks / 128 Hz clock = 1 second
16
16
64 interrupt ticks / 16 Hz clock = 4 seconds
17
17
32 interrupt ticks / 1 Hz clock = 32 seconds
18
18
16 interrupt ticks / 1/16 Hz clock = 256 seconds
19
-
19
+
20
20
The following code will configure the watchdog for both interrupt and reset
21
21
generation, and immediately start the watchdog timer.
22
22
The watchdog ISR provided will 'pet' the watchdog four times. On the fifth
29
29
Tested with SparkFun Artemis Redboard.
30
30
*/
31
31
32
- #include < WDT.h>
32
+ #include " WDT.h"
33
33
34
34
APM3_WDT wdt;
35
35
@@ -47,17 +47,19 @@ void setup()
47
47
48
48
// Configure the watchdog
49
49
/*
50
- Available watchdog timer clock dividers:
51
- 0 = Low Power Mode. This setting disables the watch dog timer
52
- 1 = 128 Hz
53
- 2 = 16 Hz
54
- 3 = 1 Hz
55
- 4 = 1/16th Hz
50
+ Available watchdog timer clock dividers.
51
+ Users can choose either the clock definition (i.e. WDT_128HZ) or Apoll3 core enumeration (i.e. 1)
52
+ WDT_OFF = 0 = Low Power Mode. This setting disables the watch dog timer
53
+ WDT_128HZ = 1 = 128 Hz
54
+ WDT_16HZ = 2 = 16 Hz
55
+ WDT_1HZ = 3 = 1 Hz
56
+ WDT1_16HZ = 4 = 1/16th Hz
56
57
*/
57
58
// Set watchdog timer clock to 128 Hz
58
59
// Set watchdog interrupt to 1 seconds (128 ticks / 128 Hz = 1 second)
59
60
// Set watchdog reset ~2 seconds (255 ticks / 128 Hz = 1.99 seconds)
60
- wdt.configure (1 , 128 , 255 ); // Note: Ticks are limited to 255 (8-bit)
61
+ // Note: Ticks are limited to 255 (8-bit)
62
+ wdt.configure (WDT_128HZ, 128 , 255 ); // Equivalent to: wdt.configure(1, 128, 255);
61
63
wdt.start (); // Start the watchdog
62
64
}
63
65
@@ -74,9 +76,14 @@ void loop()
74
76
Serial.print (" Period: " ); Serial.print (currentMillis); Serial.println (" ms" );
75
77
76
78
// The watchdog configurations can also be set individually
77
- wdt.setClock (2 ); // Set watchdog timer clock to 16 Hz
79
+ wdt.setClock (WDT_16HZ ); // Set watchdog timer clock to 16 Hz
78
80
wdt.setInterrupt (64 ); // Set watchdog interrupt to 4 second (64 ticks / 16 Hz = 4 seconds)
79
81
wdt.setReset (96 ); // Set watchdog reset to 8 seconds (96 ticks / 16 Hz = 8 seconds)
82
+
83
+ if (watchdogInterrupt == 9 )
84
+ {
85
+ Serial.println (" Warning: Watchdog has triggered a system reset" );
86
+ }
80
87
}
81
88
watchdogFlag = false ; // Clear watchdog flag
82
89
delay (1 );
0 commit comments