hil_watchdog_set_other_expiration_state hil_watchdog_reload navigation bar

Table of Contents

hil_watchdog_start

Starts the watchdog timer with the given timeout interval.

Description

The hil_watchdog_start function starts the watchdog timer with the given timeout interval. It should only be called after the expiration states have been configured using the hil_watchdog_set_xxxx_expiration_state functions. Once the watchdog timer has been started, it must be reloaded each time before it expires using the hil_watchdog_reload function.

Prototype

t_error 
hil_watchdog_start(t_card card, t_double timeout);
    

Parameters

t_card card

A handle to the board, as returned by hil_open .

t_double timeout

The expiration timeout interval in seconds.

Select a board type from the list for board-specific details: .

Return value

The return value is 0 if the watchdog started 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_START

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.

QERR_INVALID_TIMER_PERIOD

The specified timer period 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            = 0.1;                         /* 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);
    

 

navigation bar