Table of Contents
hil_watchdog_reload
Reloads the watchdog timer.
Description
The hil_watchdog_reload function reloads the watchdog timer. It is typically called to reload the watchdog timer before it expires at the top of the control loop.
Prototype
t_error hil_watchdog_reload(t_card card);
Parameters
t_card card
A handle to the board, as returned by hil_open .
Return value
Returns 1 if the watchdog timer was reloaded prior to expiration. Returns 0 if
the watchdog timer had expired before being reloaded. 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_RELOAD
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 reloaded 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_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 */ hil_watchdog_reload(card); /* reload watchdog before using counts for control */ ... /* 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.
Link to this page.