Software Servo library vs ATmega 328 timers (Arduino Uno)

I'm involved with a project that requires use of pwm signals to drive six brushless DC motors (each connected to an ESC) for a hexrotor hovercraft. The hovercraft will use an IMU to automatically hover in one spot for prolonged periods of time; this will, of course, require the use of PID control. My partner and I differ on how to generate the appropriate pwm signals; I am leaning toward using the microcontroller's Timer and OCRn registers directly, while my partner prefers to use the Software Servo library.

My fear of using the Servo library is due to the fact that I don't understand how one timer (Timer1 in this case) can drive six motors without sacrificing performance. I've looked at Servo.h and Servo.cpp, but Servo.cpp's code is difficult for me to understand and I'd like to just start finishing up the programming for the project. Can anyone offer a simple explanation on how Software Servo drives more than two motors, or their thoughts on choosing timers vs the servo library?

If indeed the servo library is just, or almost efficient, as manually programming the timers I'll go with the servo library in a heartbeat.

The Servo library uses a hardware timer of the avr chip, but the hardware timer only issues an interrupt and does not change any output pins. Inside the interrupt, the function "handle_interrupts" is called. This function sets the outputs pins high or low for one or more pins. The tone() function and the SoftPWM use the same technique.

I'm not familiar with DC brushless servo motors. Can you post a link where I can read about it ? I have only used normal servo motors (0-180 degrees) and H-bridge drivers for DC motors. Can those motors operate with a PWM signal ? If you use the function analogWrite, you use hardware timers with PWM output.

The OP is using ESCs (Electronic Speed Controller) for each motor. They are controlled as servos.

A bit of a Servo library overview here -

Duane B

Slappy: but Servo.cpp's code is difficult for me to understand and I'd like to just start finishing up the programming for the project.

This is classic premature optimization syndrome. If you want to start finishing up the programming, then start finishing up the programming with the Servo Library.

As long as your code is properly organized, it should be trivial to replace the Servo Library with your own 'optimized' implementation (though not trivial to write your own optimized implementation) [u]IF[/u] project testing shows that the Servo Library is too slow. I think you'll find that the Servo Library is quite adequate to the task.

As for optimisation its fast, around 1% of CPU time used to control 12 servos.

Duane B

Thank you all for your responses!