Enable AVR watchdog timer

This commit is contained in:
Josh Stewart 2017-01-11 17:31:23 +11:00
parent 1b27436ed8
commit 83114b4c76
1 changed files with 11 additions and 0 deletions

View File

@ -14,6 +14,10 @@ Timers are typically low resolution (Compared to Schedulers), with maximum frequ
#include "globals.h"
#include "sensors.h"
#if defined(CORE_AVR)
#include <avr/wdt.h>
#endif
void initialiseTimers()
{
#if defined(CORE_AVR) //AVR chips use the ISR for this
@ -26,6 +30,10 @@ void initialiseTimers()
/* Now configure the prescaler to CPU clock divided by 128 = 125Khz */
TCCR2B |= (1<<CS22) | (1<<CS20); // Set bits
TCCR2B &= ~(1<<CS21); // Clear bit
//Enable the watchdog timer for 2 second resets (Good reference: https://tushev.org/articles/arduino/5/arduino-and-watchdog-timer)
wdt_enable(WDTO_2S);
#elif defined (CORE_TEENSY)
//Uses the PIT timer on Teensy.
lowResTimer.begin(oneMSInterval, 1000);
@ -74,6 +82,9 @@ unsigned long targetTachoPulseTime;
if (loop250ms == 250)
{
loop250ms = 0; //Reset Counter.
#if defined(CORE_AVR)
wdt_reset(); //Reset watchdog timer
#endif
}
//Loop executed every 1 second (1ms x 1000 = 1000ms)