Newsgroups: comp.robotics
Path: brunix!cat.cis.Brown.EDU!agate!howland.reston.ans.net!europa.eng.gtefsd.com!MathWorks.Com!news.duke.edu!news-feed-1.peachnet.edu!umn.edu!moose.cs.umn.edu!jfischer
From: jfischer@moose.cs.umn.edu (John D. Fischer)
Subject: Re: controling servo motors
Message-ID: <CqqCFu.IMB@news.cis.umn.edu>
Keywords: servo 6811
Sender: news@news.cis.umn.edu (Usenet News Administration)
Nntp-Posting-Host: moose.cs.umn.edu
Organization: University of Minnesota, Twin Cities
References:  <2s3ukv$h6e@lastactionhero.rs.itd.umich.edu>
Date: Wed, 1 Jun 1994 17:51:23 GMT
Lines: 46

void ServoInit()
{
   pokeb(OC1M, 0x60); /* */
   pokeb(OC1D, 0x60); /* */
   poke(TOC1, 0); /* set OC1 to trigger when the counter reaches 0 */
   poke(TOC2, 2500); /* set servo on port A6 to center */
   poke(TOC3, 2500); /* set servo on port A5 to center */
   pokeb(TCTL1, 0xA0);
}
void ServoTurn(angle5, angle6)
   int angle5, angle6;
{
   /* the difference between consecutive servo positions is 20 ticks. */
   if (200 < angle5) angle5= 200;
   angle5= (angle5*20) + 500;
   
   poke(TOC3, angle5); /* change the position bigger = counter-clockwise */

   if (200 < angle6) angle6= 200;
   angle6= (angle6*20) + 500;
   
   poke(TOC2, angle6); /* change the position bigger = counter-clockwise */
}
void main()	       /* Begin of main routine         */
{
   int servo1, servo2;

   ServoInit();

   while(1)	 /* Create an infinite loop       */ 
   {
      servo1= rcv_i();
      servo2= rcv_i();

      ServoTurn(servo1, servo2);
   }
}  /* End of main routine */

This program runs two servos from port a5 and a6.
In your start up routine on the eprom you will want to set the clock 
to go as fast as it can. Set the TMSK2 pr1 and pr0 bits to 0.  This will
give a 31.25 ms cycle time. I got my servos to work using this program.
I found that I had to change the TOC by 20 in order to change the postion
of the servo.

	john fischer 
