2023-10-13 11:27 AM
Hi,
I am new to STM32 devices. I have a STM32F407 Discovery 1 board.
I wanted to generate a 1 KHZ signal with a 50% duty cycle.
The timer clock is configured to 84 MHZ
I am using TIM3 on channel 4. The prescaler is 210 and the counter period is 400 =>
84000000 / 210 / 400 is 1000 HZ
In my code I have the following:
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4); // start PWM on TIM3 CH4 on PB1 pin
PWM_Duty = 200; // set duty cycle to 50%
__HAL_TIM_SetCompare(&htim3, TIM_CHANNEL_4, PWM_Duty); // set duty cycle of PWM pin, now PWM starts running
Here is what I am seeing on the scope:
As you can see the frequency is 992.9 HZ.
I am trying to understand the resolution and why it is not 1000 HZ?
Thanks for any info.
Brent
Solved! Go to Solution.
2023-10-13 11:44 AM
Values for Prescaler and Period are N-1, you created 84000000 / 210+1 / 400+1 is 992.78 HZ
You want 210-1 and 400-1, the 50/50 point is still 200
For best resolution / granularity in width make the Prescaler as small as possible, and the Period as large as will fit in 16-bit TIM3
2023-10-13 11:44 AM
Values for Prescaler and Period are N-1, you created 84000000 / 210+1 / 400+1 is 992.78 HZ
You want 210-1 and 400-1, the 50/50 point is still 200
For best resolution / granularity in width make the Prescaler as small as possible, and the Period as large as will fit in 16-bit TIM3