How to make two steppers work simultaneously?
Loola Lindgren
Posts: 8
How to make two steppers work simultaneously?
Hi, I am at the starting point of building a coil-winding machine driven by two steppers that’s to be controlled by a BS2. The mechanical part of this project is no problem, but I hope to get some help writing the code to make my BS2 control two steppers working simultaneously. I have only managed to get them to work one or the other, never simultaneously.
·
····················· ·····················
Winding process
The mechanical part in theory would be that stepper-A rotates the coil while stepper-B through a mechanical device is guiding the wiring to even layers on the coil. That takes a code that is able to do something like this: Stepper-A starts at a speed of (let’s say) 100 revs/minute and stops when reached 1000 complete revs. Stepper-B starts at the same time as stepper-A at a speed of (let’s say) 10 revs/minute. When stepper-B has completed 10 revs it changes direction, and after 10 more revs it changes direction again, and so on until 10 direction changes are completed. The finished winded coil would have 10 layers of 100 revs/layer with a total of 1000 revs.
·
·
Hardware
Micro controller: Basic Stamp 2
Stepper: 200 steps/rev
Driver for the stepper: 2 inputs, step and direction (TTL)
·
·
If anyone should be able to help me out with this coding issue, then I just would like to point out that the code don’t have to match this above given example. But the code has to meet these specs.
·
1. It has to be able to simultaneously control 2 steppers
2. Be able to work with stepper drivers that use step and direction commands.
3. The movements on the steppers will be specified by a certain amount of steps rather then a certain amount of revs.
4. Changes that have to be made in the code to meet different specs on different coil sizes should be done only by changing numeric values (example: # of steps to be taken with stepper-A to complete the right amount of wiring revs. # of steps between direction changes on stepper-B. The speed on stepper-B has to be easily changed too).
·
Ramping of the steppers would also be nice, but not necessary, thou the load and speed is low.
I hope that I have been able to explain this issue clear enough for you to understand and that I not just have left you with a lot of question marks in your head J
Complete code, parts of, or just comments would be greatly appreciated.
Kind regards,
Loola Lindgren
Sweden
Post Edited (Loola Lindgren) : 4/6/2008 8:55:19 AM GMT
Hi, I am at the starting point of building a coil-winding machine driven by two steppers that’s to be controlled by a BS2. The mechanical part of this project is no problem, but I hope to get some help writing the code to make my BS2 control two steppers working simultaneously. I have only managed to get them to work one or the other, never simultaneously.
·
····················· ·····················
Winding process
The mechanical part in theory would be that stepper-A rotates the coil while stepper-B through a mechanical device is guiding the wiring to even layers on the coil. That takes a code that is able to do something like this: Stepper-A starts at a speed of (let’s say) 100 revs/minute and stops when reached 1000 complete revs. Stepper-B starts at the same time as stepper-A at a speed of (let’s say) 10 revs/minute. When stepper-B has completed 10 revs it changes direction, and after 10 more revs it changes direction again, and so on until 10 direction changes are completed. The finished winded coil would have 10 layers of 100 revs/layer with a total of 1000 revs.
·
·
Hardware
Micro controller: Basic Stamp 2
Stepper: 200 steps/rev
Driver for the stepper: 2 inputs, step and direction (TTL)
·
·
If anyone should be able to help me out with this coding issue, then I just would like to point out that the code don’t have to match this above given example. But the code has to meet these specs.
·
1. It has to be able to simultaneously control 2 steppers
2. Be able to work with stepper drivers that use step and direction commands.
3. The movements on the steppers will be specified by a certain amount of steps rather then a certain amount of revs.
4. Changes that have to be made in the code to meet different specs on different coil sizes should be done only by changing numeric values (example: # of steps to be taken with stepper-A to complete the right amount of wiring revs. # of steps between direction changes on stepper-B. The speed on stepper-B has to be easily changed too).
·
Ramping of the steppers would also be nice, but not necessary, thou the load and speed is low.
I hope that I have been able to explain this issue clear enough for you to understand and that I not just have left you with a lot of question marks in your head J
Complete code, parts of, or just comments would be greatly appreciated.
Kind regards,
Loola Lindgren
Sweden
Post Edited (Loola Lindgren) : 4/6/2008 8:55:19 AM GMT
Comments
http://www.parallax.com/Portals/0/Downloads/docs/prod/motors/Stepper_Motor_27964.pdf
the BS2 example code allows for forward/reverse , number of steps and a delay that can be used for ramp.
Jeff T.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
The Parallax Servo Pal will do exactally what you want. Check it out. The two I have are great!
http://www.parallax.com/Store/Accessories/MotorServoControllers/tabid/160/ProductID/481/List/1/Default.aspx?SortField=ProductName,ProductName
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
D. A. Wreski
·
The stepper driver boards·are not Parallax item they are custom build. The inputs are TTL.
One pulse on the “step pin” generates one step on the stepper.
High level (5 volts) on the “dir pin” generates CWW rotation on stepper, and low level (0 volts)
generates the opposite direction.
·
·
Thanks for a fast reply!
·
Loola
Post Edited (Loola Lindgren) : 4/6/2008 8:57:08 AM GMT
·
This is not quite what I am looking for. This link describes a code used to control a different kind of driver board. This set-up will use 4 pins on the BS2 to work with one stepper. My set-up needs only 2 pins from the BS2. One pin for step (one high TTL level gets one step on stepper). One pin for direction, high level (5 volts) on the “dir pin” generates CWW rotation on stepper, and low level (0 volts) generates the opposite direction. The circuit at the end of my driver board, where I connect my stepper, is PBL3717. It takes two of these to “feed” one stepper.
·
To describe this coding issue more clearly, this is the code that I have trying to change to suite my needs. This code will make one stepper move 10 steps, change direction and do 10 steps, change direction again, and so on.· I need to get one more stepper to work simultaneously with this one. Any suggestions?
·
' {$STAMP BS2}
' {$PBASIC 2.5}
·
StepperDir····· PIN···· 0······················ ' direction control
StepperMove···· PIN···· 1······················ ' movement
·
CW············· CON···· 0
CCW······· ·····CON···· 1
·
idx············ VAR···· Byte
·
Reset:
· OUTPUT StepperDir
· HIGH StepperMove····························· ' move on high-to-low transition
·
Main:
· StepperDir = CW
· FOR idx = 1 TO 10
··· PULSOUT StepperMove, 500
··· PAUSE 500
· NEXT
·
· StepperDir = CCW
· FOR idx = 1 TO 10
··· PULSOUT StepperMove, 500
··· PAUSE 500
· NEXT
·
· GOTO Main
·
This might work, I'm not a great programmer so I have to run my code through the editor several times before I get all the errors out of it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
·
Thank you for the effort you have put in to this.
·
I am not skilful enough at Pbasic coding to tell if you are on to something here. But it looks interesting to me. But sorry to say when I tried to run your code in my Stamp editor (V 2.4) it halted at line 17. I changed “steppermove” to stepper1move and then it halted at line 20 so I changed that to stepper2move and run it again. This time it halted at line 24, and there I’m lost. Are my Stamp editor V 2.4 out of date, or is this a coding issue?
Any suggestions Stephen?· (Or anyone else for that matter)
·
·
Regards,
·
Loola L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I am 1010, so be surprised!
Many thanks to Stephen and tpw_man, with their help we now have a code that look like the one below. It’s a good start, but we are not really there yet. I need to be able to adjust the speed on stepper1 independently of what speed the stepper2 are at, and I am not able to do that with this code.
And I would like to have the counter (cnt) “connected” to stepper2 only.
Anyone out there who have a clue?
Kind regards,
Loola Lindgren·· Sweden
' {$STAMP BS2}
' {$PBASIC 2.5}
Stepper1Dir····· PIN···· 0······················ ' direction control
Stepper1Move···· PIN···· 1······················ ' movement
Stepper2Dir····· PIN···· 2······················ ' direction control
Stepper2Move···· PIN···· 3······················ ' movement
CW············· CON···· 0
CCW············ CON···· 1
idx············ VAR···· Byte
cnt··· VAR· Byte
·Reset:
· OUTPUT Stepper1Dir
· HIGH Stepper1Move····························· ' move on high-to-low transition
· OUTPUT Stepper2Dir
· HIGH Stepper2Move····························· ' move on high-to-low transition
· Stepper2Dir = CW
· cnt = 0
·Main:
· IF cnt = 100 THEN END
· Stepper1Dir = CW
· FOR idx = 1 TO 10
· PULSOUT Stepper1Move, 500
· PULSOUT Stepper2Move, 500
· PAUSE 500
· NEXT
· Stepper1Dir = CCW
· FOR idx = 1 TO 10
· PULSOUT Stepper1Move, 500
· PULSOUT Stepper2Move, 500
· PAUSE 500
· NEXT
· cnt = cnt + 1
· GOTO Main
Post Edited (Loola Lindgren) : 4/7/2008 4:09:56 PM GMT
·
Show me I’m wrong.
·
·
Regards,
·
Loola
Jeff T.
The·idea is that since the Stamp is single-tasking, so it quickly moves stepper A, then·stepper B, counts, then changes direction.·· I hope this helps.
'·{$STAMP·BS2}
'·{$PBASIC·2.5}
Stepper1Dir······PIN·····0·······················'·direction·control
Stepper1Move·····PIN·····1·······················'·movement
Stepper2Dir······PIN·····2·······················'·direction·control
Stepper2Move·····PIN·····3·······················'·movement
CW··············CON·····0
CCW·············CON·····1
idx····VAR··· WORD
cnt····VAR··· WORD
NumstepA····· VAR··· WORD
NumstepB····· VAR WORD
Numstep1····· VAR WORD
Numstep2····· VAR WORD
Reset:
··OUTPUT·Stepper1Dir
··HIGH·Stepper1Move· ·············'·move·on·high-to-low·transition
··Stepper1Dir = CW
··OUTPUT·Stepper2Dir
··HIGH·Stepper2Move···············'·move·on·high-to-low·transition
··Stepper2Dir·=·CW
· Idx = 0
· NumstepA = 100·········· ‘place holder for number of steps on Stepper A
· NumstepB = 10····· ······ ‘Place holder for number of steps on Stepper B
Numstep1 = NumstepB· · ···········
Numstep2 = Numstep1
Main:
DO UNTIL NumStepA = 0
FOR idx = 1 to numstep1
TOGGLE Stepper1Move······· ‘High to Low
TOGGLE Stepper2Move
TOGGLE Stepper1Move······· ‘Low to High
TOGGLE Stepper2Move
PAUSE 10
NEXT
Stepper2Dir = CCW········· ‘Reverses Stepper B’s direction
NumstepA = NumstepA-NumstepB····· ‘Subtracts to account for steps already done
Idx = 0
FOR idx = 1 to Numstep2
TOGGLE Stepper1Move
TOGGLE Stepper2Move
TOGGLE Stepper1Move
TOGGLE Stepper2Move
PAUSE 10
NEXT
Stepper2Dir = CW·········· ‘Reverses Stepper B’s direction
NumstepA = NumstepA-NumstepB····· ‘Subtracts to account for steps already done
LOOP
·
END
·
·
I have just finished testing your code with my steppers, and I like your work on the code very much. But there still is a big issue to be solved. Because I’m not able to adjust the speed individually on the steppers. I can change the speed by changing the value of the PAUSE command. But that changes the speed equal on both steppers.
Question: Is it possible to have different PAUSE values for each stepper i.e. one value for “Stepper1move” and a different value for “Stepper2move”. If so, could this be a way to have different speeds on the steppers.
·
Regards,
·
Loola L
If the above doesn’t work, then you have a few other options:·
1)····· Use the Stamp to control an external oscillator, which will feed your stepper controller.· To do this, build an “astable multi-vibrator” (maybe using a 555/556 timer?) to generate the move signal for your motors.· (A frequency generator will work nicely too!)· Feed this signal into both clock inputs of a “Dual J-K Flip-Flop”; tie the J, K and pre-set inputs high, through a resistor.· The Stamp will control the reset line for each flip-flop separately.· The Stamp will also continue to control the direction.· To let the motors move, just hold the flip-flop reset line high, which lets the move signal go through it.· To pause or stop a motor, bring its flip-flop’s reset line low, which will stop the move signal from going through, and stop the stepper motor.· You can do the same thing using any tri-state logic chip in place of the flip-flop, such as 74LS240, 74LS241 or 74LS244.· Just use the Stamp to place the chip into tri-state (aka high-Z) mode, which will stop the clock signal.· Upside, separate control of each motor, with the ability to do separate pauses and direction control.· Downside, harder to vary speed, since your frequency source would be fixed and no positive way to control the number of steps taken.· You may be able to quickly pulse the reset lines to gain some speed control, and the stamp may be able to COUNT the number of pulses and control the motors as needed, but again, if the Stamp is counting pulses, it can’t do anything else, which may lead you back to your original problem!
2)····· Add a “slave stamp.”· Each Stamp will control a motor, with a master and a slave.· The master Stamp will process your inputs for both motors, and pass-to the slave what it needs to know.· The slave would wait in a loop, looking for the data from the master.· Once the slave received the data and was ready, it would signal the master.· Then the master would tell it to “go”, and both Stamps would start their motors.· Bill Chennault, here on the forums, has already done something very similar to this.· Upside, complete control over the motors’ speed, direction and pauses.· Downside, cost and complexity.
3)····· Change controllers, to something like the MoBo Stamp PE, an SX-48 (programmed in SX/B) or the Propeller.· The MoBo Stamp PE incorporates a Stamp and two co-processors.· Each co-processor can be programmed to control a motor.· The SX-48 has two background timers, which could be used for motor control.· Upsides, really fast single-module solutions with complete control of frequency, direction, and pauses for both motors simultaneously.· With the Propeller, you could even drive a TV for a display!· Downside, initial cost, since you have to buy completely new hardware.· For the SX-48 and Propeller, you’d also need a programming device and with the Propeller, learn a new programming language.
MoBo Stamp PE:· http://www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/CategoryID/9/List/0/SortField/0/Level/a/ProductID/451/Default.aspx
SX-48:· http://www.parallax.com/Store/Microcontrollers/SXDevelopmentBoards/tabid/141/CategoryID/54/List/0/SortField/0/Level/a/ProductID/362/Default.aspx
Propeller:
http://www.parallax.com/Store/Microcontrollers/PropellerDevelopmentBoards/tabid/514/CategoryID/73/List/0/Level/a/ProductID/423/Default.aspx?SortField=ProductName%2cProductName
4)····· Overall, your project has a lot in common with home-brew CNC milling.· You need complete control over multiple stepper motors at the same time.· Check out some of those resources and programs.· Depending on your skill and resources, you could program a spare computer to control the steppers.· The computer would replace the Stamp.· Even an old notebook or PDA may work for you; the hardest part is done, interfacing to the motors.· Since a computer is much more powerful than a Stamp, speed control, pauses and multi-tasking should be no problem.
I hope this helps, or least gives you good ideas!
·
Let me start by saying how much I really appreciate your help with this.
·
The amount of adjustment I need is about 60 rpm to 300 rpm.
And it looks like the BS2 is not capable of satisfying my needs there.
·
Like you suggested, I have tried to run my steppers trough a PC with CNC software (Kcam 4. the step and dir signals is taken from the parallel port), and yes they are running independently. But know a different problem appears. There is no accuracy in the steppers behaviour. They are losing steps and then the repeatability is lost (and that have to be spot on). I have spent hours trying to solve the problem with no success. If Windows XP or Kcam causes the problem, I do not know.
·
Earlier in this thread, servos were mentioned as another approach to the problem. I do not have any knowledge or hardware in this matter. But would it be any easier to create code for two servos that have to spin at different steady speeds and one has to change directions repeatedly, then it is to write code for two steppers? And how about repeatability, is that spot on when it comes to servos?
·
Is there anyone who has tried to control steppers trough PC and CNC software with good result? ··What software did you use?
·
·
Regards,
·
Loola Lindgren·
Sweden
I know this is not ideal and more expensive, but it seems as though it should work.