[nzlug] Controlling a basic servo-motor ...
Wayne Rooney
wrooney at ihug.co.nz
Sun Dec 2 09:45:35 NZDT 2007
On Saturday 01 December 2007 22:08, Bernard O'Leary wrote:
> At this stage I'm looking for pointers, advise, and answers to a few
> questions. For example - is it advisable to test the serial port output
> using an oscilloscope prior to hooking up the servo? And is it sweet to
> hook the serial port output directly to the PCM signal input on the servo,
> or should there be some hardware in-between? What is the recommended way to
> power a servo (I assume the serial port lacks the necessary juice
> requirements)? etc ...
Once upon a tine, Dick Smith's was selling an excellent book
called "Controlling the world with your PC" by Paul Bergsman. I have a copy.
Controlling DC servo motors is Chapter 27, page 133.
"The control logic generates positive going pulse width control. With power
applied and no pulses, the output shaft is free turning. The length of the
pulse tells the on-board electronics what angular position to move to and
then stay at. Pulse widths between 0.5 milliseconds, and 2.5 milliseconds
will result in the output shaft moving 0 to 180 degrees. For example, a
pulse width of 1.5 milliseconds would position the output shaft at 90
degrees, while a pulse width of 1 millisecond would position the shaft at a
45 degree position. The output shaft will maintain its position as long as
pulse width signals are repeated." Circuit diagram, Pascal and C code
included, for controlling a servo motor off a parallel port, with a note that
it is easy to controll up to eight motors simultaneously off a parallel port.
I don't know if a serial port will natively produce pulse width modulation,
but I tend to think not. Perhaps I am wrong.
So you need a pulse width modulator that can be varied by a signal from a
serial port.
Mark Foster's suggestion of using a PICAXE is a good one, because a PICAXE can
input serial data and output a pulse train, just with a few simple commands
(the PICAXE has a servo command for controlling servo motors!)
The book "Programming and customizing the PICAXE microcontroller" by David
Lincoln, available from Surplustronics (www.surplustronics.co.nz) covers
controlling servo motors on pages 242 through 245. The book has a basic
circuit where the position of a potentiometer is read, and the servo motor
output shaft is positioned according to the potentiometer shaft position. The
entire circuit consists of three resistors, a potentiometer, the PICAXE and
the servo motor. The program is eight lines of code.
It wouldn't be hard at all to adapt the above circuit to adjust the pulse
train according to a signal from a serial port.
Hope this helps.
Cheers,
Wayne
More information about the NZLUG
mailing list