Newsgroups: comp.robotics
Path: brunix!sgiblab!sdd.hp.com!math.ohio-state.edu!howland.reston.ans.net!cs.utexas.edu!bcm!aio!usenet
From: lock::cordell (Andy Cordell)
Subject: Re: Source (and circuit) for hobbie servos
Message-ID: <1993Dec7.003916.19896@aio.jsc.nasa.gov>
Sender: usenet@aio.jsc.nasa.gov (USENET News Client)
Organization: LOCKHEED, Johnson Space Center
X-Newsreader: WinVN version 0.80
References: <1993Nov30.052809.23334@dunix.drake.edu> <CHBJ3H.CMv@eskimo.com>
Date: Tue, 7 Dec 1993 00:39:16 GMT
Lines: 72

Somebody (yes, I forgot to save the message) a few days ago
asked for a circuit to control model airplane servos for 
use in a walking robot.

I built a walking robot a while ago and the following is 
what I discovered by trial and error, so no guarantees...

R/C servos are controlled by a PWM signal that controls the
position, not the speed of the output shaft.  The length of
each cycle is 15 mS. If the on time is 1.5 mS the servo will
be centered, less time it will move to the left, more time to
the right.  This makes them very easy to control with 
microprocessors.  If you don't have many servos to control, or
your processor doesn't have much else to do, you can drive it 
directly from an I/O port.  I had 18 servos to control so I 
used several 8253 timers. 8253 timers are the same timer used 
in PCs to keep track of time.  Your microprocessor can just 
set the timer and forget about it.  The timer will hold the
servo in position.  

Somebody might find the following program useful.  It allows you
to control a servo from a PCs printer port. I wrote it while I 
was trying to figure out exactly how R/C servos work.  I would be
interested in hearing from anyone building a walking robot.
					- Andy 
					

/*
 *  This program allows a PC to control a R/C model servo thru its
 *  printer port.
 *
 *  The servo should be wired with the red wire to 5-6v, black to 
 *  GND AND to pin 25(gnd) of LPT1 ,white to Pin 2(data 0) of of LPT1.
 * 
 *  The numbers entered for ON time and CYCLE time will vary 
 *  greatly from one computer to another.  My computer (386sx 16)
 *  worked with the cycle = 3000 and on = 10 to 1000.  
 *						
 */
#include <stdio.h>
#include <conio.h>

void main(void)
{
int ct,pw,i;

clrscr();
do
 {
  printf("Enter the total lenth of the CYCLE: ");
  scanf("%d",&ct);

  printf("Enter the length of the ON time: ");
  scanf("%d",&pw);

  if(pw >= ct)
    printf("Hey Bozo! Your ON time can't be less than the cycle time !\n\n");
  else
    {
      printf("We're running!...\n\n");
      while(!kbhit())
      {
	outportb(0x378,1);
	for(i=0;i<pw;i++);
	outportb(0x378,0);
	for(i=0;i<(ct-pw);i++);
      }
    }
}while (getch() != 27);

}

