Basic Program for Stepper Motors
NWUpgrades
Posts: 292
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
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
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
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?
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
A) StpIdx is directed to receive the result.
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
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
1//4 really means (0), 1 or 1/4 = 0 with 1 left over.
Now, wasn't that easy?
Sid
1) The code I post is usually tested and working·
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
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
At least it's better than having to type MOD all the time -
Ryan
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
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
"What's the difference between ignorance and apathy ?"
"I don't know, and I don't care."
·
Can you help on the half-step thingie?
Sid
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 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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
This N&V article should help: http://www.parallax.com/dl/docs/cols/nv/vol6/col/nv121.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
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
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
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
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
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
Applications Engineer, Parallax
Thanks
Sid
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
Sid
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
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
http://www.cyberbiota.com
Sid
Sid