go_away

Author Topic: Variable Motor Speed Stepper  (Read 1670 times)

0 Members and 1 Guest are viewing this topic.

Offline RobDTopic starter

  • Full Member
  • ***
  • Posts: 64
  • Helpful? 0
Variable Motor Speed Stepper
« on: May 31, 2008, 10:20:40 AM »
I was looking through the forums for examples of how to vary the speed of steppers outside of software and saw some of the examples being used.  I may have missed one so I apologize if this is a duplicate effort.  This is just here for anyone thats curious how I do it.  I borrowed this idea from  http://www.interq.or.jp/japan/se-inoue/e_step.htm
 
This method of varying the speed outside of software is to use an RC integrator and a transistor.  A capacitor and varaible resistor are tied in series with the top of the resistor at Vcc and the bottom of the cap at GND.  The base of the NPN transistor is connected to an output pin of a microcontroller and the emitter to ground.  The collector of the transistor is tied to the top of the cap and an input pin on the microcontroller.

When the output pin is high, the transistor is turned on, the cap is discharged and a low is read on the input of the uController.  When the output pin is low, the transistor is off and the cap is allowed to charge. When it completes its charging a high is read on the input of the uController.

This charging time is varied by adjusting the variable resistance.  The formula is Time = Resistance*Capacitance

So, for a 100k variable resistor and a 10uF cap you can vary from 0 to 0.1 ms.  I've added a 1K fixed resistor to mine so that when the variable is turned all the way down, the charge time is 0.01 ms. 

Here's the schematic as used on a pic:

(image here) http://www.brandywineobservatory.org/electro/motor6.GIF



The code:

:
;consider RA4 input and RA3 output
;
;To discharge capacitor
;

bsf     porta, 3      ;set output high to turn on transistor
btfsc  porta, 4      ;check if input is low - capacitor discharged?
goto  $-1             ;no?  wait

;
;do stuff here
;

;
;to charge the capacitor
;

bcf     porta, 3      ;set output low to turn off transistor
btfss   porta, 4      ;check if input is high - capacitor charged?
goto   $-1            ;no?  wait

;
;do other stuff now
;

I still use a small delay in software, but add the discharge code at the beginning and the charge code at the end.  Works quite well.



     

 


Get Your Ad Here