Servo library

Hi,

I am controling a brushless motor using Servo.h library and I have 2 questions: when I use the command "write(120)" once, does the library keeps sending the interval of microsseconds related to the 120 angle forever? Or it sends only one pulse and stop?

And one more question: when I use only servo.attach(pin_number) and nothing else my motor starts turning. Why? The attach should not send any pulse to the motor, right?

oes the library keeps sending the interval of microsseconds related to the 120 angle forever?

Yes, that's what a servo expects.

: when I use only servo.attach(pin_number) and nothing else my motor starts turning. Why?

Because the attach starts the servo pulses.

If you want the motor to start at a particular speed you can do a .write() before you do the .attach().

The default is defined in the Servo library source - it's 1500us You can do a "write" before you do an "attach" to change this.

#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

Why 2000?

Why indeed - it should be 20000.

A servo PWM frame is 20ms (20000us) long, and is LOW most of the time, and HIGH for only 1 to 2ms nominally.

So you say it shouldnt be 2000 but 20000? If the pulse will be HIGH for only 1-2ms why does the pulse takes 20ms? Why cant it be 10ms?

Not sure if it is what you are talking about, but the circuit in the servo needs to see a low signal for ~3us to 5us to reset it self for the next position command. This fact might be included in the servo library in order to control more servos than the old analog 6 channel analog RC tx/rx systems.

Why do you need the pulse cycle to be 10ms? As far as I know, 20ms is the norm for servos. All it means is that the high part which lasts 1000-2000us is repeated on a 20000us cycle. What would be the advantage of repeating it more frequently?

The scope trace below shows the 1500 default attach being repeated.

servo attached.jpg

My motor expects a cycle of 20000?

Your motor? What motor? I thought we were talking about an ESC.

Each servo and ESC will have its own range of pulse spacing it is happy with, but they ALL work with 20ms. 1500us pulse-width is mid-travel in a RC control joystick, corresponding to mid-travel for servos and idle power for ESCs usually.

I just would like to be able to change the period of the wave to 10ms instead of 20ms which is the default of Servo library.

Why?

Why?

To possibly to change the command update to the ESC/servo from 20ms to 10ms. Might not really make any difference to motor/servo performance.

gilperon:
I just would like to be able to change the period of the wave to 10ms instead of 20ms which is the default of Servo library. Does anyone knows how to do that?

Have a look in servo.h where REFRESH_INTERVAL is set to 20000.

Edit: Attached scope screen shows it set to 10000.

Disclaimer: I have no idea what effects this may have on servo operations. I hooked my scope up without an actual servo plugged in.

10ms servo refresh.jpg