2020-12-16 12:41 PM
I'm using STM32l152 and use TIM5_Ch2 for generate pwm .
My target frquency pwm is 2.85 KHz .
I using these parameter:
clock frequency = 32MHz
htim5.Init.Prescaler = 6;
htim5.Init.Period = 100;
I measured pwm on oscilloscope and I measure 2.85KHz with 50% duty cicle .
The formula that used is :
Frequency_pwm = ClockFreq / ((PSC + 1) * (ARR + 1))
where am i wrong?
BR.
Francesco
2020-12-16 01:27 PM
> My target frquency pwm is 2.85 KHz .
> I measured pwm on oscilloscope and I measure 2.85KHz with 50% duty cicle .
What's the problem, exactly?
In any case, read out and check/post the TIM registers content, and post the clocks (AHB/APB) setup (if in doubts, output clock onto MCO and measure, and/or also check/post relevant RCC registers content).
JW
2020-12-16 10:55 PM
this my register ..
Yu can tell me the values of f clock and if
Frequency_pwm = ClockFreq / ((PSC + 1) * (ARR + 1)) = 2.85 KHz ?
Thanks
2020-12-17 11:30 AM
RCC_CFGR.SW=0 which means you are running from MSI, RCC_ICSCR.MSIRANGE = 0b101 i.e. MSI runs around 2.097MHz. There's no APB prescaler in RCC_CFGR i.e. APB thus TIM clock is 2.097MHz. TIM is set to period 2097000/(6+1)/(100+1)=2.966kHz. TIM configuration is not finished, it's not running, nor is any channel enabled in CCER, nor is any CCRx set to other than 0, so I don't know what would an output look like exactly.
Note, that MSI is an RC oscillator, i.e. it has some error, see datasheet.
I still don't know, what was the question.
JW