Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Watchdog Timer missing!

  1. #1
    Junior Member
    Join Date
    Sep 2015
    Posts
    3

    Watchdog Timer missing!

    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.
    }

  2. #2
    Senior Member Constantin's Avatar
    Join Date
    Nov 2012
    Location
    In the yard with a 17' Dia. Ferris Wheel
    Posts
    1,408
    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 by Constantin; 09-23-2015 at 06:34 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •