Hi all,
I'm trying to set up a watchdog timer on the teensy but it wont trigger the interrupt for some reason when I get stuck in a loop. Any help would be appreciated.
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 |= WDOG_STCTRLH_ALLOWUPDATE | WDOG_STCTRLH_WDOGEN |
WDOG_STCTRLH_WAITEN | WDOG_STCTRLH_STOPEN | WDOG_STCTRLH_CLKSRC; // Enable WDG
WDOG_TOVALL = 1000; // 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
interrupts();
// ...
}
void loop()
{
// use the following 4 lines to kick the dog
noInterrupts();
WDOG_REFRESH = 0xA602;
WDOG_REFRESH = 0xB480;
interrupts();
do
{
delay(1);
}while(1);
// 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.
}
I'm trying to set up a watchdog timer on the teensy but it wont trigger the interrupt for some reason when I get stuck in a loop. Any help would be appreciated.
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 |= WDOG_STCTRLH_ALLOWUPDATE | WDOG_STCTRLH_WDOGEN |
WDOG_STCTRLH_WAITEN | WDOG_STCTRLH_STOPEN | WDOG_STCTRLH_CLKSRC; // Enable WDG
WDOG_TOVALL = 1000; // 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
interrupts();
// ...
}
void loop()
{
// use the following 4 lines to kick the dog
noInterrupts();
WDOG_REFRESH = 0xA602;
WDOG_REFRESH = 0xB480;
interrupts();
do
{
delay(1);
}while(1);
// 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.
}