PDA

View Full Version : Basic Program for Stepper Motors



NWUpgrades
06-14-2005, 09:48 PM
Jon, a while back ago you posted a reply to me with code for a PBasic program to help test my stepper motors.· I unfortunately did not have that saved and lost my hard drive. Could you maybe point me back to that code? Thanks

Jon Williams
06-14-2005, 09:52 PM
I don't know which BASIC Stamp module you're using, so I've attached BS1 and BS2 code.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Newzed
06-15-2005, 12:24 AM
Jon, I don't understand the above BS2 program.

StpIdx is declared a nibble.· You wrote:

Step_Fwd:
· stpIdx = stpIdx + 1 // 4····················· ' point to next step
· GOTO Do_Step

What is the starting value of StpIdx.· If 0, then it looks like StpIdx will remain at 0 since I don't see where it is incremented.

Sorry to be so dumb.

Sid

Paul Baker
06-15-2005, 02:36 AM
The stamp does left to right evaluations of expressions (Did I see somewhere that some newer stamps (or is it the IDE?) supports expression nesting?).

stpIdx = stpIdx + 1 // 4

when executed first adds 1 to stpIdx then performs the modulus 4 of the result meaning the progression is 0,1,2,3,0,1,2,...

Did I understand your question correctly? Did this answer it?

Newzed
06-15-2005, 02:45 AM
suppose StpIdx = 0

then StpIdx = 0 + 1//4 which = 0

It looks like StpIdx will stay at 0 until the dividend is·=> than 4.·

If I understand //4 correctly, it says "show the remainder after dividing by 4".

???????

Sid

Paul Baker
06-15-2005, 02:50 AM
You are correct in everything except you are applying order of precedence to a system which does not use it (you are assuming the modulus function is done before the increment). PBASIC does a strict left to right evaluation of the expression, so:

A) StpIdx is directed to receive the result.
B) The temporary variable is initialized to StpIdx
C) The temporary variable is incremented by 1
D) The temporary variable is mod 4'ed
E) The temporary variable is written to StpIdx

Oh and 1//4 is 1 not 0, the remainder of 1/4 is 1.

So for your example:

StpIdx = 0 + 1//4 = 1


Post Edited (Paul Baker) : 6/14/2005 7:56:04 PM GMT

Newzed
06-15-2005, 03:03 AM
I just wrote a little program:

stp· VAR byte

Stp = 0
Stp = stp + 1//4
DEBUG dec ? stp, cr

The debug said stp = 1.· I don't understand it, but I know it works.· Of course, I guess you don't have to know how everything works, just how to use it.

Maybe some day.........................

Sid

Newzed
06-15-2005, 03:52 AM
I just figured it out.

1//4 really means (0), 1 or 1/4 = 0 with 1 left over.

Now, wasn't that easy?

Sid

Jon Williams
06-15-2005, 04:12 AM
Two things to remember...

1) The code I post is usually tested and working· http://forums.parallax.com/images/smilies/tongue.gif
2) The BASIC Stamp evaluates from left to right unless parenthesis are used, so....

··· stpIdx = stpIdx + 1 // 4

··· ... causes stpIdx to be incremented by 1 before divided by 4.· Since the modulus operator is used, the final result of the equation is the remainder of the division.

Do this as a test:

Main:
· DO
··· stpIdx = stpIdx + 1 // 4
·· ·DEBUG DEC stpIdx, CR
··· PAUSE 500
· LOOP

And here's a trick for making the values loop and wrap-around the other direction:

Main:
· DO
··· stpIdx = stpIdx +·3 // 4
·· ·DEBUG DEC stpIdx, CR
··· PAUSE 500
· LOOP
···
I'll leave it to you to figure out why it works (this is one of my favorite "tricks").

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Newzed
06-17-2005, 04:07 AM
Jon, if I increase the delay in your program from 15 to 30 the shaft will turn at half speed.· Will this make it jerky?· I don't know how fast the motor shaft turns and I might want to slow it down.· Just looking ahead.

Sid

Jon Williams
06-17-2005, 04:21 AM
I don't know, Sid, why don't you give the stuff a try?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Ryan Clarke
06-17-2005, 04:35 AM
Too bad PBasic doesn't use the % for modulus ;) *teasing*

At least it's better than having to type MOD all the time -

Ryan

Newzed
06-17-2005, 08:46 PM
I have been studying the stepper program above and it looks like power is applies to each winding for 15ms plus overhead.· Decreasing 15 would make it step faster, increasing 15 would make it step slower up to the point where travel became jerky.

Does anyone have an idea how to convert this program from full step to half step, or can it even be done with a Stamp.· I think I remember reading that windings must be pulsed for a minimum of 5us - there was no reference to a max pulse.

Sid

Bean
06-17-2005, 08:58 PM
The pulse time depends on how fast you want the motor to turn.
Stepper motors can turn as SLOW as you want (including standing still), so there is no maximum pulse time.

BUT...
Because of inertia you should start moving at a slower speed then ramp the speed up. Same with stopping, you should ramp the speed down before you stop. Remember steppers have the more torque at·slower speeds.

Some stepper control systems change the current to the stepper too, at startup and stop current is increased. When stopped or moving slowly current is decreased.

With the stamp alone, you probably cannot pulse the stepper too fast.
Bean.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95

http://www.parallax.com/detail.asp?product_id=30012

Product web site: www.sxvm.com (http://www.sxvm.com)

"What's the difference between ignorance and apathy ?"
"I don't know, and I don't care."
·

Newzed
06-17-2005, 09:20 PM
Thanks, Bean.· I'll add a ramping sequence to my program - will double pause for first 100 steps be adequate?

Can you help on the half-step thingie?

Sid

Jon Williams
06-17-2005, 09:29 PM
Half stepping is indeed possible -- but the stepper loses torque when you do that.· What you need to do is change the table to half steps, and update the step routine (the modulus value will be eight instead of four).·

This is what a half step table looks like:

Step1·········· DATA··· %1000
Step2·········· DATA··· %1100
Step3·········· DATA··· %0100
Step4·········· DATA··· %0110
Step5·········· DATA··· %0010
Step6·········· DATA··· %0011
Step7·········· DATA··· %0001
Step8·········· DATA··· %1001


And the code to use it:

Step_Fwd:
· sAddr = sAddr + 1 // 8
· READ (Step1 + sAddr), Coils
· PAUSE speed
· RETURN

Step_Rev:
· sAddr = sAddr +·7 // 8
· READ (Step1 + sAddr), Coils
· PAUSE speed
· RETURN

(This happens to be from StampWorks 1.2)

As a reminder ... Google (http://www.google.com) is your friend.· I have found a lot of interesting stepper projects and resources with a just·a few minutes of web searching.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Post Edited (Jon Williams (Parallax)) : 6/17/2005 2:33:15 PM GMT

Newzed
06-27-2005, 12:04 AM
Jon's stepper program, posted way up above, is for a unipolar.· I have another stepper with four wires so it must be bipolar.· Could I use Jon's program to run a bipolar?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html

·

Jon Williams
06-27-2005, 12:41 AM
Yes, you can use the same code -- with a different driver.· Using the L293D (on the PDB and I know you have one) can be used to drive unipolar or bipolar steppers (since the L293D outputs are driven in both directions).·

This N&V article should help: http://www.parallax.com/dl/docs/cols/nv/vol6/col/nv121.pdf

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Newzed
06-27-2005, 01:34 AM
Thank you very much, Jon.· Just what I needed.· The wire switch trick for the bipolar makes life easy.

I see the L293D is rated at 36 VDC.· Can I apply up to this voltage to the V+ screw terminal?

If I increase the delay the stepper runs slower but has more torque.· Is this correct?

Sid

Newzed
06-29-2005, 08:25 PM
I got my little stepper wired up and running with Jon's sample code.· The problem is that 48 steps turns it 1/2 revolution.· The phases were identified according to the info here:

http://www.doc.ic.ac.uk/~ih/doc/stepper/others/

The stepper appears to run quite smoothly -· is it possible that one of the phases is incorrectly identified?

Thanks

Sid

Newzed
06-30-2005, 07:22 PM
Jon's program uses

Phase··· VAR· OUTB

and

DIRB = %1111

which makes things very neat.

I have a old BS2 I would like to dedicate to running one of my biploar steppers.· Unfortunately some of the pins are damaged and I do not have DIRA or DIRB available.· I do have Pins 0, 1, 6 and 7.· Can I write:

Phase··· VAR OUTL

and then

DIRL = %110000011

Thanks

Sid

Jon Williams
06-30-2005, 07:29 PM
Of course you can, but using OUTL like that affects eight pins at a time (some that may be needed for other things).· I would be more inclined to write a subroutine where the coil output pins are named and grab the bit values from the step table.· Something like this:

Do_Step:
· READ (Steps + stpIdx), coilData
· Coil1 = coilData.BIT0
· Coil2 = coilData.BIT1
· Coil3 = coilData.BIT2
· Coil4 = coilData.BIT3
· PAUSE stpDelay
· RETURN


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Newzed
06-30-2005, 07:41 PM
Like this:

Coil1· ·PIN 0
Coil2·· PIN 1
Coil3·· PIN 6
Coil4·· PIN 7

then

Output 0
Output 1
Output 6
Output 7

and to rest of program using the modified Do_Step.

Sid

Jon Williams
06-30-2005, 07:57 PM
Yep. Or you can set the outputs with DIRS since that usually needs to happen just once.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Newzed
06-30-2005, 11:14 PM
Can anyone ghive me an estimate of how much power I would lose if I ran a bipolar at half-step instead of full step?

Thanks

Sid

ChipCircuit
07-01-2005, 02:22 AM
Exactly the same or double, depending on the driver circuit.

Each phase is energized for a half step.

There are different types of driver circuits, and some will actually use full power on both phases at the same time, others will use half power on each phase.

But, if you size your power supply to the total watts of the two phases, you are set.

Dave

Newzed
07-01-2005, 03:48 AM
I am driving with a BS2 and an L293D, running the motor at 12VDC for the moment'

Sid

Newzed
07-01-2005, 04:12 AM
I modified Jon's N&V Col.121 BS1 program to run on a BS2, driving an L293D.· Both enables are pulled high and I have 12VDC on Pin 8 of the L293.· I debugged StpIdx and Phase and am getting all the right numbers.

However, the motor doesn't run.· I hooked up my scope and am getting input signals on the four inputs but no signal of any kind on the four outputs.

Would you say I had a bad L293?

I'm sure the program is OK, but I have attached it anyway.

Sid

cyberbiota
07-01-2005, 08:40 AM
Sid-

Are the Stamp and motor grounds shared and connected to the '293?

peter

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Peter C. Charles

Director, Research and Technology
CyberBiota, Incorporated
Peter.charles@cyberbiota.com (mailto:Peter.charles@cyberbiota.com)
http://www.cyberbiota.com (http://www.cyberbiota.com)

Newzed
07-01-2005, 06:14 PM
Yes - I'm running off of Vin right now.

Sid

Newzed
07-03-2005, 05:31 AM
I am trying to come up with a circuit to drive a bipolar but I'm not having much luck.· It is too big for the L293 on my PDB.· I'm not looking for a Gecko type controller - I just want to make the thing run.· The biggest chips I have are TIP120s.· Resistance of each phase pair is about 7.7 ohm, so at 18VDC it is going to draw about 2.3 amps.· Can anyone help - nothing fancy - all I want to do is run the thing.

Sid

Larry
07-03-2005, 05:48 AM
The L298N chip is pin compatible with the L293N and will handle up to·4 amps with proper heat sinking.
The N version of this chip requires external doides.

you can also reduce the power consumption (and power of the motor) by adding small resistors in line with the coils. it is a good choice if you don't need all the power of the motor.


A fancier driver·couples ·the 297 controller chip· with the L298N and features a chopper drive-- but you said "nothing fancy"

Larry

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


Post Edited (Larry) : 7/2/2005 10:54:07 PM GMT

Newzed
07-03-2005, 06:21 AM
Thanks for the suggestion, Larry.· If I add the 8 external diodes, do I wire this up·just like my L293?· Can I use the same program to drive the L298?

With the staggered pins this chip won't plug into a breadboard - probably have to have a PC board made.· Guess it would be simpler if I could find a used controller somewhere.· Anyway, thanks - this is the only possibility I have right now.

Sid

Larry
07-03-2005, 07:33 AM
Here are the pinouts and datasheet that will show the diode ladder arrangement. Schematically, it's the same as the 293. the same program would work, too.

http://www.hvwtech.com/pages/products_view.asp?ProductID=198

I've done a "dead Bug" quicky implimentation that worked well enough that it is still in a robot. I soldered the pins directly to Radio shack terminal connectors and the other bits.

As I recall, the pins will fit into a proto board on the diagonal with a bit of tweaking if you want something more substantial. then use wire wrap wire to connect everything.


Larry

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Newzed
07-04-2005, 01:49 AM
Larry, the Super Carrier Board has a row of staggered pads on the right edge - the L298 should drop right in.· I'll order one and make that board my dedicated bipolar driver.· Not bad for $20.00http://forums.parallax.com/images/smilies/yeah.gif

Thanks again for the suggestion.

Sid

Newzed
07-04-2005, 05:11 AM
Larry, go to this site:

http://www.solarbotics.com/

Click on Kits and scroll down to Kit #13 - The L298 Motor Driver.· This looks like the answer and only $17.95!

Sid

Mike Cook
07-04-2005, 09:06 PM
Sid,

If you want to use your TIP120 transistors to drive your stepper motors you can try this. I have built a driver circuit to test my 100 oz steppers for my wood CNC router. Used the diagram found here:

http://eio.com/jasstep.htm#intro (Figure 2.1)

The circuit uses TIP110 which I replaced with TIP120. I also replaced the 7406 with four 2N3906 transistors. You'll need to use a resistor on the 2N3906 when connecting to the stamp. Using one of Jon's stepper motor programs to drive the stepper motor using a BS2 (P4, P5, P6, P7). Works pretty well for testing the motors, but will probably end up using www.hobbycnc.com (http://www.hobbycnc.com) 4AUPC boards to eventually control the router using TurboCNC for the G-Code.

Attached is the code that I'm using to drive the motor.

Mike





▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"OEM NMEA GPS Module" Now available on ebay for only $19.99

Product web site: http://www.allsurplus.net/Axiom/

Newzed
07-04-2005, 11:17 PM
Mike, why did you add the four external diodes.· The TIP is a Darlington and already has clamp diodes.

Sid

Mike Cook
07-05-2005, 12:28 AM
Sid,

Was not sure if I needed them or not, so put them in anyway. Seems to function ok. Like I said this is just to test the motors. Since I will be using TurboCNC to drive the completed machine, I will be using the 4AUPC to drive these motors @ 28 VDC.

Mike

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"OEM NMEA GPS Module" Now available on ebay for only $19.99

Product web site: http://www.allsurplus.net/Axiom/