cancel
Showing results for 
Search instead for 
Did you mean: 

How to set ARR and PSC for 20kHz Center-Aligned PWM with TIM1 and resolution over 1000?

김형건
Associate II

Hi,

I'm using STM32F103RB (NUCLEO-F103RB) and I configured the clock system in STM32CubeMX.
I am using HSI as the clock source, and the APB2 timer clock is running at 64 MHz.
I want to generate 20kHz PWM signals using TIM1 Channel 1, 2, and 3, and I’ve already set all channels to Center-Aligned PWM Mode 2.

My requirements are:

PWM frequency: 20 kHz

Resolution: At least 1000 steps (preferably ARR ≥ 999)

Timer: TIM1, running at 64 MHz input clock

However, I’m not sure how to set the correct values for ARR and PSC to achieve exactly 20kHz and also meet the resolution requirement.

Questions:
What combination of ARR and PSC values should I use to achieve 20kHz PWM with ≥1000 resolution?

Is it okay to use PSC = 0 and a higher ARR to get better resolution?

Are there any known limitations with HSI or APB2 clock setup that I should be aware of in this context?

Thanks in advance for your help!

3 REPLIES 3
ahsrabrifat
Senior

Use:

PSC = 0;
ARR = 1599;

 

This gives you exactly 20 kHz PWM in Center-Aligned Mode with 1600 steps of resolution.

Totally valid and efficient configuration.

 

김형건
Associate II

Shouldn't it be PSC=1, ARR=1599?

64,000,000 / ((1+1)*(1+1599)) = 20,000 

> Shouldn't it be PSC=1, ARR=1599?

No, @ahsrabrifat is correct.

In center aligned mode, it counts twice per pwm period.

TDK_0-1747161303134.png

 

If you feel a post has answered your question, please click "Accept as Solution".