Skip to main content
bharadwajtke
Associate II
March 11, 2015
Question

Generating 1Mhz PWM with STM32F407(Discovery Board)

Posted on March 11, 2015 at 13:44

I have been trying to generate a PWM of 1Mhz & 2Mhaz in different pins, with a system clock of 168Mhz, but unable to do so, can any body help me out with the code.

Please help me with a small code snippet for the same...

Thanks in advance :)

#discovery #stm32f407
This topic has been closed for replies.

11 replies

Tesla DeLorean
Guru
March 17, 2015
Posted on March 17, 2015 at 15:32

Ok, it helps to understand what you're doing rather than use tools that hide the detail.

Your system file suggests the timer is clocking at 64 MHz, not 168 MHz

To get 1 Hz you need to count 64000000 ticks at 64 MHz. A simple factoring of this gives

1000 x 64000

So

Prescaler = 1000 - 1;

Period = 64000 - 1;

Pulse = 64000 / 2; // Half of the Period

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..