10 Replies Latest reply on May 27, 2014 6:20 AM by DaKn_263916

# Problem to control servo motor

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

• ###### 1. Re: Problem to control servo motor

Is the period 20ms? or frequency 20Hz?

• ###### 2. Re: Problem to control servo motor

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

1 of 1 people found this helpful
• ###### 3. Re: Problem to control servo motor

Ref material.

Regards, Dana.

1 of 1 people found this helpful
• ###### 4. Re: Problem to control servo motor

Ref material

Regards, Dana.

1 of 1 people found this helpful
• ###### 5. Re: Problem to control servo motor

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

• ###### 6. Re: Problem to control servo motor

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

Bob

• ###### 7. Re: Problem to control servo motor

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

• ###### 8. Re: Problem to control servo motor

Happy coding.

Bob

• ###### 9. Re: Problem to control servo motor

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.

• ###### 10. Re: Problem to control servo motor

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.