Skip to main content
Explorer
January 7, 2024
Solved

Frequency PWM calculation vs real

  • January 7, 2024
  • 1 reply
  • 2451 views

Hi, 

I would like to understand why I don't have the right frequency on my PWM. I am working on STM32F103RG.

I would like to have a 8Khz PWM on Timer 3 channel 1, so I have configure my HSI to 8Mhz. APB2 Timer is set to 8Mhz. Prescaler to 10 and ARR to 100. 

So theoretically, my frequency PWM is 8Mhz, but when I measure it, I have 7.22khz. Around 10% from 8Khz. And HSI can have around 2% tolerance so this not the problem...

Some one have this problem ? Why I can't be able to have 8Khz ? 

 

    This topic has been closed for replies.
    Best answer by TDK

    You're off by one. Set PSC=9 and ARR=99.

    8 MHz / (10 + 1) / (100 + 1) = 7.2 kHz

    1 reply

    TDKAnswer
    Super User
    January 7, 2024

    You're off by one. Set PSC=9 and ARR=99.

    8 MHz / (10 + 1) / (100 + 1) = 7.2 kHz

    ELECL.2Author
    Explorer
    January 7, 2024

    Thanks ! Need to read datasheet careful with PSC bit !