Watchdog clock management on Arduino
In electronics and by extension in computing, the watchdog is a resource that allows a physical device or an application to restart when it stops working normally. Specifically, referring to microcontrollers, it is a countdown clock that produces a reset when it overflows.
Logically, the device does not know when it stops working correctly, the principle of operation is to prevent the countdown from ending and therefore the system reset. To do this, first the time interval in which the restart occurs is configured, and secondly this value is refreshed, thus indicating that the device is working correctly and should not be restarted at the moment.
To manage the watchdog with Arduino the library should be used and only three functions: to disable it while configuring the reset time, that configures and activates the watchdog at the time indicated as a parameter (time) and that renews the interval that the watchdog counts.
1
2
3
4
5
6
7
8
9
10
11
12
|
#include <avr/wdt.h> // Incluir la librería que contiene el watchdog (wdt.h)
void setup()
{
wdt_disable(); // Desactivar el watchdog mientras se configura
wdt_enable(WDTO_2S); // Configurar a dos segundos
}
void loop()
{
wdt_reset(); // Actualizar el watchdog para que no produzca un reinicio
}
|
Constants that can be used with
to set the countdown time are:- = 15 milliseconds
- = 30 milliseconds
- = 60 milliseconds
- = 120 milliseconds
- = 250 milliseconds
- = 500 milliseconds
- = 1 second
- = 2 seconds
- = 4 seconds
- = 8 seconds
Before using the watchdog it is important to ensure that the bootloader What does the microcontroller on the board have? Arduino that is being used has provided for the use of this resource. There is a known error in the plates of the Arduino Mega 2560 that were left hanging precisely with programs that used the watchdog.
To learn more about what a bootloader or boot manager and how to record a different one than the one that comes with your plate, you can consult the article on methods for programming Atmel microcontrollers.
Post Comment