Associate
July 10, 2019
Solved
STM32F1xx: Confusion on CCRx value for a given PWM frequency with TIM1 PWM Output???
- July 10, 2019
- 5 replies
- 2348 views
I'm using an old STM32F103RD with SPL v3.6.1. I'm confused with the value to put in TIM1_CCRx for a giving PWM frequency.
Looking at \STM32Cube_FW_F1_V1.7.0\Projects\STM32F103RB-Nucleo\Examples_LL\TIM\TIM_PWMOutput\Src\main.c:
/* Set compare value to half of the counter period (50% duty cycle ) */
LL_TIM_OC_SetCompareCH1(TIM2, ( (LL_TIM_GetAutoReload(TIM2) + 1 ) / 2));
but I found in slider of STM32F7 webinar (en.STM32F7_WDG_TIMERS_GPTIM.pdf, see screenshot) that we should substract 1.
Ex: ARR = 4999, for a duty cyle of 50%, CCR1 = (4999+1) * 0.5 = 2500 or 2499?
Does the PWM mode (edge vs center-aligned) have an impact CCRx formula?
