Go Down

Topic: Software Servo library vs ATmega 328 timers (Arduino Uno) (Read 2226 times) previous topic - next topic

Slappy

Jul 31, 2012, 03:10 am Last Edit: Jul 31, 2012, 03:16 am by Slappy Reason: 1
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.

Krodal

#1
Jul 31, 2012, 10:07 am Last Edit: Jul 31, 2012, 10:24 am by Krodal Reason: 1
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.
http://www.arduino.cc/en/Reference/Servo
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.

dxw00d

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

DuaneB

Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

jraskell


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) IF 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.

DuaneB

Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com


Go Up