Code for standalone stepper motor controller.
I am very new to PARALLAX Propeller.
I'd like make a simple Standalone stepper motor controller by using P8X32A QuickStart and Easydriver(DIR & STEP),
What I need do is: when I press momentary push button switch, The stepper motor turn 30 rev. (assume 200STEPS/REV.), then
stop.
Can somebody write a code for me?
Thanks a lot in advance!
I'd like make a simple Standalone stepper motor controller by using P8X32A QuickStart and Easydriver(DIR & STEP),
What I need do is: when I press momentary push button switch, The stepper motor turn 30 rev. (assume 200STEPS/REV.), then
stop.
Can somebody write a code for me?
Thanks a lot in advance!
Comments
How much does this job pay?
and then create a loop in Spin that change a pin state 200*30 times and stop.
Quote:
Step Input (STEP). A low-to-high transition on the STEP input sequences the translator and advances the motor one increment.
If you want to use a driver device such as the Easy Driver, you really have to read all the material and figure out what does what. Nobody wants to read documents for somebody else. That Easy Driver has some sort of 'control language' that should have examples included with its documentation.
Frankly, depending on the size and voltage of the stepper motor, the wiring of it is actually a much bigger hurdle than the coding. You can Google for both coding and wiring samples, but it is just of loop of 4 or 8 steps in the usual setups. Rotation rate is determined by inserting a delay.
I do have an example of doing this in PropForth with a UNL2803 and a tiny 5 volt stepper and it was extremely easy.
Here is just one code example from OBEX. Sorry, but no code for Easy Driver.. that's a SparkFun product.
http://obex.parallax.com/objects/682/
After purchasing a Propeller Professional Development Board, I wanted to try writing a program that would use the buttons (normally pulled high) to control a stepper with the on board L293D chip. The attached code was written in June 2010 (expect for the modifications I made this morning).
I've attached that program modified to only turn 30 times one way or the other based on which of two buttons if pressed.
The code should work with a lot of different motor control chip that use a "half" H-bridge circuit.
There's no ramping or speed control. I'll likely be adding these as soon as OBC sends me a set of cheap steppers and wheels for another robot.
Here's the part of the code that looks for the button presses and sends the motor driving object instructions to turn 30 times.
if ina[12] == 0 ' pin 12 normally held high if button brings pin low it is "on" repeat intructionAcceptedFlag := Stepper.DriveRevolutions(30, 0) while intructionAcceptedFlag == 0 Debug.str(string("30 full revolution cw")) Debug.tx(13) elseif ina[13] == 0 repeat intructionAcceptedFlag := Stepper.DriveRevolutions(30, 1) while intructionAcceptedFlag == 0 Debug.str(string("30 full revolution ccw")) Debug.tx(13)
I'm sure there are many better stepper objects around (including Loopy's).
As Loopy warned, there are lots of different kinds of steppers. The code I attached was used with a bipolar (four wire) stepper motor.
The original poster got a rather cold reception for being a new user. Your help is more in keeping with what Parallax Forums do best.
Your question is a little broad, being there are many stepper motor options out there, but here's some simple code which I'm using to run those little 5v stepper motors you find almost everywhere.
_clkmode = xtal1 + pll16x _xinfreq = 5_000_000 StepperA = 18 ' Stepper Motor Coil 1 StepperB = 19 ' Stepper Motor Coil 2 StepperC = 20 ' Stepper Motor Coil 3 StepperD = 21 ' Stepper Motor Coil 4 forward = 1 backward = 0 VAR byte BitPattern[ 5 ] long count PUB Demo | cycles, direction cycles := 512 direction := forward OneStepper(StepperA,StepperB,StepperC,StepperD,direction,cycles) PUB OneStepper (in1,in2,in3,in4,direction,cycles) | pos0,pos1 if direction == 1 pos0:=0 pos1:=3 if direction == 0 pos0:=3 pos1:=0 BitPattern[ 0 ] := %1100 '%1000 BitPattern[ 1 ] := %0110 '%1100 BitPattern[ 2 ] := %0011 '%0100 BitPattern[ 3 ] := %1001 '%0110 DirA[ in1..in4 ] := %1111 repeat cycles repeat count from pos0 to pos1 OutA[ in1..in4 ] := BitPattern[count] waitcnt(cnt+(clkfreq>>8))
I'm sure I'll be working on my stepper code more once I start working with your version of a cheap an inexpensive robot.
When I first started working with a stepper, I noticed how the bit pattern just seemed to rotate so I decided to use bit rotation of a single bit mask instead of having multiple bit masks.
I define the intial pattern as:
_InitialPattern = %11001100_11001100_11001100_11001100
And then rotate the pattern one way or the other depending on the direction.
PRI ClockWise repeat until (stepCounter-- =< 0) stepPattern <-= 1 outa[pinD..pinA] := stepPattern long[globalStepsLocation] += 1 Pause(_MinimumStepDelay + delay) ready := 1 PRI CounterClockWise repeat until (stepCounter-- =< 0) stepPattern ->= 1 outa[pinD..pinA] := stepPattern long[globalStepsLocation] -= 1 Pause(_MinimumStepDelay + delay) ready := 1
Since bit ratotation is a "long" operation, I repeat the byte sized bit pattern four times. Only the lowest byte of the long is used to set the output pins.
Anyway, I thought it was kind of a cool way to do it. (I'm sure I'm not the first to do it this way.)
I'll have to see if I can get my OBC CheapBot to do a figure 8 with this method.