I have some servo code I wrote about a month ago to control two servos. It was for a 16F872 or 873, and uses TMR1. I don't think the F84 has that timer, but it can probably be adapted to use TMR0. You can read the description of the code at: http://www.qsl.net/n8mx/tank/technical.html There are links to two files there: servoslo.asm and servoint.asm. Servoint.asm works using interrupts and the timer, so hardly any processor time is used. Servoslo.asm uses interrupts, but only for the "big" 20ms pulse. The other two pulses are generated using a speed variable like in Dale's description (I havent looked at his code yet). Also, both of the programs turn the servos (incf for one and decf for the other) in the interrupt code. You will want to get rid of this so you can update the servos on your own. Servo1Pos and Servo2Pos are the position (speed on the modded servos, I guess...) of the servos. Delay1ms and ServoPulseDelay are the two routines in servoslo.asm which delay. They will have to be modified to work right on a slower processor (I was running this one at 24.5MHz!). There is a delay generator at www.piclist.com in the code section that I have found to be very helpful in this. The time constant might have to be modified to work with your servos, but if you can get "close" enough (where the servos move in a semi-normally) it should be a lot easier to zero it in. Do you have an oscilloscope? That would make it a LOT easier to get the times in the "ballpark." Let me know if I can help with the code or explain it better... Andy Meng N8MX ----- Original Message ----- From: "Dale Botkin" To: Sent: Monday, December 24, 2001 10:12 AM Subject: Re: [PIC]: Servo code & robots > I've done both in C, but not assembly... if you'd like to see the servo > C code from my first attempt (warning:ugly, amateur C code!) you can see > it at https://www.botkin.org/dale. There is a .LST file that has the C > and ASM code in the same listing, if that helps. > > What I do is set up a regular interrupt using TMR0, usually around 1ms. > In the interrupt service routine I increment a counter. When the counter > hits the refresh interval of 20ms (or a little longer), I generate a pulse > with its period determined by the value of a variable. So all I have to > do is make that variable represent the position (or speed, in your case) > desired for the servo, and let the ISR do the work. > > By the way, if anyone has not seen it yet, the /TAB BOOKS BUILD YOUR OWN > ROBOT KIT/ is available in the US at Barnes & Noble. Awesome deal!! > Designed by Myke Predko & Ben Wirz, two names that should be very familiar > to anyone on this list. It's a complete PIC controlled robot kit in a > box, with a socket for a Basic STAMP II and Parallax App Mods. Price is > $60 and B&N had 20% off when I got one for my 16 year old son. The web > site at http://www.tabrobotkit.com/ has complete source listings and > schematics, so it's a hack-friendly platform. My *only* wish is that the > wheels were big enough for carpet use. Anyway, #3 Son will be opening it > some time today or tomorrow, I'll have more info on it then. I just hope > someone took my blatant hints and got one for me too! > > Dale > -- > "Curiosity is the very basis of education and if you tell me that > curiosity killed the cat, I say only the cat died nobly." > - Arnold Edinborough > > > On Mon, 24 Dec 2001, Prince Anamalech wrote: > > > > > Hello fellow PICSter's > > > > I am new to the pic scene but have gained sufficient knowledge to get me through so far! > > i am currently building a robot using a PIC16F84 . I am using two hacked servos for the motors, and am hoping to use two > > ultrasonic transducers (40Khz) to detect obstacles. > > I have hacked the servo's using a transistor bridge (making it think it is always in the centre position). I am trying to > > test out the servos by writing some assembly code with mplab, but i am having no success. > > I have connected the servo's control wire to a pic pin. PINS A.0 and A.1. Left and Right respectively. > > i have tried manipulating some code on the piclist archive but with no success. > > COULD anyone please help me out with some assembly code PLEASE? > > also does anyone have any ideas or schem's/code to help me out with my ultrasonic's?? > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics