[bsp/stm32]优化功能(drv_pwm):设置PWM频率和脉宽时不破坏上一个PWM周期 (#6129)

* [bsp/stm32]优化功能(drv_pwm):设置PWM频率和脉宽时不破坏上一个PWM周期
This commit is contained in:
BreederBai 2022-07-04 10:26:33 +08:00 committed by GitHub
parent b39210dea3
commit 78faea4b8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -330,10 +330,12 @@ static rt_err_t drv_pwm_set(TIM_HandleTypeDef *htim, struct rt_pwm_configuration
pulse = period;
}
__HAL_TIM_SET_COMPARE(htim, channel, pulse - 1);
__HAL_TIM_SET_COUNTER(htim, 0);
/* Update frequency value */
HAL_TIM_GenerateEvent(htim, TIM_EVENTSOURCE_UPDATE);
/* If you want the PWM setting to take effect immediately,
please uncommon the following code, but it will cause the last PWM cycle not complete. */
//__HAL_TIM_SET_COUNTER(htim, 0);
//HAL_TIM_GenerateEvent(htim, TIM_EVENTSOURCE_UPDATE); /* Update frequency value */
return RT_EOK;
}