Searching \ for '[PIC]: Driving a servo?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=servo
Search entire site for: 'Driving a servo?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Driving a servo?'
2001\03\08@154737 by Justin Fielding

flavicon
face
Just started playing with timing on my 16F84's and thought driving a servo
would be idea as a little project.  I know that the pulses should be  from
1 - 2 ms, both being the extremes of travel.  What sort of resolution should
i be using  (e.g multis of 0.1 ms etc? ) and what shouls the spacing between
pulses be?

Thanks,

Justin.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\03\08@161224 by Lawrence Glaister

flavicon
face
Hi Justin,
you can find code to do this by searching the archives. If you want to try
it yourself, its not that hard.

1) set signal line low (or hi depending on servo model)
2) call a delay routine you write that takes a number 0..255 and delays
between 1 and 2ms depending on delay variable passed in
3)set signal line hi (or low as needed)
4) call a delay routine of around 40ms (0.040sec), this is not a critical
delay
5) loop back to 1

you may have to experiment to determine if your servos need to be pulsed hi
or low and invert the bit settings mentioned above.

the delay routine mentioned in 2 above is the only tricky part. 256 delay
values is getting close to all you expect to resolve through the mechanical
system in the servo.
=======================================================
Lawrence Glaister VE7IT             email: spam_OUTlgTakeThisOuTspamjfm.bc.ca
1462 Madrona Drive                    http://jfm.bc.ca/
Nanoose Bay BC Canada      http://gspy.sourceforge.net/
V9P 9C9               http://members.home.net/cncstuff/
=======================================================
{Original Message removed}

2001\03\08@162709 by Lawrence Lile

flavicon
face
Justin,

I always set up a one-byte counter for this purpose, which gives 256 steps
of resolution.  I found this to be sufficient for my purposes, but you'll
have to decide how precise you want to control position.  Each increment of
the counter ticks off 1mS/256 seconds, or about 4 clock ticks at 4 MHz.


Be careful, most servos use 1-2mS, but some use 0.5 to 2.5 mS.  If you send
the second kind of pulse to the first kind of servo, a loud POP will be
heard as the servo breaks it's stops.  I've got some code (in C) written for
the 0.5 to 2.5 mS kind of servo if you want it.

Hacking these can be fun.  Take the stops  and feedback resistor out of a
servo, and it can become a powerful reversable speed controlled gearmotor
motor.  Or, use an external pot and connect the servo to a jackscrew.  I
made a real nice coil winder with a hacked servo like this one time, the
servo working the wire back and forth across the face of the coil.

Lawrence Lile


{Original Message removed}

2001\03\08@170555 by Drew Vassallo

picon face
>4) call a delay routine of around 40ms (0.040sec), this is not a critical
>delay

I never heard of this... typically the servos work at 50Hz, which is 20ms
between pulses.  There's no real reason to go to 40ms delay.

You'll get jitter on your servos if you don't have the pulse widths within 2
or 3us (MAYBE stretch it to 4us) on consecutive pulses.

In other words, set output high, wait the desired time (0-2ms, depending on
to where you want your servo to move), set output low, wait 20ms minus the
time you had your pulse high.  Repeat, but ensure that the next high pulse
width is within 2 or 3us of the previous one.  This can be tricky if you're
using interrupts to determine your pulse width.  Or, if you run through
different paths to get to your pulse level changing routine, you may end up
with more or fewer instruction cycles from one pulse to the next.
Alternately, if you don't care about a few minor "clicks" of your servo here
and there, then you can ignore the jitter.

Should be a good learning experience... at least it'll give you a good
visual example of what happens in your code.

--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\03\08@171731 by Justin Fielding

flavicon
face
I basically just want to use bit 0 of port b to send the pulse, 1.5mS which
will centre the servo.  Trying to work out the delay's .. UHhhhh

Can someone paste some suitable code in?


{Original Message removed}

2001\03\08@181820 by Dale Botkin

flavicon
face
On Thu, 8 Mar 2001, Justin Fielding wrote:

> I basically just want to use bit 0 of port b to send the pulse, 1.5mS which
> will centre the servo.  Trying to work out the delay's .. UHhhhh
>
> Can someone paste some suitable code in?

Check the PICLIST website or, better yet, mine...  I've got a servo
exerciser program there.  http://www.botkin.org/dale/servotst.htm for the
whole thing.  I have to warn you -- it's old code, witten in a way
nonstandard C (CC5X), and it was my first exercise in C programming, so
it's ugly.  On the other hand, it works.  I also didn't bother to get more
than a few discrete steps, not fine control, but that wouldn't be too
difficult, I'm sure.  Hope it's helpful.

Dale

>
>
> {Original Message removed}

2001\03\08@183238 by Chris Carr

