hil_set_pwm_frequency hil_set_card_specific_options navigation bar

Table of Contents

hil_set_pwm_mode

Deprecated

The HIL API MATLAB functions have been deprecated in favour of the new quanser.hardware.hil class, which has support for code generation for Quanser targets. Hence, with the new hil class it is possible to run MATLAB scripts in real-time on Quanser targets, while making use of the Quanser hardware.

Sets the mode of the specified PWM channels.

Syntax

err = hil_set_pwm_mode(board, channels, pwm_modes)
    

Description

Sets the mode of the specified PWM channels. The mode determines how values written to the PWM outputs are interpreted.

In duty cycle mode values are interpreted as duty cycles, with 0.0 indicating a 0% duty cycle and 1.0 indicating a 100% duty cycle. The PWM output frequency is fixed in this case and may be set using the hil_set_pwm_frequency function.

In frequency mode values are interpreted as frequencies. In this case the duty cycle is fixed and may be set using the hil_set_pwm_duty_cycle function.

In period mode values are interpreted as periods. In this case the duty cycle is fixed and may be set using the hil_set_pwm_duty_cycle function.

If no err output is provided then it throws an exception if an error occurs. In generated code it prints the error message. Use hil_get_error_message to get the message associated with an error code.

Parameters

board

The board handle returned by hil_open.

channels

A vector of channel numbers. Channel numbers are zero-based.

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

pwm_modes

A vector of PWM modes. There must be one element for each channel in the channels vector. Valid modes are:

Mode

Name

Comment

0

PWM_DUTY_CYCLE_MODE

Values are interpreted as duty cycles where 0.0 is 0% and 1.0 is 100% - the default

1

PWM_FREQUENCY_MODE

Values are interpreted as frequencies

2

PWM_PERIOD_MODE

Values are interpreted as periods

3

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

4

PWM_TIME_MODE

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

5

PWM_ENCODER_EMULATION_MODE

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

6

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)

Outputs

err

A negative error code or zero on success.

Examples

% Writes 50% to pwm channel 0, 100% to channel 3 and -50% to channel 5
hil_set_pwm_mode(board, [0 3 5], [0.5 1.0 -0.5);
    

See Also

 

navigation bar