Teensy 3: enable Watchdog

Status
Not open for further replies.

frank

New member
Hello,

i want to enable a watchdog timer. Is there an description how to enable this? Or is there a way to reboot to my Application via timer interrupt? The reboot code i found here jumps to bootloader.

Frank
 
Hey Peter, I saw your post yesterday just when I was researching about this exact same topic. I spent many hours reading up on docs and trying out code. After I got my code to work I wrote a small test and left it running for 15+ hours now since I will need it for a (literally) mission critical application and I think I can safely say that I got the watchdog to work. Hows progress on your end?
 
In my experience, the hard part of using a watchdog timer is determining the several criteria for the recurring reset-timer (kick the dog). If you miss a case, there's no watchdog to force a recovery.
This is very true in unattended devices that don't have remote access.
An incorrect watchdog reset strategy can lead to an airplane trip to go fix it.
 
Last edited:
I haven't the watchdog really running. I've written a software watchdog using a timer. For reboot i use this routine:

// reboot arduino
void reset_arduino()
{
Serial.println(F("Reset"));
#ifdef WATCHDOG
wdt_enable(WDTO_15MS);
#else
// Teensy 3
#ifndef SCB_AIRCR_SYSRESETREQ_MASK
#define SCB_AIRCR_SYSRESETREQ_MASK ((unsigned int) 0x00000004)
#endif
cli();
delay(100);
SCB_AIRCR = 0x05FA0000 | SCB_AIRCR_SYSRESETREQ_MASK;
while(1);
#endif
delay(1000);
}
 
I'm not sure where you got the wdt_enable function (or most of the stuff in the code you've posted) but this is how I got it to work:

void setup()
{

// the following code should be placed at the end of setup() since the watchdog starts right after this
WDOG_UNLOCK = WDOG_UNLOCK_SEQ1;
WDOG_UNLOCK = WDOG_UNLOCK_SEQ2;
delayMicroseconds(1); // Need to wait a bit..
WDOG_STCTRLH = 0x0001; // Enable WDG
WDOG_TOVALL = 200; // The next 2 lines sets the time-out value. This is the value that the watchdog timer compare itself to.
WDOG_TOVALH = 0;
WDOG_PRESC = 0; // This sets prescale clock so that the watchdog timer ticks at 1kHZ instead of the default 1kHZ/4 = 200 HZ

// ...

}

void loop()
{

// use the following 4 lines to kick the dog
noInterrupts();
WDOG_REFRESH = 0xA602;
WDOG_REFRESH = 0xB480;
interrupts()

// if you don't refresh the watchdog timer before it runs out, the system will be rebooted

delay(1) // the smallest delay needed between each refresh is 1ms. anything faster and it will also reboot.

}

What I'm trying to do now is to implement the watchdog interrupt under Teensyduino without modifying the source code in the library, I will report back with any results.
 
Status
Not open for further replies.
Back
Top