hil_watchdog_clear
Clears the watchdog state after expiration.
Description
When the watchdog timer expires, it prevents further access to the hardware after setting the outputs to the configured expiration states. In order to clear this "protected" state and allow access to the hardware again, the hil_watchdog_clear function must be called. This function restores the hardware to its state prior to the watchdog timer expiring, if possible.
For example, for the Q8-series cards it reprograms the digital directions and analog modes to their original values since these are reset by the watchdog expiration (if the analog and digital output expiration states have been configured).
Prototype
t_error hil_watchdog_clear(t_card card);
Parameters
t_card card
A handle to the board, as returned by hil_open .
Return value
The return value is 0 if the watchdog state is cleared successfully.
Otherwise a negative error code is returned. Error codes are
defined in quanser_errors.h
. A suitable error message
may be retrieved using
msg_get_error_message
.
Error codes
QERR_HIL_WATCHDOG_CLEAR
This function is not supported by the board-specific HIL driver for this board type.
QERR_INVALID_CARD_HANDLE
An invalid card handle was passed as an argument. Once a card has been closed using hil_close the card handle is invalid.
Requirements
Include Files |
Libraries |
---|---|
hil.h |
hil.lib;quanser_runtime.lib;quanser_common.lib |
Examples
/* * Configure a watchdog timer that will expire every 0.1 seconds and reset the * analog outputs to 0V and the digital outputs to tristate upon expiration. * Also create a task for performing real-time control that reads * four encoder channels every millisecond. The watchdog is cleared every sampling * instant. */ t_double frequency = 1000; /* 1 kHz (0.001 seconds) */ t_uint32 samples = 5000; /* Iterate for 5000 samples (5 seconds) */ t_uint32 samples_in_buffer = frequency; t_uint32 samples_to_read = 1; /* Read one sample (four channels) every sampling instant */ t_double timeout = 100 / frequency; /* 100 sampling instants (0.1 seconds) */ t_uint expirations = 0; t_uint32 encoder_channels[] = { 0, 1, 2, 3 }; t_uint32 analog_channels[] = { 0, 1, 2, 3 }; t_double voltages[] = { 0, 0, 0, 0 }; t_uint32 digital_channels[16]; t_uint32 states[16]; t_int32 counts[4]; t_error result; t_task task; int index; for (index=0; index < ARRAY_LENGTH(digital_channels); index++) { digital_channels[index] = index; states[index] = DIGITAL_STATE_TRISTATE; } hil_watchdog_set_analog_expiration_state(card, analog_channels, ARRAY_LENGTH(analog_channels), voltages); hil_watchdog_set_digital_expiration_state(card, digital_channels, ARRAY_LENGTH(digital_channels), states); hil_task_create_encoder_reader(board, samples_in_buffer, channels, ARRAY_LENGTH(channels), &task); hil_watchdog_start(card, timeout); hil_task_start(task, SYSTEM_CLOCK_1, frequency, samples); for (int index = 0; index < samples; index++) { hil_task_read_encoder(task, samples_to_read, counts); /* returns every millisecond with next sample */ if (hil_watchdog_reload(card) == 0) { /* reload watchdog before using counts for control */ /* Watchdog expired before we managed to reload it. Keep track of how many times this occurs. */ expirations++; /* Clear watchdog state so we can continue to control the hardware */ hil_watchdog_clear(card); } ... /* do control calculations and output motor torques */ } hil_task_stop(task); hil_task_delete(task); hil_watchdog_stop(card);
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.