Question
STM32U575 change PWM output duty realtime
I tried to change PWM output duty without stopping or suspending PWM output, but between two times of writing new value to CCR, there must be a delay time inserted in. Following is the example code:
/* if delay_ms(300), code can run correctly, if changing it to delay_ms(200), a hardfault would occur
volatile int val = 0;
if (HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1) != HAL_OK)
{
/* PWM Generation Error */
Error_Handler();
}
while (1)
{
__HAL_TIM_SetCompare(&htim1, TIM_CHANNEL_1, val);
delay_ms(300);
if (val == 144)
{
val = 0;
}
else
{
val += 12;
}
}
Who can help me out that if it is a bug of this MCU?