Problem to control servo motor

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 Hi everybody!!

actually i´m working to control a servo motor i read that the frecuency is 20 hz and the duty cycle is 1,1.5 and 2 ms
i´m using pwm16:

   


parameter pwm16
clock = 1,000,000
period= 49,999
duty cycle = 999-> 1ms->0°
                     1499-> 1.5ms -> 90°
                      1999 -> 2ms -> 180°

but the servo doesn´t work correctly don´t go to the correctly position and keeps vibrating and i don´t understand why,so if someone help me i´m really be glateful
i put my code if someone can check it

 

0 Likes
1 Solution
Anonymous
Not applicable

 Is the period 20ms? or frequency 20Hz?

View solution in original post

0 Likes
10 Replies
Anonymous
Not applicable

 Is the period 20ms? or frequency 20Hz?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The specs for those kind of servos usually say: pulse repeated every 20 to 40ms non-critical, pulse width between 1.0 and 2.0 ms where 1ms is left stop, 2ms is right stop.

   

Usually having a PWM with a fixed frequency and changing the pulse-width as needed.

   

To care for the side effects might be necessary: the datasheet says

   

   
    Side Effects:   
   
    Writing the PulseWidth register, while the counter is active, changes the duty cycle of the output. This may cause the output to glitch or change inadvertently.   
   

   

Pulses not in the range of 1-2ms will be interpreted as failure and (depending on the servo model) a neutral position is used.

   

 

   

Bob

lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Ref material.

   

 

   

Regards, Dana.

ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Ref material

   

 

   

Regards, Dana.

Anonymous
Not applicable

 the frecuency it´s 50 Hz and the period it´s 20 ms 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Your selected period is 50ms, not 20 when looking into your source.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

thanks bob you´re rigth, i put the wrong value in the period i put 19999 and no longer vibrates   and works perfectly
thanks to all

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Your are always welcome!

   

 

   

Happy coding.

   

Bob

0 Likes
Anonymous
Not applicable

 If you have a servomotor Hitec... The servomotor works a 10 ms. So, you should use a 10khz in a PWM8, for example.

   

Next step, the servomotor works a left movement if you suministry 0.5ms of WidthPulse, works neutral(90 degrees) in a 1.5ms, and works a right with 2.5ms. This is the Hitec´s servomotors.

   

Excuse me, if you don´t understand my English 😞 . I learned English slowly.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

From the Hitec website -

   

 

   
        
  •        Q. What signal do servos require to operate?
  •    
   
    

A. All Hitec servos require a 3-4V peak to peak square wave pulse. Pulse duration is from 0.9ms to 2.1ms with 1.5ms as center. The pulse refreshes at 50Hz (20ms).

   
   

 

   

Regards, Dana.

0 Likes