2016-05-24 07:03 AM
I'm use STM32CubeMX to configure TIM2 CH1 to compare output, and it works well. Now I want to change it to PWM output when the programm running. Then which HAL library function to call to clear the registers previous set? It seems if I directly configure it without clear the registers, the value written before can't be cleared. My target MCU are STM32F429I.
Thanks. #timer2016-05-24 07:28 AM
You need to enable the preloading of shadow register by setting the TIM_CR1_ARPE in TIMx->CR1 register. It seems that the HAL doesn't provide a way to do this currently, so you have to configure it manually:
TIM3->CR1 |= TIM_CR1_ARPE; //Enable preloading TIM3->CR1 &= ~TIM_CR1_ARPE; //Disable preloadingThis will cause that the ARR is updated when the timer expires.2016-05-24 07:56 AM
Thanks. But in my situation, I can't even clear the setting values in CRx written previously. The bit I set before can't be reset. Why? Do I need manually clear them?
2016-05-24 08:37 AM
Hi diverger,
Try , first, to reset the output compare mode bits , select PWM mode and then enable the output compare preload. See code below:/* SET PWM1 mode */
/* Reset the Output Compare Mode Bits */
TIM1->CCMR1 &= ~TIM_CCMR1_OC1M;
TIM1->CCMR1 &= ~TIM_CCMR1_CC1S;
/* Select the output compare mode 1*/
TIM1->CCMR1 |= TIM_OCMODE_PWM1;
/* Enable the output compare 1 Preload */
TIM1->CCMR1 |= TIM_CCMR1_OC1PE;
-Hannibal-