hil_set_pwm_configuration
Sets the configuration, alignment and polarity of PWM outputs.
Description
The hil_set_pwm_configuration function sets the configuration that will be used for a PWM output, as well as their alignment and polarities. Currently supported configurations are:
Configuration |
Description |
---|---|
PWM_UNIPOLAR_CONFIGURATION |
The PWM output is unipolar, with a value of 0 or Vcc at any instant of time, where Vcc is the supply voltage (or I/O pin voltage). |
PWM_BIPOLAR_CONFIGURATION |
In the bipolar configuration, PWM outputs may take on -Vcc, 0 or +Vcc values. Only a select number of Quanser cards support this functionality. On the Quanser QPID and QPIDe cards, bipolar outputs appear on analog output pins instead of the PWM outputs. |
PWM_PAIRED_CONFIGURATION |
In the paired configuration, two PWM outputs are paired and are controlled by the first PWM output in the pair. The second output may have leading-edge and trailing-edge deadbands applied relative to the first signal. |
PWM_COMPLEMENTARY_CONFIGURATION |
The complementary configuration is like the paired configuration, except the second PWM output in the pair is an inverted version of the first PWM output in the pair. The second output may have leading-edge and trailing-edge deadbands applied relative to the first signal. This configuration is useful for driving H-bridges, for example. |
The PWM alignment values may be:
Alignment |
Description |
---|---|
PWM_LEADING_EDGE_ALIGNED |
The leading edge of the pulse is aligned to the beginning of the PWM period. |
PWM_TRAILING_EDGE_ALIGNED |
The trailing edge of the pulse is aligned to the end of the PWM period. |
PWM_CENTER_ALIGNED |
The pulse is centered in the PWM period. |
Valid PWM polarities are:
Polarity |
Description |
---|---|
PWM_ACTIVE_LOW_POLARITY |
The PWM output is active-low. In other words, the signal is inverted. |
PWM_ACTIVE_HIGH_POLARITY |
The PWM output is active-high. |
The actual PWM output mode may not be changed until the PWM output is used in one of the following functions:
Prototype
t_error hil_set_pwm_configuration(t_card card, const t_uint32 pwm_channels[], t_uint32 num_channels, const t_pwm_configuration configurations[], const t_pwm_alignment alignments[], const t_pwm_polarity polarities[]);
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 configurations 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_configuration [] configurations
An array containing the configurations of the PWM outputs. The array must contain num_channels elements. Each element in the configurations array corresponds to the same element in the pwm_channels array.
const t_pwm_alignment [] alignments
An array containing the alignments of the PWM outputs. The array must contain num_channels elements. Each element in the alignments array corresponds to the same element in the pwm_channels array.
const t_pwm_polarity [] polarities
An array containing the polarities of the PWM outputs. The array must contain num_channels elements. Each element in the polarities array corresponds to the same element in the pwm_channels array.
Return value
The return value is 0 if the PWM configurations 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_CONFIGURATION_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_CONFIGURATION
One of the PWM configurations specified is not supported by this board.
QERR_INVALID_PWM_ALIGNMENT
One of the PWM alignments specified is not supported by this board.
QERR_INVALID_PWM_POLARITY
One of the PWM polarities 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 configuration of PWM channel 0 to be an independent output that is center-aligned with normal polarity.
* Set the configuration of PWM channel 1 to be an independent bipolar output that is edge-aligned with inverse polarity.
* Set the configuration of PWM channel 2 to be a complementary output that is center-aligned with normal polarity. For the QPID
* this setting will also determine the configuration of PWM channel 3 since it is paired with channel 2 as a complementary output.
*/
t_uint32 channels[] = { 0, 1, 2 };
t_pwm_configuration configurations[] = { PWM_UNIPOLAR_CONFIGURATION, PWM_BIPOLAR_CONFIGURATION, PWM_COMPLEMENTARY_CONFIGURATION };
t_pwm_alignment alignments[] = { PWM_CENTER_ALIGNED, PWM_EDGE_ALIGNED, PWM_CENTER_ALIGNED };
t_pwm_polarity polarities[] = { PWM_ACTIVE_HIGH_POLARITY, PWM_ACTIVE_LOW_POLARITY, PWM_ACTIVE_HIGH_POLARITY };
t_error result;
result = hil_set_pwm_configuration(card, channels, 3, configurations, alignments, polarities);
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.