« Close

Datasheets and User Guides

App Notes

Software & Driver


4.3.13 - Watchdog Timer

The U3 (hardware version 1.21+ only) has firmware based watchdog capability. Unattended systems requiring maximum up-time might use this capability to reset the U3 or the entire system. When any of the options are enabled, an internal timer is enabled which resets on any incoming USB communication. If this timer reaches the defined TimeoutPeriod before being reset, the specified actions will occur. Note that while streaming, data is only going out, so some other command will have to be called periodically to reset the watchdog timer.

Timeout of the watchdog on the U3 can be specified to cause a device reset, update the state of 1 digital I/O (must be configured as output by user), or both.

Typical usage of the watchdog is to configure the reset defaults (condition of digital I/O and analog outputs) as desired (use the “config defaults” option in LJControlPanel V2.26+), and then use the watchdog simply to reset the device on timeout. For initial testing, “config defaults” in LJCP can be used to enable the watchdog all the time, but often it is desirable to enable/disable the watchdog in user software so it is only active while that software is running.

Note that some USB hubs do not like to have any USB device repeatedly reset. With such hubs, the operating system will quit reenumerating the device on reset and the computer will have to be rebooted, so avoid excessive resets with hubs that seem to have this problem.

If the watchdog is accidentally configured to reset the processor with a very low timeout period (such as 1 second), it could be difficult to establish any communication with the device. In such a case, the reset-to-default jumper can be used to turn off the watchdog. Power up the U3 with a jumper securely installed from FIO6 to SPC (FIO2 to SCL on U3 1.20/1.21), then remove the jumper and power cycle the device again. This resets all power-up settings to factory default values.

There is one IOType used to configure and control the watchdog:

LJ_ioSWDT_CONFIG  // Channel is enable or disable constant.

The watchdog settings are stored in non-volatile flash memory (and reloaded at reset), so every request with this IOType causes a flash erase/write. The flash has a rated endurance of at least 20000 writes, which is plenty for reasonable operation, but if this IOType is called in a high-speed loop the flash could be damaged.

The following are special channels used with the watchdog config IOType above:

LJ_chSWDT_ENABLE  // Value is timeout in seconds (3-65535).

The following are special channels, used with the put config IOType, to configure watchdog options. These parameters cause settings to be updated in the driver only. The settings are not actually sent to the hardware until the LJ_ioSWDT_CONFIG IOType (above) is used:


Following is example pseudocode to configure and enable the watchdog:

//Initialize EIO2 to output-low, which also forces the direction to output.
//It would probably be better to do this by configuring the power-up defaults.
AddRequest(lngHandle, LJ_ioPUT_DIGITAL_BIT, 10,0,0,0);

//Specify that the device should be reset on timeout.
AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSWDT_RESET_DEVICE,1,0,0);

//Specify that the state of the digital line should be updated on timeout.
AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSWDT_UDPATE_DIOA,1,0,0);

//Specify that EIO2 is the desired digital line.
AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSWDT_DIOA_CHANNEL,10,0,0);

//Specify that the digital line should be set high.
AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSWDT_DIOA_STATE,1,0,0);

//Enable the watchdog with a 60 second timeout.
AddRequest(lngHandle, LJ_ioSWDT_CONFIG, LJ_chSWDT_ENABLE,60,0,0);

//Execute the requests.

Following is pseudocode to disable the watchdog:

//Disable the watchdog.
ePut(lngHandle, LJ_ioSWDT_CONFIG, LJ_chSWDT_DISABLE,0,0);


Hello, i'm streaming data with the options LJ_chSTREAM_SCAN_FREQUENCY, eGet_ByRef(lngHandle, LJ_ioGET_STREAM_DATA....., eGet(lngHandle, LJ_ioGET_CONFIG, LJ_chSTREAM_BACKLOG_COMM...and so on about every 400ms.

You write:note that while streaming, data is only going out, so some other command will have to be called periodically to reset the watchdog timer.

Which command can i while streaming reset the wd timer or a digital-io on labjack u3? Can you give me a sample in VB6? thx

You can do about any command/response call.  How about just doing a call to eDI which reads 1 digital input.  See the VB6 U3_EFunctions example which makes a call to this function.  You can just call it after each read of stream data, assuming that happens more often than the watchdog timeout you have configured.


My question is: does setting the watchdog on or off write to the flash. If so does it count towards the ~20,000 write limits to the flash before it is damaged?

I have several U3's. I am using the watchdog for safety when I have a laser on. If the software crashes or the usb cable is uplugged the watchdog will kick in and set the default outputs which will turn the laser off.

Every time I turn the laser on I enable the watchdog and every time I turn the laser off I disable the watchdog.

I use the commands






Changing the watchdog's settings does write to flash and does count toward the 20k limit. And the settings are loaded each time the device resets or powers up. It seems OK to me to leave the watchdog on all the time. That will leave the fail safe on except when you program is up and running. You program will need to expect IO lines to be in the safe states and change them as necessary.