Watchdog timer and audio SGTL5000

Status
Not open for further replies.

Stanleyvc

Active member
The watchdog timer works well on my Teensy 3.6
But after a sound play, the watchdog reset somtimes.

what is heppents
Thanks
 
I believe you can feed the watchdog every quarter of the total time, if your feeding it too fast you could also cause a WTG reset

interrupts must be disabled as well when feeding

This code feeds it

Code:
  __disable_irq();
  WDOG_REFRESH = 0xA602;
  WDOG_REFRESH = 0xB480; 
  __enable_irq();
 
I have this function for reset the watchdog.

void reset_watchdog() {
noInterrupts();
WDOG_REFRESH = 0xA602;
WDOG_REFRESH = 0xB480;
interrupts();
}
 
This is the watchdog start function:

void start_watchdog() {
Serial.println("Start WatchDog!");
noInterrupts();
WDOG_UNLOCK = WDOG_UNLOCK_SEQ1;
WDOG_UNLOCK = WDOG_UNLOCK_SEQ2;
delayMicroseconds(1); // Need to wait a bit..

WDOG_STCTRLH = 0x0001; // Enable WDG
WDOG_TOVALH = 1;//0x166d;
WDOG_TOVALL = 30;
WDOG_PRESC = 30;//0x400;

WDOG_STCTRLH |= WDOG_STCTRLH_ALLOWUPDATE |
WDOG_STCTRLH_WDOGEN | WDOG_STCTRLH_WAITEN |
WDOG_STCTRLH_STOPEN | WDOG_STCTRLH_CLKSRC;

interrupts();
}

And this is the watchdog reset function:

unsigned long wdt_millis = 0;
void reset_watchdog() {
if ((millis() - wdt_millis) > 1000) {
wdt_millis = millis();
noInterrupts();
WDOG_REFRESH = 0xA602;
WDOG_REFRESH = 0xB480;
interrupts();
}
}

I have a test routine, after 64633 millis, the Teensy 3.6 have a watchdog reset.
Somtimes after a sdplay, the sound file is 6 seconds, the Teensy have a watchdog reset.
 
Hmmm, I didn't test, but your WDOG config looks suspicious.

1) WDOG_PRESC needs to set the lower 3 bits of the upper byte of the register, so your 30 is meaningless, prescale is 0 (no prescale)

2) you have selected WDOG_STCTRLH_CLKSRC as clock source, e.g., F_BUS (60 mhz for T3.6)

3) your timeout value is 65566 ticks, so @60mhz that's about 1 ms ??

if you omit WDOG_STCTRLH_CLKSRC, WDOG will use LPO at 1khz (10% accuracy)

for your amusement, here is a sketch that will test the WDOG using either F_BUS or LPO
Code:
// duff from https://forum.pjrc.com/threads/25370-Teensy-3-0-Watchdog-Timer
//  LPO @1khz 10% err,  4s WDOT timer
#define PRREG(x) Serial.print(#x" 0x"); Serial.println(x,HEX)

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(100);
  digitalWrite(LED_BUILTIN, LOW);
  // You have about 4 secs to open the serial monitor before a watchdog reset
  while (!Serial);
  delay(100);
  printResetType();
  KickDog();
  PRREG(WDOG_STCTRLH);
  PRREG(WDOG_PRESC);
  PRREG(WDOG_TOVALL);
  PRREG(WDOG_TOVALH);
  PRREG(WDOG_RSTCNT);
  for (int i = 1; i <= 5; i++) {
    Serial.print("loop "); Serial.println(i);
    KickDog();
    delay(1000);
  }
  Serial.println("long delay reset");
  delay(5000);
}

void loop() {
  Serial.println("never gets here ...");
  delay(3000);
}

void KickDog() {
  Serial.println("Kicking the dog!");
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  noInterrupts();
  WDOG_REFRESH = 0xA602;
  WDOG_REFRESH = 0xB480;
  interrupts();
}

void printResetType() {
  if (RCM_SRS1 & RCM_SRS1_SACKERR)   Serial.println("[RCM_SRS1] - Stop Mode Acknowledge Error Reset");
  if (RCM_SRS1 & RCM_SRS1_MDM_AP)    Serial.println("[RCM_SRS1] - MDM-AP Reset");
  if (RCM_SRS1 & RCM_SRS1_SW)        Serial.println("[RCM_SRS1] - Software Reset");
  if (RCM_SRS1 & RCM_SRS1_LOCKUP)    Serial.println("[RCM_SRS1] - Core Lockup Event Reset");
  if (RCM_SRS0 & RCM_SRS0_POR)       Serial.println("[RCM_SRS0] - Power-on Reset");
  if (RCM_SRS0 & RCM_SRS0_PIN)       Serial.println("[RCM_SRS0] - External Pin Reset");
  if (RCM_SRS0 & RCM_SRS0_WDOG)      Serial.println("[RCM_SRS0] - Watchdog(COP) Reset");
  if (RCM_SRS0 & RCM_SRS0_LOC)       Serial.println("[RCM_SRS0] - Loss of External Clock Reset");
  if (RCM_SRS0 & RCM_SRS0_LOL)       Serial.println("[RCM_SRS0] - Loss of Lock in PLL Reset");
  if (RCM_SRS0 & RCM_SRS0_LVD)       Serial.println("[RCM_SRS0] - Low-voltage Detect Reset");
}

#ifdef __cplusplus
extern "C" {
void startup_early_hook();
}
extern "C" {
#endif
  void startup_early_hook() {
#if 1
    // clock source 0 LPO 1khz, 4 s timeout
    WDOG_TOVALL = 4000; // The next 2 lines sets the time-out value. This is the value that the watchdog timer compare itself to.
    WDOG_TOVALH = 0;
    WDOG_STCTRLH = (WDOG_STCTRLH_ALLOWUPDATE | WDOG_STCTRLH_WDOGEN | WDOG_STCTRLH_WAITEN | WDOG_STCTRLH_STOPEN); // Enable WDG
#else
    // bus clock  4s timeout
    uint32_t ticks = 4000 * (F_BUS / 1000); // ms
    WDOG_TOVALL = ticks & 0xffff; // The next 2 lines sets the time-out value. This is the value that the watchdog timer compare itself to.
    WDOG_TOVALH = (ticks >> 16) & 0xffff;
    WDOG_STCTRLH = (WDOG_STCTRLH_ALLOWUPDATE | WDOG_STCTRLH_CLKSRC | WDOG_STCTRLH_WDOGEN | WDOG_STCTRLH_WAITEN | WDOG_STCTRLH_STOPEN);
#endif
    WDOG_PRESC = 0; // prescaler
  }
#ifdef __cplusplus
}
#endif

and there is https://github.com/adafruit/Adafruit_SleepyDog

earlier thread https://forum.pjrc.com/threads/25370-Teensy-3-0-Watchdog-Timer
 
Last edited:
Status
Not open for further replies.
Back
Top