Quote:
Originally Posted by Cadyyan
I'm currious about how the watchdog actually turns off the robot. I had an idea, not sure if it is already implemented in the library and I just don't know about it, about having the DS display where in the code the watchdog timed out at. I hate having to hunt through code to find watchdog errors when I program blind.
|
The watchdog timer is a hardware device; there's may not even be a dedicated function in the kernel that manages it, because VxWorks can run on many different hardware architectures. While I can't tell you how watchdog is specifically implemented on the cRIOs, I can tell you how they work in general. (For more information, you can also look at the
Wikipedia article or one of
these articles on NI.com)
One of the fundamental hardware devices in a microcontroller is a
hardware timer. The function of such a device is, when told, periodically decrement a number in its internal memory, and then when that number gets to 0, set its output to a high state (output a "1" if you want to think in binary). The processor in the microcontroller is hooked both to control lines for the timer in order to start and stop it and to set the timer's counter value, and to the timer's output line so that the program running can use it like any other digital input (or more commonly the output will be connected to a
hardware interrupt line so that the program is actively notified whenever the counter reaches zero). Timers (also called counters) are used for many things in embedded programming, including generating PWM signals to control motors, control operating system scheduling routines, to regulate transmission rates over communication ports such as
RS232,
I2C, or
SPI, etc.
A watchdog timer is a hardware timer whose output line, instead of being connected to an input to the processor, is instead connected to the processor's reset line. Thus if the timer is allowed to reach 0, it will cause the processor to reset. When you first open the watchdog (Watchdog Open.vi or new Watchdog(); ) it enables the watchdog, meaning the watchdog starts counting down. Whenever you feed the watchdog, you are resetting the counter value to a large enough number. Thus, if the watchdog isn't fed often enough, the timer will reach 0 and the processor will reset, all as hardware functions. Because the watchdog is a hardware device, as [The Lucas] pointed out, it's probably connected through the FPGA, as that seems to be how most hardware devices are connected in the cRIO, but this will be part of NI's proprietary hardware design, so I doubt anyone who knows could tell you.
So basically (as [The Lucas] also pointed out) it's not possible to know where the watchdog timed out because if the watchdog is working properly it will only reset when the code is frozen. The best thing you can do is routinely update the DS's display with some indicator of the last thing that was run in your code, and so when the Watchdog throws the display will be stuck there.
Good luck,
--Ryan
P.S. For a good free open source kernel, check out the
FreeRTOS project.
EDIT: Looks like link to the second NI article is dead for the moment.