PWM Driver
Description
PWM Driver
The PWM driver uses one or more TIMER peripherals to generate one or more PWM waveform, with configurable frequency, duty cycle, and polarity. Multiple instances of the driver can be created and allocated to their own TIMER channel.
The duty cycle of the PWM waveform can be updated, while the PWM driver is running by calling sl_pwm_set_duty_cycle() , without causing glitches in the output waveform.
- Note
- If several PWM driver instances are set up to use the same TIMER instance, the PWM frequency of these instances must be the same.
PWM Example Code
Basic example for generating PWM waveform:
Data Structures |
|
| struct | sl_pwm_instance |
|
PWM driver instance.
|
|
| struct | sl_pwm_config |
|
PWM driver configuration.
|
|
Functions |
|
| sl_status_t | sl_pwm_init (sl_pwm_instance_t *pwm, sl_pwm_config_t *config) |
|
Initialize PWM driver.
|
|
| sl_status_t | sl_pwm_deinit (sl_pwm_instance_t *pwm) |
|
Deinitialize PWM driver.
|
|
| void | sl_pwm_start (sl_pwm_instance_t *pwm) |
|
Start generating PWM waveform.
|
|
| void | sl_pwm_stop (sl_pwm_instance_t *pwm) |
|
Stop generating PWM waveform.
|
|
| void | sl_pwm_set_duty_cycle (sl_pwm_instance_t *pwm, uint8_t percent) |
|
Set duty cycle for PWM waveform.
|
|
| uint8_t | sl_pwm_get_duty_cycle (sl_pwm_instance_t *pwm) |
|
Set duty cycle for PWM waveform.
|
|
Enumerations |
|
| enum |
sl_pwm_polarity_t
{
PWM_ACTIVE_HIGH = 0, PWM_ACTIVE_LOW = 1 } |
|
PWM polarity selection.
|
|
Function Documentation
◆ sl_pwm_init()
| sl_status_t sl_pwm_init | ( | sl_pwm_instance_t * |
pwm,
|
| sl_pwm_config_t * |
config
|
||
| ) |
Initialize PWM driver.
- Parameters
-
[in] pwmPWM driver instance [in] configDriver configuration
- Returns
- SL_STATUS_OK if there are no errors.
◆ sl_pwm_deinit()
| sl_status_t sl_pwm_deinit | ( | sl_pwm_instance_t * |
pwm
|
) |
Deinitialize PWM driver.
- Parameters
-
[in] pwmPWM driver instance
- Returns
- SL_STATUS_OK if there are no errors.
◆ sl_pwm_start()
| void sl_pwm_start | ( | sl_pwm_instance_t * |
pwm
|
) |
Start generating PWM waveform.
- Parameters
-
[in] pwmPWM driver instance
◆ sl_pwm_stop()
| void sl_pwm_stop | ( | sl_pwm_instance_t * |
pwm
|
) |
Stop generating PWM waveform.
- Parameters
-
[in] pwmPWM driver instance
◆ sl_pwm_set_duty_cycle()
| void sl_pwm_set_duty_cycle | ( | sl_pwm_instance_t * |
pwm,
|
| uint8_t |
percent
|
||
| ) |
Set duty cycle for PWM waveform.
- Parameters
-
[in] pwmPWM driver instance [in] percentPercent of the PWM period waveform is in the state defined as the active polarity in the driver configuration
◆ sl_pwm_get_duty_cycle()
| uint8_t sl_pwm_get_duty_cycle | ( | sl_pwm_instance_t * |
pwm
|
) |
Set duty cycle for PWM waveform.
- Parameters
-
[in] pwmPWM driver instance
- Returns
- Percent of the PWM period waveform is in the state defined as the active polarity in the driver configuration
Enumeration Type Documentation
◆ sl_pwm_polarity_t
| enum sl_pwm_polarity_t |