From 78faea4b8dd3456131405fd72059476dc426ca2e Mon Sep 17 00:00:00 2001 From: BreederBai Date: Mon, 4 Jul 2022 10:26:33 +0800 Subject: [bsp/stm32]优化功能(drv_pwm):设置PWM频率和脉宽时不破坏上一个PWM周期 (#6129) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [bsp/stm32]优化功能(drv_pwm):设置PWM频率和脉宽时不破坏上一个PWM周期 --- bsp/stm32/libraries/HAL_Drivers/drv_pwm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c index 81af346b1e..b655b7c442 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_pwm.c @@ -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; } -- cgit v1.3.1