flavicon
face
> I basically just want to use bit 0 of port b to send the pulse, 1.5mS
which
> will centre the servo.  Trying to work out the delay's .. UHhhhh
>
> Can someone paste some suitable code in?
>
Yes, I can, but why should I, or anyone, else go to go to the effort of
providing information which, with a little bit of effort on your part you
would find is easily obtainable from the piclist.com archives and other
sources.

This topic of controlling toy servos has been covered to the point of
exhaustion on this list.

Knowledge is not a free commodity
It requires demonstrable effort on the part of the person
wishing to acquire it.

Carr

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\03\08@184723 by Justin Fielding

flavicon
face
part 1 1442 bytes content-type:text/plain; (decoded 7bit)

Your a real helpful guy, you are a great asset to the pic list.

Ahem,

Anyway, the following is the code I have written but it does not work.  I
just get a little blip when I turn it on and when I reset the pic.  Nothing
more, the servo does not attempt to hold position.


{Original Message removed}
part 2 6076 bytes content-type:application/octet-stream; (decode)

part 3 1126 bytes content-type:application/octet-stream; (decode)

part 4 154 bytes
--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\03\08@191407 by David Huisman

flavicon
face
A padded steering wheel and comfortable seat are essential for driving a
servo :)

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\03\09@024418 by Francois Robbertze

flavicon
face
I used the following code to turn a servo 90deg clockwise after a delay and
then 90 c-clockwise when the button is pressed again. This code have no
servo hold between actions...
I have done this code once when I was doing a project for a magician (a
pic16f84, ni-cad power and a servo was build into a book - It was Not a
Bomb)

Time1_K         equ     .5
Time1_M1        equ     .40
Time1_M2        equ     .1

;-------------------------------Port
Assingments-----------------------------
;         PORT A
        #Define         Servo   PortA,0
        #Define         Led       PortA,1
;         PORT B
       #Define         Start         PortB,0    ;activate switch
       #Define         Set1          PortB,1    ;setup menu switch
       #Define         Set2          PortB,2    ;setup menu switch

;start main program...

main
 ;return rotor to innitial position after initial setup...
 call  Clockwise

main1
 decf  timer,f
 btfsc  STATUS,Z
 call  togled  ;toggel LED
 btfsc  Start  ;wait for button
 goto  main1
 call  delay          ;appr. 5 sec delay
 call  Clockwise   ;Turn Clockwise

main2              ;reset servo to original pos. after switch pressed
 decf  timer,f
 btfsc  STATUS,Z
 call  togled
 btfsc  Start  ;wait for button
 goto  main2
 call  CClockwise ;Turn CClockwise
 goto  main1

togled
 decfsz  timer1,f
 return
 movlw  B'00000010'
 xorwf  PortA,f
 #movlf  .255,timer
 #movlf  .255,timer1
 return

;Subroutine to turn motor...

CClockwise
 #movlf  .100, steps
 bcf  Servo
ccwloop
 bsf  Servo
 call  delay1
 bcf  Servo
 call  delay20
 decfsz  steps,f
 goto  ccwloop
 return

Clockwise
 #movlf  .200, steps
 bcf  Servo
 #movlf  .1, deladd
cwloop
 bsf  Servo
 call  delay1
 incf  deladd,f
 call  delayadd        ;slowly increment delay to get a even movement!
 bcf  Servo
 call  delay20
 decfsz  steps,f
 goto  cwloop
 return

;20ms delay between servo pulses
delay20
#movlf  .20, deltim
loop20
 call  Time1
 decfsz  deltim,f
 goto  loop20
 return

;2ms delay for clockwise pulses
delay2  call  Time1
 call  Time1
 return

;1ms delay for cclockwise pulses
delay1  call  Time1
 return

;Delay Subroutine for waiting before motor action - app. 5 sec loop
delay
 movfw  trigger
 movwf  temp
delay_1
 call  delay_2
 decf  temp,f
 btfsc  STATUS,Z
 return
 goto  delay_1
delay_2
 movlw  .25   movwf  deltim
delay_3
 decfsz  deltim,f
 goto  delay_3
 decfsz  x,f
 goto  delay_2
 decfsz  y,f
 goto  delay_2
 return

delayadd
 movf  deladd,w
 movwf  deltim
delayloop1
 #movlf  .1,Count
delayloop2
 decfsz  Count,f
 goto  delayloop2
 decfsz  deltim,f
 goto  delayloop1
 return

Time1         ;appr. 1ms loop
 #movlf  Time1_M2, Time1M2Reg
Tme1_2
 #movlf  Time1_M1, Time1M1Reg
Tme1_1
 #movlf  Time1_K, Time1KReg
Dly1
 Decfsz  Time1KReg,F
 goto       Dly1
 Decfsz  Time1M1Reg,F
 goto       Tme1_1
 Decfsz  Time1M2Reg,F
 goto       Tme1_2
Return


hope this help!

regards

Francois


{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...