Skip to main content
Graduate
May 13, 2025
Question

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

  • May 13, 2025
  • 2 replies
  • 591 views

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!

    This topic has been closed for replies.

    2 replies

    Visitor II
    May 13, 2025

    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.

     

    김형건Author
    Graduate
    May 13, 2025

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

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

    Super User
    May 13, 2025

    > 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