Pages: [1]   Go Down
Author Topic: Software Servo library vs ATmega 328 timers (Arduino Uno)  (Read 2076 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 30, 2012, 08:16:40 pm by Slappy » Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 31, 2012, 03:24:19 am by Krodal » Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A bit of a Servo library overview here -

http://rcarduino.blogspot.com/2012/01/can-i-control-more-than-x-servos-with.html

Duane B

Logged


New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://rcarduino.blogspot.com/2012/02/can-i-control-more-than-x-servos-with_03.html

Duane B
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you all for your responses!
Logged

Pages: [1]   Go Up
Jump to: