PWM driver
Collaboration diagram for PWM driver:
Functions | |
void | pwm_init (uint32_t period, uint32_t *duty, uint32_t pwm_channel_num, uint32_t(*pin_info_list)[3]) |
Initialize PWM function, including GPIO selection, period and duty cycle. More... | |
void | pwm_start (void) |
Starts PWM. More... | |
void | pwm_set_duty (uint32_t duty, uint8_t channel) |
Sets duty cycle of a PWM output. More... | |
uint32_t | pwm_get_duty (uint8_t channel) |
Get duty cycle of PWM output. More... | |
void | pwm_set_period (uint32_t period) |
Set PWM period. More... | |
uint32_t | pwm_get_period (void) |
Get PWM period. More... | |
uint32_t | get_pwm_version (void) |
Get version information of PWM. More... | |
Detailed Description
Function Documentation
◆ get_pwm_version()
uint32 get_pwm_version | ( | void | ) |
Get version information of PWM.
- Return values
-
uint32 PWM version
◆ pwm_get_duty()
Get duty cycle of PWM output.
- Parameters
-
channel PWM channel, which depends on how many PWM channels are used
- Return values
-
uint32 Duty cycle of PWM output
Duty cycle will be (duty*45) / (period*1000).
◆ pwm_get_period()
uint32 pwm_get_period | ( | void | ) |
Get PWM period.
- Return values
-
uint32 Return PWM period in us.
◆ pwm_init()
void pwm_init | ( | uint32_t | period, |
uint32_t * | duty, | ||
uint32_t | pwm_channel_num, | ||
uint32_t(*) | pin_info_list[3] | ||
) |
Initialize PWM function, including GPIO selection, period and duty cycle.
- Parameters
-
period PWM period duty duty cycle of each output pwm_channel_num PWM channel number pin_info_list Array containing an entry for each channel giving
- Note
- This API can be called only once.
Example:
uint32 ioInfo[][3] = { {PWM_0_OUT_IO_MUX, PWM_0_OUT_IO_FUNC, PWM_0_OUT_IO_NUM}, {PWM_1_OUT_IO_MUX, PWM_1_OUT_IO_FUNC, PWM_1_OUT_IO_NUM}, {PWM_2_OUT_IO_MUX, PWM_2_OUT_IO_FUNC, PWM_2_OUT_IO_NUM} }; pwm_init(light_param.pwm_period, light_param.pwm_duty, 3, ioInfo);
- Parameters
-
period PWM period duty duty cycle of each output pwm_channel_num PWM channel number pin_info_list Array containing an entry for each channel giving
- Note
- This API can be called only once.
Example:
uint32 io_info[][3] = { {PWM_0_OUT_IO_MUX, PWM_0_OUT_IO_FUNC, PWM_0_OUT_IO_NUM}, {PWM_1_OUT_IO_MUX, PWM_1_OUT_IO_FUNC, PWM_1_OUT_IO_NUM}, {PWM_2_OUT_IO_MUX, PWM_2_OUT_IO_FUNC, PWM_2_OUT_IO_NUM} }; pwm_init(light_param.pwm_period, light_param.pwm_duty, 3, io_info);
◆ pwm_set_duty()
void pwm_set_duty | ( | uint32_t | duty, |
uint8_t | channel | ||
) |
Sets duty cycle of a PWM output.
- Parameters
-
duty The time that high-level single will last, duty cycle will be (duty*45)/(period*1000) channel PWM channel, which depends on how many PWM channels are used
Set the time that high-level signal will last. The range of duty depends on PWM period. Its maximum value of which can be Period * 1000 / 45.
For example, for 1-KHz PWM, the duty range is 0 ~ 22222.
◆ pwm_set_period()
void pwm_set_period | ( | uint32_t | period | ) |
Set PWM period.
- Parameters
-
period PWM period in us. For example, 1-KHz PWM period = 1000us.
◆ pwm_start()
void pwm_start | ( | void | ) |
Starts PWM.
This function needs to be called after PWM configuration is changed.