@@ -47,17 +47,19 @@ void TimerPeripheral::init() {
4747 handle->Instance = handle_to_timer[handle];
4848 handle->Init .Prescaler = init_data.prescaler ;
4949 handle->Init .CounterMode = TIM_COUNTERMODE_UP;
50- for (PWMData pwm_data : init_data.pwm_channels ) {
50+ handle->Init .Period = init_data.period ;
51+ handle->Init .ClockDivision = TIM_CLOCKDIVISION_DIV1;
52+ handle->Init .RepetitionCounter = 0 ;
53+ handle->Init .AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
54+ for (PWMData pwm_data : init_data.pwm_channels ) {
5155 if (pwm_data.mode == PHASED) {
52- handle->Init .CounterMode = TIM_COUNTERMODE_CENTERALIGNED1;
53- break ;
56+ handle->Init .CounterMode = TIM_COUNTERMODE_CENTERALIGNED3;
57+ handle->Init .AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
58+ break ;
5459 }
5560 }
56- handle->Init .Period = init_data.period ;
57- handle->Init .ClockDivision = TIM_CLOCKDIVISION_DIV1;
58- handle->Init .RepetitionCounter = 0 ;
59- handle->Init .AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
60-
61+
62+
6163 if (init_data.type == BASE) {
6264 if (HAL_TIM_Base_Init (handle) != HAL_OK){
6365 ErrorHandler (" Unable to init base timer on %d" , name.c_str ());
@@ -111,8 +113,7 @@ void TimerPeripheral::init() {
111113 sConfigOC .OCNIdleState = TIM_OCNIDLESTATE_RESET;
112114
113115 if (pwm_data.mode == PHASED) {
114- // ASSYMETRIC_MODE_1 means one output per pair of registers (CCR1 - CCR2) for example
115- sConfigOC .OCMode = TIM_OCMODE_ASSYMETRIC_PWM1;
116+ sConfigOC .OCMode = TIM_OCMODE_PWM1;
116117 if (HAL_TIM_PWM_ConfigChannel (handle, &sConfigOC , pwm_data.channel ) != HAL_OK) {
117118 ErrorHandler (" Unable to configure a PWM channel on %d" , name.c_str ());
118119 }
0 commit comments