STWD100 Watchdog Timer

I am in the process of adding a STWD100 watchdog timer to my photonAlarm project. I have a test device on a breakout board and have it connected to a Photon. The photonAlarm code includes a c++ class hwd, and I have a small test routine which uses this class to test the device.
With a Saleae Logic Analyzer attached to the device pins, I can see that the device is performing
correctly. With a loop time of 1000ms the checkin pulse on WDI keeps the timer reset, and the
WDO reset line remains high. When the loop time is changed to 2000ms, the checkin pulse is late, and the WDO line pulses low to perform a reset. You can see screenshots of the logic analyzer here: on the Watchdog Timer page.
All of the code is in this repository on the Code page.

The STWD100 is connected to the Photon reset line as shown in Fig.4 of ST’s device documentation pdf. On the Main page of my wiki, the circuit show does not include the 10K resistor on the RST line, pulling it HI to vcc. I have tried this both with and without this resistor.

Question / Problem:
My problem is that the the Photon goes into a constant cycle of resets when the device is connected to the reset line. There seems to be some timing issue with getting the Photon to pull the EN line high during startup, and therefore disable the STWD device, until is is properly configured [by hwd.init()], and enabled as a last thing in setup() [by had.enable()].

Has anyone worked with this device? I really like hardware watchdog timers since they provide another independent way of ensuring that the microprocessor and it’s firmware are running properly. I greatly appreciate any help in resolving this issue.
Thanks, Don

Debug Code:
Node: hwd.h and hwd.cpp are available in the code repository.

  Master-Remote alarm system for Particle Photon
  @file     Debug-Alarm-Master.cpp
  @author   D. Thompson
  @license  GNU General Public License (see license.txt)
  @version  3.1.0

  Copyright (C) 2016 Donald Thompson, Raynham Engineering

#include "application.h"
#include "hwd.h"

#define LOOP_DELAY_TIME 1000        //Delay ms between loop passes
#define SYSTEM_STATUS_PIN D2        //RED if Armed, Blinking if any tripped
#define SYSTEM_NOTIFICATION_PIN D3  //GREEN blinks at each loop ??
#define TRIGGER_PIN D4              //debug pin for logic analyzer trigger

int loop_count;

int ledStatus = SYSTEM_STATUS_PIN;            //blink this LED at each loop pass
int ledNotice = SYSTEM_NOTIFICATION_PIN;      //blink this LED at each notification
HWD hwd;

void setup() {
  pinMode(HWD_EN_PIN, OUTPUT);
  digitalWrite(HWD_EN_PIN, HIGH);
  digitalWrite(TRIGGER_PIN, LOW);
  loop_count = 0;
  #ifdef SERIAL_WAIT
    while(!Serial.available())  // Wait here until the user presses ENTER
      Spark.process();          // in the Serial Terminal. Call the BG Tasks;
    Serial.println("Debug initializing...");
    Serial.println("starting watchdog");
    digitalWrite(TRIGGER_PIN, HIGH);


//LOOP IS testing hardware watchdog reset.
//SHOULD reset at arount 2 seconds without checkin
void loop() {
    //wd.checkin() done automatically at end of each loop
    #ifdef SERIAL_DEBUG

Problem Solved!!
The problem was that the STWD EN (enable) connected to D5 in my test code, floats low during Photon startup (reset). The time that this remains low, (low is enabled state of STWD) is too long and the device issues a reset before the startup is complete, thus a constant string of resets.

The fix is to pull the EN line high with a 10K pullup resistor. This holds the line high during Photon reboot and keeps the STWD disabled. In setup(), just before loop() starts, had.enable() sets EN low and start the time. The loop() immediately starts, and the STWD is keep from resetting by calls to had.checkin() every loop. As long as the loop time is less than about 1 sec, all is well. I anything goes wrong in software where the loop hangs and no longer performs checkin(), the STWD will reset the Photon.

See wiki for more detail with some photos of the fix.

This really helped me solve my problem. I had the same behaviour of my Argon and fixed it with a pullup to 3V3.

Did you also experience the device not able to flash? I’m having difficulties keeping the watchdog disabled during a flash.

I tried using system events and used the handler to disable the watchdog, but that did not last during the flash process.

— Fixed!
I altered

 System.on(firmware_update_begin, updateHandler);


 System.on(firmware_update, updateHandler);

should have tried that before posting :sweat_smile:.

I think you’re going to run into a problem with that configuration. I presume you’re pulling /EN high to disable the STWD100. The problem is that when the device resets, all of the pins go into high-impedance mode and thus the watchdog will be reenabled because of its internal pull-down. It will take some time to install the user firmware, and could take a minute or more if a system firmware update is required.

We generally recommend using a hardware watchdog as a method of last resort, with a minimum period of 60 seconds for Wi-Fi and longer for cellular. I usually use a TPL5000 for Wi-Fi devices.

1 Like