Skip to main content
Associate
March 12, 2024
Question

controlling servo motors in high frequency with stm32

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

 

    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    March 13, 2024

    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    March 13, 2024

    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    galporatAuthor
    Associate
    March 14, 2024

    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