I learned in school that typical servos use a simple "PWM" system to control a servo. To do this, we would generate a 1000 μs pulse to put the servo at 0 degrees and a 2000 μs pulse to set it at 180 degrees. Simple basics, right?
I recently tried configuring my HS-311 with these values and I found the servo moving less than 90 degrees. I switched to the Servo.h
library and it worked fine. I peeked at the Servo.h
file and found the following:
#define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo
#define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo
#define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached
544? 2400? Where are these numbers coming from?
I looked at an old datasheet for this servo and found
OPERATING TRAVEL: 40°/ONE SIDE PULSE TRAVELING 400 usec
DIRECTION: CLOCK WISE/PULSE TRAVELING 1500 TO 1900 usec
A bit hard to tell what the numbers mean but they are definitely not 1000 to 2000!
Then I took a look at the specs on servocity.com and I see:
Max PWM Signal Range 575-2460 μsec.
This matches with the Servo.h
source code!
What's going on here? Do manufacturers normally move outside of the 1000 μs to 2000 μs range? The values that I see far exceed what I'd think are acceptable tolerances. Please help me figure out where these numbers came from!
1 Answer 1
I've ran into this same issue. In the research I've done and the servo's I've worked with, the only way to know what the true max and min pulse widths are is to do some experimentation.
For example, servocity.com says this:
Different brands, and even different servos of the same brand, will have different maximum and minimums. Generally the minimum pulse will be about 1 ms wide and the maximum pulse will be 2 ms wide.
From my own testing with 3 or 4 different servo brands, 1ms-2ms is a "safe range". The servos will move within that range, but it likely won't be the full range that the servo is capable of. Start by looking at the data sheet, and then proceed to testing if you really need to eek out the most range.
For the HS-311, I believe the datasheet can be read as, "a change of 400usec corresponds to a rotation of 40°". If we assume the midpoint is 1500usec and the servo is capable of 180° rotation, then that would put the pulse width in the range of 600usec-2400usec which is close to the default range of the Servo.h
library which is why it likely worked without needing to change the default max and min values.
analogWrite()
.