Servo library or AnalogWrite

Hi everybody,

I'm using an Arduino Due, to run a quadrotor UAV. So far, i've been using the Servo library to run my 4 GAUI 1050KV DC motor through 4 GUEC GE-010 ESC. For resolution matters, i want to use the AnalogWrite function instead of the Servo library. However, it seems like the motors are not responding at all. For now i didn't change the PWM resolution so it's still 8 bits. This code wouldn't make the rotors turn:

int motor4Pin = 8;    

void setup()  { 
pinMode(motor4Pin,OUTPUT);
  analogWrite(motor4Pin, 10); 
  delay(1000);
  analogWrite(motor4Pin, 200); 
} 

void loop()  
{                           
  }

Thanks =)

The PWM signal to a servo is a 1 to 2 mS pulse every 20 mS. AnalogWrite() signal is 0 to 100% duty cycle at a much higher rate (varies from port to port) and is not even close to what a servo (your ESC wants). You can use the servo.writeMicroseconds() function to get better resolution than 0 to 180 degrees.

You can use the servo.writeMicroseconds() function to get better resolution than 0 to 180 degrees.

Or you can use Servo.write with "angle" values in the range of about 544 to 2500, which is the same as calling the writeMicroseconds function.

Thanks for the information. Is it possible to make AnalogWrite() works in that case by modifying the timers? Maybe it's a silly question, actually i didn't really get that part; and why i can't use direct PWM now; although i already runned brushless motor like that before.

The way servo.write works is that for "angle" values between 0 and 180, it takes a nominal 1856us interval (2400 - 544) and divides it by 180, giving a granularity of about 10us.

If you use servo.writeMicroseconds or "angle" values above 543, you can specify to the microsecond (though there'll be some jitter) the width of your R/C control pulse, so you've got much finer control - about 10x finer.

Stoo: Is it possible to make AnalogWrite() works in that case by modifying the timers? Maybe it's a silly question, actually i didn't really get that part; and why i can't use direct PWM now; although i already runned brushless motor like that before.

Might that have anything to do with the fact that a servo is different from a brushless motor? It's a bit like saying I used to tell the time with my clock, why can't I do it with my football?

What exactly do you want to do with your servo that you can't do with the Servo library?

...R