hil_set_clock_frequency hil_set_digital_directions navigation bar

hil_set_clock_mode

Sets the mode for the hardware clocks.

Description

The hil_set_clock_mode function sets the mode of the hardware clocks. This function is used with hardware clocks that are multipurpose. Some boards, like the Q8, allow the hardware clocks to be configured as timebases (the default) or as PWM outputs. This function allows the appropriate mode to be selected

Prototype

t_error
hil_set_clock_mode(t_card card, const t_clock clocks[], t_uint32 num_clocks, const t_clock_mode clock_modes[]);
    

Parameters

t_card card

A handle to the board, as returned by hil_open.

const t_clock * clocks

An array containing the clocks whose mode will be changed. System clocks do not support different modes so only hardware clocks, such as HARDWARE_CLOCK_0, should be specified.

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

t_uint32 num_clocks

The number of clocks specified in the clocks and clock_modes arrays.

const t_clock_mode * clock_modes

An array of clock modes to which to set the clocks. Each element in the clock_modes array corresponds to the same element in the clocks array. Hence, there must be as many elements in the clock_modes array as there are clocks. The clock modes currently supported are:

Mode

Description

CLOCK_TIMEBASE_MODE

Allow the clock to be used as a hardware timebase.

CLOCK_PWM_MODE

Use the hardware clock as a PWM output.

CLOCK_ENCODER_MODE

Use the hardware clock as an encoder input.

Return value

The return value is 0 if the clock modes are set 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_SET_CLOCK_MODE_NOT_SUPPORTED

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_TOO_MANY_CLOCKS

Too many clocks were specified.

QERR_CLOCK_NOT_SUPPORTED

One of the clocks that was specified is not a valid clock. Clock numbers range from 0 to one less than the number of hardware clocks.

QERR_CLOCK_MODE_NOT_SUPPORTED

One of the clock modes that was specified is not supported by this board type.

QERR_HARDWARE_CLOCK_IN_USE

One of the specified clocks is already in use for another operation and the board-specific HIL driver for this board does not permit sharing of the hardware clock.

Requirements

Include Files

Libraries

hil.h

hil.lib;quanser_runtime.lib;quanser_common.lib

Examples

/* Configure HARDWARE_CLOCK_0 as a PWM output. */
t_uint32 clocks[] = { HARDWARE_CLOCK_0 };
t_int32 modes[] = { CLOCK_PWM_MODE };
t_error result = hil_set_clock_mode(board, clocks, ARRAY_LENGTH(clocks), modes);
    

See Also

 

navigation bar