cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f429 TIM9 PWM setup

nobody102
Associate II
Posted on March 17, 2017 at 02:58

I am sure this has been asked 1000 times, but I still cannot get the results I need.  I am trying to generate a 12800000 clock output on TIM9 with a 50% duty cycle.  I have looked at the code examples.  I have the APB2 clock set to 160MHz, but cannot figure out the prescalar, ARR, and pulse values.  Any help is apperciated.

#pwm
1 REPLY 1
S.Ma
Principal
Posted on March 17, 2017 at 07:03

Trying to understand, goal is to generate a periodic square wave at 180MHz/

12800000 ?

Usually the additional question would be: How many duty cycles are needed? Here we assume 50% only.

The prescaler can be 100000 (PSC=9999). In this case, the counter has to count from 0 to 127 and overflow back to 0 for 128 steps. (AAR=128)

The period will be 180MHz/(100000 x 128)

Duty cycle 50% would be when the counter reaches 64, this will be the CCn compare register which will toggle the output pin. There are various configuration option for the behaviour of the output compare to chose from.

Use an oscilloscope and a debugger to stop the SW in the main loop, then open the HW register editor watch window and manually play with the timer/gpio registers until things look right. This avoid repetitive compile/test cycles.