View Full Version : Discussion PIC Servo Driver Tutorials?
jtprouty
Dec 27, 2007, 11:42 AM
Hi All,
Are there any tutorials on the web that walk you through programming a PIC to drive servos? How about stepper motors? Always been interested in both but haven't been able to find the info I need.
Happy flying,
Jimmy
anestho
Dec 27, 2007, 01:06 PM
1) which PIC do you plan to use?
2) what resolution do you need for the servo (how many steps)?
3) what compiler do you want to use? and language: basic, C, asm..etc
I'll try to find the stepper program. I assume you know the hardware setup and just need the programming.
jtprouty
Dec 27, 2007, 01:14 PM
Thanks for the help. What I'm looking for are general tutorials to learn how to program PICs for servo and stepper applications. I haven't picked one out yet but do have some steppers and a bunch of servos. Programming in C would be best as I've studied C++ (as well as Basic) in the past but am willing to learn a new language to be able to do this.
Thanks again,
Jimmy
rmteo
Dec 27, 2007, 01:36 PM
If you want to go the quick and easy route, take a look at this software:
http://www.oshonsoft.com/pic.html
It has built-in routines for driving R/C servos as well as stepper motors. You can download a free, full-featured version that will run for 30 days.
Here is their routine for R/C servos:
● Interfacing Radio Control (R/C) servos
For writing applications to interface R/C servos there are two statements available: SERVOIN and SERVOOUT. R/C servo is controlled by a train of pulses (15-20 pulses per second) whose length define the position of the servo arm. The valid length of pulses is in the range 1-2ms. These two statements have two arguments. The first argument of both statements is the microcontroller pin where the servo signal is received or transmitted. For SERVOIN statement that pin should be previously setup as an input pin and for SERVOOUT statement the pin should be setup for output. The second argument of SERVOIN statement must be a Byte variable where the length of the pulse will be saved. The pulses are measured in 10us units, so it is possible to measure pulses in the range 0.01-2.55ms. The value stored in the variable for normal servos should be in the range 100-200. The second argument of the SERVOOUT statement should be a Byte variable or constant that determines the length of the generated pulse. For proper operation of the target servo SERVOOUT statement should be executed 15-20 times during one second. Here is an example of the servo reverse operation:
DIM length AS BYTE
TRISB.0 = 1
TRISB.1 = 0
loop:
SERVOIN PORTB.0, length
IF length < 100 THEN length = 100
IF length > 200 THEN length = 200
length = length - 100
length = 100 - length
length = length + 100
SERVOOUT PORTB.1, length
GOTO loop
anestho
Dec 27, 2007, 02:34 PM
I have 2 sets of code for driving a servo with 1000 steps between 1ms and 2 ms. Again depending on what you need. I write in C and use CCS C compiler. I would first take a look at the data specs of the chip you want to use. If you give me some more details about your project, I can suggest a chip for you.
xorcise
Dec 27, 2007, 08:58 PM
How about 33 servos at 256 PWM and 1us PWM with a single PIC.... oh yeah... with up to 115Kbaud USART and no jitter?
http://www.electro-tech-online.com/micro-controllers/34390-drive-33-servos-one-pic-usart.html
vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.