Skip to main content
ELECL.2
Associate II
January 7, 2024
Solved

Frequency PWM calculation vs real

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.
TDK
TDKBest answer
January 7, 2024

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

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

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

2 replies

TDK
TDKBest answer
January 7, 2024

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

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

"If you feel a post has answered your question, please click ""Accept as Solution""."
ELECL.2
ELECL.2Author
Associate II
January 7, 2024

Thanks ! Need to read datasheet careful with PSC bit !