quanser.hardware.hil.set_pwm_frequency quanser.hardware.hil.set_string_property navigation bar

Table of Contents

quanser.hardware.hil.set_pwm_mode

Sets the mode of the specified PWM channels.

Syntax

err = board.set_pwm_mode(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 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 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 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 instance returned by the quanser.hardware.hil.open function.

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

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
board.set_pwm_mode([0 3 5], [0.5 1.0 -0.5);
    

See Also

 

navigation bar