cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling Servo motors with Timers problem

WINNER
Associate II

I set the parameter of TIM5 of my MCU on CubeMX,the frequency of the clock is 72 MHz,PSC is 7199,ARR is 199,the information about my settings is below:屏幕截图 2024-03-21 183646.png屏幕截图 2024-03-21 183735.png

TIM5 is used to output 4  channels of PWM to control four SG90 servos,TIM1 toTIM4 is used to control four Ultrasonic ranging module,I use this sentence to initialize four servos:屏幕截图 2024-03-21 184516.png

I think these servos should turn to 0 degree,but in fact it turn to 90 degrees and stuck there,I don't know the reason why it happened.I hope someone can heip me solve this problem,it has been made me confused for several days 

4 REPLIES 4
SofLit
ST Employee

Hello,

Check if your PWM timings fit the servo requirements:

SofLit_0-1711021953109.png

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

PWM frequency=(ARR+1)*(PSC+1)/72MHz=0.2s=20ms,

if I want to make four sevros turn to 0 degree,I should give it a high level for 0.5ms,so

0.5/20*200=5, I think my PWM setting is okay.Can you provide me another suggestion?Thank you very much!!

Attached an example (in draft) of a servomotor controlled by NUCLEO-F401RE board.

Hope it can help you.

 

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

These are relevent programs I wrote,can you help me find the problems in it?

I wonder where the problems come from.I want the servo turn to 0 degree at first,turn to 90 degrees when I press these keys.Thank you very much!