cancel
Showing results for 
Search instead for 
Did you mean: 

PWM frequency generated using timer 1 is incorrect.

GBert.2
Senior

I want to generate a PWM at ~76K Hz using the TIMER1 on an STM32F401 microcontroller.

To my understanding, because the timer 1 is clocked at 84 MHz, I need to configure the ARR to 1099. See the screenshot to see my detailed configuration.

## The problem: I observed a ~14.5 kHz on my logic analyzer.

I don't understand where this calling comes from. Do you have any idea?

0693W00000JPWf2QAH.png 

## Config details

Here you can see which bus is connected to timer1

0693W00000JPWenQAH.pngHere you can see my clock tree configuration0693W00000JPWesQAH.pngHere you can see my PWM configuration0693W00000JPWeTQAX.png 

## Software version

CubeMx 6.4.0

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

So it's off by a factor of ~5.2.

84 MHz / 5.2 = 16 MHz, which is the HSI frequency.

Most likely your system clock is the default HSI and not what you have shown in the clock tree.

Perhaps clock initialization fails and is silently ignored.

Outputting MCO would confirm, but what you've shown is pretty conclusive in itself.

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

View solution in original post

2 REPLIES 2
TDK
Guru

So it's off by a factor of ~5.2.

84 MHz / 5.2 = 16 MHz, which is the HSI frequency.

Most likely your system clock is the default HSI and not what you have shown in the clock tree.

Perhaps clock initialization fails and is silently ignored.

Outputting MCO would confirm, but what you've shown is pretty conclusive in itself.

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

You were right. For some reason, the SystemClock_Config was not called in the main.

Even after regenerating the project.

Thanks for your answer @TDK​