hil_set_pwm_mode hil_set_pwm_duty_cycle navigation bar

Table of Contents

hil_set_pwm_frequency

Sets the frequency of a PWM output.

Description

The hil_set_pwm_frequency function sets the frequency that will be used for a PWM output. This function is typically used only in PWM_DUTY_CYCLE_MODE (the default). The actual PWM output frequency is not changed until the PWM output is used in one of the following functions:

Prototype

t_error
hil_set_pwm_frequency(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 frequencies 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 frequencies in Hertz 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 frequencies 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_FREQUENCY_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_CLOCK_FREQUENCY_NOT_POSITIVE

One of the PWM frequencies specified is negative or zero. The PWM frequency must be positive.

QERR_CLOCK_FREQUENCY_TOO_HIGH

The PWM frequency is too high for one of the specified PWM outputs.

QERR_CLOCK_FREQUENCY_TOO_LOW

The PWM frequency is too low for one of the specified PWM outputs.

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 frequency to 10 kHz for PWM output channel 0 and 20 kHz for PWM output channel 1.
*/

t_uint32 channels[] = { 0, 1 };
t_double buffer[]   = { 10000, 20000 };
t_error result = hil_set_pwm_frequency(board, channels, ARRAY_LENGTH(channels), buffer);
    

 

navigation bar