Watchdog Timer missing!

Status
Not open for further replies.

SnowySpark

New member
I'm attempting to use a watchdog on my Teensy so that if it does crash it automatically restarts itself. This is the code example that I have been trying to use. I keep getting the error wdt_reset() not defined in scope but when I search my arduino IDE install (version 1.6.5) there are three versions of the wdt.h so I don't understand why it can't find the definition. In addition I also get the error message that there should be a constructor before the ISR definition so i tried using void and then it complains that WDT_vect has not been declared in scope. I think my IDE can't be finding the header files. Help would be much appreciated.

Code:
/*
Watchdog Timer Basic Example
10 June 2011
Nicolas Larsen
*/
#include <avr/wdt.h>
int loop_count = 0;

//-----------------------DEFINITION OF SETUP---------------------

void setup()
{
  Serial.begin(9600);
  Serial.println("Starting up...");
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  delay (500);
  watchdogSetup();
}

//---------------------DEFINITION OF WATCHDOG--------------------

void watchdogSetup(void)
{
  cli(); # # // disable all interrupts
  wdt_reset(); # // reset the WDT timer
  /*
  WDTCSR configuration:
  WDIE = 1: Interrupt Enable
  WDE = 1 :Reset Enable
  WDP3 = 0 :For 2000ms Time-out
  WDP2 = 1 :For 2000ms Time-out
  WDP1 = 1 :For 2000ms Time-out
  WDP0 = 1 :For 2000ms Time-out
  */
  // Enter Watchdog Configuration mode:
  WDTCSR |= (1 << WDCE) | (1 << WDE);
  // Set Watchdog settings:
  WDTCSR = (1 << WDIE) | (1 << WDE) | (0 << WDP3) | (1 << WDP2) | (1 << WDP1) | (1 << WDP0);
  sei();  //reenable all interrupts

}

//-----------------------DEFINITION OF LOOP_---------------------

void loop()
{
  for (int i = 0; i <= loop_count; i++) {
    digitalWrite(13, HIGH);
    delay(100);
    digitalWrite(13, LOW);

    delay(100);
  }
  loop_count++;
  wdt_reset();
  Serial.print(loop_count);
  Serial.print(". Watchdog fed in approx. ");
  Serial.print(loop_count * 200);
  Serial.println(" milliseconds.");
}

//---------------------DEFINITION OF INTERRUPT ROUTINE-------------------
ISR(WDT_vect) // Watchdog timer interrupt.
{
  // Include your code here - be careful not to use functions they may cause the interrupt to hang and
  // prevent a reset.
}
 
Not clear is whether your issue is with a series 2 teensy (ie AVR based) or Teensy 3 or LC. The latter run on ARM MCUs and though Paul has tried to port a number of AVRisms to make the ARM based products more compatible, compatibility is not 100%. Your watchdog code seems to presume a AVR processor. For an example of how to run it on a ARM-based Teensy, see here.

What Teensy are you trying to run this on?
 
Last edited:
Status
Not open for further replies.
Back
Top