hil_set_encoder_quadrature_mode hil_set_pwm_frequency navigation bar

Table of Contents

hil_set_pwm_mode

Sets the mode of a PWM output.

Description

The hil_set_pwm_mode function sets the mode that will be used for a PWM output. The mode determines how the values written to a PWM output are interpreted. The modes currently supported are:

Mode

Comment

PWM_DUTY_CYCLE_MODE

Values written to a PWM output are interpreted as duty cycles. Duty cycle values must be fractions between 0.0 and 1.0, where 0.0 indicates 0% and 1.0 denotes 100%. The value may be signed for those boards which support bidirectional PWM outputs. The PWM frequency is fixed. The PWM frequency is set using hil_set_pwm_frequency.

PWM_FREQUENCY_MODE

Values written to a PWM output are interpreted as frequencies. Frequencies must be positive. The PWM duty cycle is fixed. The PWM duty cycle is set using hil_set_pwm_duty_cycle .

PWM_PERIOD_MODE

Values written to a PWM output are interpreted as periods. Periods must be positive. The PWM duty cycle is fixed. The PWM duty cycle is set using hil_set_pwm_duty_cycle .

PWM_ONE_SHOT_MODE

Values are interpreted as duty cycles where 0.0 is 0% and 1.0 is 100%, but only a single pulse generated per write

PWM_TIME_MODE

Values are interpreted as the active pulse time in seconds, which should range from 0 to the PWM period

PWM_ENCODER_EMULATION_MODE

PWM outputs vary in frequency by specifying counts/sec. Paired/complementary signals are 90 degrees out of phase

PWM_RAW_MODE

PWM outputs vary in duty cycle by raw board-specific values (used for DSHOT, for example, to allow throttle, telemetry and checksum to be encoded in a PWM output)

The actual PWM output mode is not changed until the PWM output is used in one of the following functions:

Prototype

t_error
hil_set_pwm_mode(t_card card, const t_uint32 pwm_channels[], t_uint32 num_channels, const t_pwm_mode buffer[]);
    

Parameters

t_card card

A handle to the board, as returned by hil_open .

const t_uint32 [] pwm_channels

An array containing the channel numbers of the PWM outputs whose modes are being set.

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

t_uint32 num_channels

The number of channels specified in the pwm_channels array.

const t_pwm_mode [] buffer

An array containing the modes of the PWM outputs. The array must contain num_channels elements. Each element in the buffer array corresponds to the same element in the pwm_channels array.

Return value

The return value is 0 if the PWM 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_PWM_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_PWM_OUTPUT_CHANNELS

Too many PWM output channels were specified.

QERR_INVALID_PWM_OUTPUT_CHANNEL

One of the PWM output channels that was specified is not a valid channel number. Channel numbers range from 0 to one less than the number of channels.

QERR_INVALID_PWM_MODE

One of the PWM modes specified is not supported by this board.

QERR_DRIVER_INCOMPATIBLE_WITH_BOARD_DLL

The board-specific HIL driver passed an invalid parameter to the operating system specific kernel-level driver for the board. The board-specific HIL driver is likely not compatible with the operating system specific kernel-level driver for the board. Make sure both are up-to-date and compatible versions.

QERR_INTERNAL_BUFFER_TOO_SMALL

The board-specific HIL driver used an internal buffer that was too small for the operating system specific kernel-level driver for the board. The board-specific HIL driver is likely not compatible with the operating system specific kernel-level driver for the board. Make sure both are up-to-date and compatible versions.

QERR_OUT_OF_REQUIRED_SYSTEM_RESOURCES

There are not enough system resources to perform the requested operation. Try rebooting, requesting fewer samples, or adding more memory to your machine.

Requirements

Include Files

Libraries

hil.h

hil.lib;quanser_runtime.lib;quanser_common.lib

Examples


/*
* Set the PWM mode to PWM_DUTY_CYCLE_MODE for PWM output channel 0 and PWM_FREQUENCY_MODE for PWM output channel 1.
*/

t_uint32 channels[] = { 0, 1 };
t_double buffer[]   = { PWM_DUTY_CYCLE_MODE, PWM_FREQUENCY_MODE };
t_error result = hil_set_pwm_mode(board, channels, ARRAY_LENGTH(channels), buffer);
    

 

navigation bar