cancel
Showing results for 
Search instead for 
Did you mean: 

controlling servo motors in high frequency with stm32

galporat
Associate

Hello all,

I'm trying to learn how to control multiple servo motors with STM32.

I need to run my servos at 333Hz - and I don't know how to change the frequency from the default frequency?

Could anyone help me please - any example code / guide will be much apricated.

Gal

 

3 REPLIES 3

Freq = TIMCLK / ((PSC+1) * (ARR+1))

TIMCLK is typically the APBx CLK, or *2 if that's divided down from the AHB CLK

There are many STM32, can you be a bit more specific? What's the MCU clock running at?

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

For a typical 50 Hz (20 ms) Servo, off a TIMCLK of 72 MHz

PSC = 71 // Gets the counter at 1 MHz (1 us)

ARR = 19999 // Gets the frequency to 50 Hz, 20000 us, 20 ms

CCRx = 1000 to 2000 // for a pulse width of 1 - 2 ms

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

Hi, thanks for the help

I am very new to the platform can you farther explain what are the things you are setting or code example? I am using stm32f4 black pill