Table of Contents
hil_write_pwm
Writes to PWM outputs immediately.
Description
The hil_write_pwm function writes to the specified PWM output channels immediately. The function does not return until the data has been written.
The interpretation of the data to be written depends upon the PWM mode. Typically the data is interpreted as a duty cycle, in which a magnitude of 0.0 denotes a 0% duty cycle and magnitude of 1.0 indicates a 100% duty cycle. The sign determines the polarity of the output for those boards supporting bidirectional PWM outputs. However, other PWM modes are possible with some boards. Refer to the hil_set_pwm_mode function for details.
Prototype
t_error hil_write_pwm(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 to be written.
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 values to write to the PWM outputs. How these values are interpreted depends on the PWM mode. The PWM mode is configured using the hil_set_pwm_mode function. 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 outputs 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_WRITE_PWM_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_MISSING_PWM_OUTPUTS
The pwm_channels argument is NULL. If the number of channels is greater than zero then a channel vector must be provided.
QERR_MISSING_PWM_OUTPUT_BUFFER
The buffer argument is NULL. If the number of channels is greater than zero then a buffer must be provided.
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_HARDWARE_CLOCK_IN_USE
One of the PWM output channels is based on a hardware clock that is already in use for another operation and the board-specific HIL driver for this board does not permit sharing of the hardware clock.
QERR_WRONG_CLOCK_MODE
One of the PWM output channels is based on a hardware clock that is in the wrong mode for this operation. Use the hil_set_clock_mode function to change modes.
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
/*
* Write to the first four PWM output channels.
*/
t_uint32 channels[] = { 0, 1, 2, 3 };
t_double buffer[] = { 0.0, 0.3, 0.7, 1.0 };
t_error result = hil_write_pwm(board, channels, ARRAY_LENGTH(channels), buffer);
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.
Link to this page.