Table of Contents
hil_set_pwm_mode
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.
err = hil_set_pwm_mode(board, channels, pwm_modes)
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.
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 |
|
Values are interpreted as duty cycles where 0.0 is 0% and 1.0 is 100% - the default |
1 |
|
Values are interpreted as frequencies |
2 |
|
Values are interpreted as periods |
3 |
|
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 |
|
Values are interpreted as the active pulse time in seconds, which should range from 0 to the PWM period |
5 |
|
PWM outputs vary in frequency by specifying counts/sec. Paired/complementary signals are 90 degrees out of phase |
6 |
|
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) |
err
A negative error code or zero on success.
% 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
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.
Link to this page.