View Full Version : A little Stepping motor Help
05-22-2010, 02:12 AM
A little Stepping motor Help is needed.
I am running the code below and it works great. it basically runs 2 times in the repeat loop (Full Step). The idea is that I will store the byte array "StepArray" in eeprom for dynamic reasons. Now instead of running 2 times I want to run it once so that I can half step. My problem is that I cant get a bit pattern "StepArray" that works for 1/2 stepping.
Any ideas ?
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
StepMotor1 = 9 'A-
StepMotor2 = 10 'B-
StepMotor3 = 11 'B+
StepMotor4 = 12 'A+
Byte StepArray [ 8 ]
Dira [ StepMotor1..StepMotor4 ]~~
StepArray [ 0 ] := %1010 '
StepArray [ 1 ] := %0110
StepArray [ 2 ] := %1001
StepArray [ 3 ] := %0101
StepArray [ 4 ] := %1010 ' same as above in full step mode
StepArray [ 5 ] := %0110 ' same as above in full step mode
StepArray [ 6 ] := %1001 ' same as above in full step mode
StepArray [ 7 ] := %0101 ' same as above in full step mode
outa [ StepMotor1..StepMotor4 ] := StepArray [ 0 ]
outa [ StepMotor1..StepMotor4 ] := StepArray [ 1 ]
outa [ StepMotor1..StepMotor4 ] := StepArray [ 2 ]
outa [ StepMotor1..StepMotor4 ] := StepArray [ 3 ]
outa [ StepMotor1..StepMotor4 ] := StepArray [ 4 ]
outa [ StepMotor1..StepMotor4 ] := StepArray [ 5 ]
outa [ StepMotor1..StepMotor4 ] := StepArray [ 6 ]
outa [ StepMotor1..StepMotor4 ] := StepArray [ 7 ]
waitcnt((clkfreq / 10_000) * Delay + cnt)
05-22-2010, 02:31 AM
I've always used two arrays for stepping: one for full steps, the other for half steps. What you might want to do is create routines like this:
outa[COIL4..COIL1] := FullSteps[++stpIdx // 4]
outa[COIL4..COIL1] := FullSteps[(stpIdx += 3) // 4]
outa[COIL4..COIL1] := HalfSteps[++stpIdx // 8]
outa[COIL4..COIL1] := HalfSteps[(stpIdx += 7) // 8]
FullSteps byte %0011, %0110, %1100, %1001
HalfSteps byte %0001, %0011, %0010, %0110
byte %0100, %1100, %1000, %1001
You can easily move a block of 12 bytes from the EEPROM into the table (@FullSteps) to change the table for a given motor.
05-22-2010, 02:42 AM
Problem is that using data in the DAT section makes my code not update-able. I like to store most variables in the 12c EEprom. This allows my firmware to be updated sort of like Microsoft will do with windows.
What I am after is a pattern of %1s and %0s to half step that is derived from the code above that I posted. I have the full step working with said code its trying to do half stepping.
Another way of asking...
If I can full step using this
SepArray Byte %1010, %0110, %1001 , %0101
How can I half step?
Post Edited (Zap-o) : 5/21/2010 6:47:37 PM GMT
05-22-2010, 04:16 AM
Not so, Zap-o. As I indicated, at start-up your program would read the step data out of the EEPROM and then write it into the DAT tables. Now, as you're running, you're using RAM which is fast instead of the EEPROM (slow....). I'm all about updating -- I'm working on a product for EFX-TEK that lets our customers install a firmware upgrade by dropping a file onto the SD card. At the beginning of the program I look for that file; if it's there I copy it to the EEPROM, erase it (to prevent a loop), and then reboot the Propeller with the new code. In your case the process easier: just reading 12 bytes, and if you align them on a page boundary you can do it very easily with a page read.
Perhaps you don't understand the full-step/half-step thing. Full steps engage two coils, half steps engage just one. I've never seen any stepper code that used the full-step table for half steps. Even if you could come up with an algorithmic solution, chances are that it would be far less elegant (and maintainable) than a two-table solution.
05-22-2010, 08:14 AM
Yea I am a bit lost on the half step concept. Mainly because a stepper motor can be wired up several ways hence my desire to keep my program flexible at run time. I have a solution that allows me to update my code while the propeller is running and store this update permanently in EEprom. This allows the customer or me to tweak all settings versus me sending them a firmware upgrade - sort of like plug and play. The example code I posted above is just an example for simplicity. True its not elegant :)
I appreciate the explanation of full step vs. half step. I think I am understanding the concept clearer.
05-22-2010, 09:03 AM
Another thing to keep in mind is that DAT tables work just like arrays -- you can update them on the fly and then save them back out to an EEPROM. For me, I like to use them because a DAT table is an array that you can pre-initialize in code.
I'm not sure what you mean "wired up several ways" -- for correct motion you need to wire the coils in the correct order. I seems like you're trying to add flexibility to your code so you can allow the coils to be wired willy-nilly; do you really want to do that?
05-22-2010, 09:06 AM
Here's my unipolar stepper test code:
My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
My Prop Products:· http://www.rayslogic.com/Propeller/Products/Products.htm
05-22-2010, 10:39 AM
Yea I don't want to "willy nilly" the coils but you never know what a customer is going to do and once the motor is installed its a night mare to un-hook everything. I work with grad students and as smart as some are I am always amazed at how the small things hang them up.
Ill look over the code example
Gents - thanks for the help
05-22-2010, 10:55 AM
You are a brave soul. If you get it working, do post -- I'd like to see what you come up with.
For further reference I wrote about controlling steppers in my column a few years ago:
-- www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol7/col/NV136.pdf (http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol7/col/NV136.pdf)
This shows how to write a Spin method that you can launch into its own cog, letting it run "in the background" while your main program does other things.
05-23-2010, 12:01 AM
as you want to keep it very flexible. How about ONE array that contains both. I'm not too familiar with the details of fullstep/halfstep if my assuming that
halfstep switches on one coil A then two coil A and coil B then switches off coil A etc. you would store this pattern in an array
and for fullstepmode you would not use
index 1 coil A on B off
index 2 coil A and B on
index 3 coil A off B on
index 1 coil A on B off jump over index 2 right to
index 3 coil A off B on
you said something you don't want to use the DAT-section
Whenever you store a program to the EEPROM EVERYTHING of your code gets stored in the EEPROM including all DAT-sections
now if you are worried about the adresses you could store your values at the upperend of the RAM/EEPROM
the "ultrahyper-felxible" solution that allows your customers to wire whatever they want has its price by having more hardware with autodetecting everything wiring uni/bipolar number of coils etc. etc.
set a limit to the flexibility and describe it very well in the manual. If you write an EASY to understand manual your customers will be very happy and follow and obey your restrictions described in the manual.
(most manuals are written very fast and are more a repetitorium to the author than a manual you can learn from)
How about a hardware that allows halfstepping and can be switched by software to fullstepping?
05-23-2010, 09:01 AM
The "ultra-flexible" method requires some sort of UI to allow for coil configuration -- that's the tricky bit, I think, and will "cost" are more than simply having the coils wired in the correct order to start with.
Even if wired incorrectly, you can get there without know the details of the motor; the process is explained here:
-- digital.ni.com/public.nsf/allkb/0AEE7B9AD4B3E04186256ACE005D833B (http://digital.ni.com/public.nsf/allkb/0AEE7B9AD4B3E04186256ACE005D833B)
And my memory tells me to do this if the motor doesn't move or just vibrates/buzzes:
A) Swap outer leads -- if that doesn't work, then...
B) Swap inner leads -- if motor runs backward then...
C) Flip all