Appearance
PWM
Pulse Width Modulation API.
The PWM API can be used to control the duty-cycle of a PWM peripheral Since the timing-parameters are passed in microseconds, the maximum meaningful PWM frequency would be in the range of 100kHz, allowing for 100 different PWM "steps". Functionality like inverting the PWM signal and setting the maximum frequency, if available from the HAL driver, is provided via SysConfig parameters.
Sysprops
sysprop | description |
---|---|
polarity_invert | set this to 1 to have the PWM generate an active-low signal |
Types
Name | |
---|---|
typedef float | pwm_duty_percent_t |
Functions Overview
Name | |
---|---|
CW_DRIVER_FUNC | pwm_enable(int hDev, uint16_t channel) enable the PWM channel |
CW_DRIVER_FUNC | pwm_disable(int hDev, uint16_t channel) disable the PWM output. |
CW_DRIVER_FUNC | pwm_set_duty_cycle(int hDev, uint16_t channel, pwm_duty_percent_t duty_cycle, uint32_t period_us) configure the PWM output ratio. |
Types Documentation
typedef pwm_duty_percent_t
cpp
typedef float pwm_duty_percent_t;
Function Details
function pwm_enable
cpp
CW_DRIVER_FUNC pwm_enable(
int hDev,
uint16_t channel
)
enable the PWM channel
Parameters:
- hDev device handle as returned by open(const char*)
- channel some PWM peripheral drivers differentiate different pin outputs via channels. the pin-to-channel assignments will be set in the SysConf. If this is not required by the HAL driver, simply pass 0 here.
when enabled, the pin will output the PWM signal configured by a previous call to pwm_set_duty_cycle or to "0%" if the channel wasn't configured before.
function pwm_disable
cpp
CW_DRIVER_FUNC pwm_disable(
int hDev,
uint16_t channel
)
disable the PWM output.
Parameters:
- hDev device handle as returned by open(const char*)
- channel some PWM peripheral drivers differentiate different pin outputs via channels. the pin-to-channel assignments will be set in the SysConf. If this is not required by the HAL driver, simply pass 0 here.
disabling the output will effectively result in a low level on the pin, or if the driver supports inversion and it is enabled in the SysConf a high level, respectively.
function pwm_set_duty_cycle
cpp
CW_DRIVER_FUNC pwm_set_duty_cycle(
int hDev,
uint16_t channel,
pwm_duty_percent_t duty_cycle,
uint32_t period_us
)
configure the PWM output ratio.
Parameters:
- hDev device handle as returned by open(const char*)
- channel channel some PWM peripheral drivers differentiate different pin outputs via channels. the pin-to-channel assignments will be set in the SysConf. If this is not required by the HAL driver, simply pass 0 here.
- duty_cycle normalized length of the duty period (0 .. 1).
- period_us length of a pulse period in microseconds, resulting in a PWM frequency of 1,000,000 / period_us Hz.
the PWM signal will be high for (period_us / duty_us * 100) % of the time.