hil_set_pwm_frequency hil_set_pwm_configuration navigation bar

hil_set_pwm_duty_cycle

Sets the duty cycle of a PWM output.

Description

The hil_set_pwm_duty_cycle function sets the duty cycle that will be used for a PWM output. This function is typically used only in PWM_FREQUENCY_MODE or PWM_PERIOD_MODE. The actual PWM output duty cycle is not changed until the PWM output is used in one of the following functions:

Prototype

t_error
hil_set_pwm_duty_cycle(t_card card, const t_uint32 pwm_channels[], t_uint32 num_channels, const t_double 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 duty cycles 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_double [] buffer

An array containing the duty cycle values for the PWM outputs. 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 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 duty cycles are written 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_DUTY_CYCLE_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_DUTY_CYCLE_NOT_POSITIVE

One of the duty cycles specified is negative or zero. The duty cycle must be positive.

QERR_DUTY_CYCLE_TOO_HIGH

One of the duty cycles specified is greater than one. The duty cycle must be between 0.0 and 1.0 inclusive.

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 duty cycle to 50% for PWM output channel 0 and 75% for PWM output channel 1.
*/

t_uint32 channels[] = { 0, 1 };
t_double buffer[]   = { 0.5, 0.75 };
t_error result = hil_set_pwm_duty_cycle(board, channels, ARRAY_LENGTH(channels), buffer);
    

 

navigation bar