Problem using 3 Output Compare Channels for Center Aligned PWM
Hello,
i am using the STM32F103C6 MCU and i would like to produce 3 different Center Aligned PWM signals with 16KHz frequency and Duty Cycle 1 to 99%. I would like to change the duty cycle on fly using the CCR registers.
I am configuring the 3 of TIM1's channels as Output Compare:

Then i choose the Center Aligned_3 mode and setting the frequency on 16KHz (frequency is correct):

Finally, every channel has the same settings as below:

With CubeMX's default code, i am just starting the OC and setting the desired pulse:
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_TIM1_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_1);
HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_2);
HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_3);
TIM1->CCR1 = 400; //Channel_1 ~ 82% Duty Cycle
TIM1->CCR2 = 1125; //Channel_2 ~ 50% Duty Cycle
TIM1->CCR3 = 2200; //Channel_3 ~ 2% Duty CycleAnd on simulator everything is correct:

If we change the CCR1 to lower value:
TIM1->CCR1 = 100; //Channel_1 95% Duty CycleSeems like Channel 1 is not aligned with the others, like it is shifted:

- Can someone help me and explain me what i am doing wrong?
- Is there any other way to produce those Center Aligned PWM signals?
- What is the safest way to change duty cycle on fly? Should i use the compare IRQ?
