How to setting TIM CHx/CHxN for six step BLDC motor control?
I want to control BLDC motor in six step method using STM32G474RE (nucleo board).
I'm using TIM1 CHx/CHxN complementary PWM output for 6 pwm signal, like below:
The problem I have is that the PWM output does not switch synchronously when switching steps, like below:
The desired switch looks like this:
How can I synchronaize the PWM when switching the steps, with STM32G474 MPU?
Please give me some advice.
My setting for TIM1 PWM:

And, a part of code for six step:
void MC_NEXT_step(mc_six_step_t *p)
{
switch (p->step_count)
{
case 0:
HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_3);
HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_3);
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, p->compare_value);
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
break;
case 1:
HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_2);
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, p->pwm.period);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_3);
break;
case 2:
HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_1);
HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_1);
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, p->compare_value);
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);
break;
case 3:
HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_3);
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, p->pwm.period);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
break;
case 4:
HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_2);
HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_2);
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, p->compare_value);
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_3);
break;
case 5:
HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_1);
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, p->pwm.period);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);
break;
default:
break;
}
}