2

I am unsure of the relationship between duty cycle and angle. I see lots of tutorials online with many different equations to calculate duty cycle for a given angle. I have a 50Hz servo motor that ranges between a 2%-12% duty cycle for 0-180 degrees.

The equation I've seen is (angle/18 + 2). This works but I do not understand why and virtually all resources just give the equation with no explanation where the numbers come from.

Can someone please explain why I am dividing by 18 and add 2 to my duty cycle?

  • PS - In case you find the above posts too blurred to read (because of too many down votes :( ), you may try read the following clear version: (4) penzu.com/p/772fa292. Happy python programming. Cheers. – tlfong01 Feb 7 at 1:44
  • 1
    I'm sorry, but i have to downvote your post because it is a simple arithmetic question and has abslutely nothing to do wih the RPi .... you are trying to translate a range of 0 to 180 into a range of 2 to 12 ... also can be thought of as a range of 0 to 10 with an offset of 2 ....... the equation that you are having trouble grasping is (angle/180 × 10) + 2 .... (0/180×10)+2 = 2 .... (180/180×10)+2 = 12 .... (90/180×10)+2 = 7 – jsotola Feb 7 at 2:36
  • Ah let me see. Me IQ 97 never can do division. In primary school, I used a Chinese abacus and used my fingers (no pen!) to do division. In middle school, I had a 4 figure log table and used subtraction to do division. In college, I used a slide rule to do division. Fast forward a couple of decades, I still don't know what is the meaning of division, because Excel is my friend. I just ask Excel "WHAT IF", eg: What if 0 degrees = 0.4mS, 180 degrees = 2.4mS, frequency 50Hz, blah, blah, blah, and Excel, I mean Rpi4B LibreOffice Calc does all the dirty work: imgur.com/gallery/12YxJss. – tlfong01 Feb 8 at 4:38
  • Actually Libre Calc is as powerful as the evil MS Excel. It can give you a chart, yes, no scary numbers, not to mention division, of say, "relationship" between degree, pulse width, duty cycle: (1) penzu.com/p/772fa292. And much more than that, say for open loop fake PID servo control. Say if you want the servo to move from 20 degrees to 150 degrees, in a trapezoidal pattern, starting very slow, gradually increases to very fast, then steady, then towards the end point, smoothly stops. That is, no abrupt, jerky movements. Yes,poor Arduino guys without Calc are feeling jealous!. – tlfong01 Feb 8 at 5:16
3

Servos are controlled by pulse width, the pulse width determines the horn angle.

A typical servo responds to pulse widths in the range 1000 to 2000 µs.

A pulse width of 1500 µs moves the servo to angle 0. Each 10 µs increase in pulse width typically moves the servo 1 degree more clockwise. Each 10 µs decrease in pulse width typically moves the servo 1 degree more anticlockwise.

Small 9g servos typically have an extended range and may respond to pulse widths in the range 500 to 2500 µs.

Why do people think servos are controlled by duty cycle? Because servos are typically given 50 pulses per second (50 Hz). So each pulse is potentially a maximum of 20000 µs (1 million divided by 50). A duty cycle is the percentage on time. 100% will be a 20000 µs pulse, way outside the range accepted by a servo.

Do some calculations at 50 Hz for sample pulse widths.

 500 / 20000 = 0.025 or  2.5 % dutycycle
1000 / 20000 = 0.05  or  5.0 % dutycycle
1500 / 20000 = 0.075 or  7.5 % dutycycle
2000 / 20000 = 0.1   or 10.0 % dutycycle
2500 / 20000 = 0.125 or 12.5 % dutycycle

Don't use dutycycles, if possible use pulse widths, and think in pulse widths. If you send pulses at 60 Hz by duty cycle the servo will go to the wrong position.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.