2021-01-04 08:02 AM
Hi,
I'm testing various PWM scenarios and found that output frequency does not match with expected.
I'm using formula Period = (PSC+1)*(ARR+1) / TmerClockFreq in seconds Period = 1000 * (PSC+1)*(ARR+1) / TmerClockFreq in milliseconds. The board is Nucleo-144, MCU STM32H745Z.
My calculus :
PSC=0
ARR=1
TimerClockFreq (MHz)=80
TimerClockFreq (s) =0,00008
Period (ms) =25000
Frequency MHz= 40
So I expect close to 40 Mhz on output pin. GPIO setting on pin for speed is Very High.
But my measures shows me, that real frequency is 32,15 Mhz on scope, and 33.33 on 100 Mhz longing device. Documentation explains, that timers are free-running hardware parts, so any interrupts may not have impact, and all depends only on system clock. Attached system clock screen.
Where I'm wrong? Thanks in advance !
Regards,
Steponas
2021-01-06 07:16 AM
I measured a point on the MCO, frequency 7.97 Mhz, that's OK. What is interesting, any changes of clock settings (HSE, HSI, frequency from 80 to 240 Mhz) does not change result : 33.33 Mhz as is close 64 Mhz HSI RC /2. Or the problem is on initialization. But my code is simplest :
Default IDE generated HAL code + bottom
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
TIM3->PSC=0;
TIM3->ARR=1;
TIM3->CCR3=1;
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
/* USER CODE END 2 */