This is more a theoretical question than an actual problem at the moment. I am controlling a stepper motor that has an 8 step pattern (steps 1 through 8):
1000
1100
0100
0110
0010
0011
0001
1001
This works fine. I can make it go forwards and backwards, etc. as I want. If I try to skip more than two half steps, the motor does nothing. If I stop the motor at an odd position, like step 5, and then later restart if using the pattern of step one, the motor continues like there is no problem.
How does the motor "reset" itself? Or, how does the motor start with 0001 each time, even though it may have been left in another position?
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
control_pins = [7,11,13,15]
for pin in control_pins:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, 0)
halfstep_seq = [
[1,0,0,0],
[1,1,0,0],
[0,1,0,0],
[0,1,1,0],
[0,0,1,0],
[0,0,1,1],
[0,0,0,1],
[1,0,0,1]
]
for i in range(512):
for halfstep in range(8):
for pin in range(4):
GPIO.output(control_pins[pin], halfstep_seq[halfstep][pin])
time.sleep(0.001)
GPIO.cleanup()
But the problem is not where the code tells the motor to start. The question is if I leave the motor at step 5, why does the motor start with no problems when I start from step 1.
jaketh:
This is more a theoretical question than an actual problem at the moment. I am controlling a stepper motor that has an 8 step pattern (steps 1 through 8):
1000
1100
0100
0110
0010
0011
0001
1001
This works fine. I can make it go forwards and backwards, etc. as I want. If I try to skip more than two half steps, the motor does nothing. If I stop the motor at an odd position, like step 5, and then later restart if using the pattern of step one, the motor continues like there is no problem.
How does the motor "reset" itself? Or, how does the motor start with 0001 each time, even though it may have been left in another position?
Thanks
Looks like the program used in the Arduino education kit I purchased years ago off Ebay. The Arduino is wired directly to the tiny stepper motor. I think if you add a 2 second pause between step you will discover the motor will not move until the correct next pattern is processed.
But if I leave the motor at step 5 and power down and then restart at step 1, everything works. So what happened between powering down and restarting that either 1) allowed the motor to move from step 5 to step 1 or else 2) some how adjusted something so that the code for step 1 was somehow shifted to step 5.
It will jump a step to get to the nearest "copy" of step 1000. It may go forwards or backwards. It does it so quickly you can't see it.
You also get the same thing when you switch it off. When it is off you can turn the shaft and feel steps. Those steps are twice as big as the steps it makes when it is operating. If you switch off on an odd-numbered step it will fall onto an even step.
You wrote "It will jump a step to get to the nearest "copy" of step 1000. "
I do not understand what you mean exactly. That seems like it would create errors in any step counting program, or any positioning program really. (Note: I can think of work arounds for this and for the program I am using it isn't a problem because I initialize the mirror positions on every start up and then I track the steps.)
It may help for you to understand how steppers work. Everything, and I mean everything, is described here Jones on steppers.
For a two phase stepper in half step mode, which is what you are doing, there are four "copies" of step 1000 and four "copies" of step 1100. The motor can distinguish between the two sets, but not the individual copies in each set.
I think I understand stepper motors, not in the deep sense that an electrical engineer does maybe but I have read a lot and have no problems making them work.
The problem I have (had) is just the step starting/stopping problem. To be more specific, what I understand now is that if I stop on 0010 and then try to turn the motor by calling 1000, the motor doesn't step. So if I stop the motor at 0010 and then call a movement method that starts with 1000, the motor just sits there for the first few steps until a step is reached that the motor responds to. From that step onwards, everything works.
So if I want to move a motor one step, I need to track which step it is currently on and select appropriate next step. If I try to move the motor only one step and it is the wrong step, the motor could just sit there and do nothing forever, assuming each time I tried to move the motor, I used the wrong step.
Is there a mechanism for handling this potential problem?
jaketh:
I think I understand stepper motors, not in the deep sense that an electrical engineer does maybe but I have read a lot and have no problems making them work.
The problem I have (had) is just the step starting/stopping problem. To be more specific, what I understand now is that if I stop on 0010 and then try to turn the motor by calling 1000, the motor doesn't step. So if I stop the motor at 0010 and then call a movement method that starts with 1000, the motor just sits there for the first few steps until a step is reached that the motor responds to. From that step onwards, everything works.
So if I want to move a motor one step, I need to track which step it is currently on and select appropriate next step. If I try to move the motor only one step and it is the wrong step, the motor could just sit there and do nothing forever, assuming each time I tried to move the motor, I used the wrong step.
Is there a mechanism for handling this potential problem?
Thanks
Yes, there is the usual way of using a controller that can maintain the current to the coils while the motor is stopped.
jaketh:
I think I understand stepper motors, not in the deep sense that an electrical engineer does maybe but I have read a lot and have no problems making them work.
The problem I have (had) is just the step starting/stopping problem. To be more specific, what I understand now is that if I stop on 0010 and then try to turn the motor by calling 1000, the motor doesn't step. So if I stop the motor at 0010 and then call a movement method that starts with 1000, the motor just sits there for the first few steps until a step is reached that the motor responds to. From that step onwards, everything works.
So if I want to move a motor one step, I need to track which step it is currently on and select appropriate next step. If I try to move the motor only one step and it is the wrong step, the motor could just sit there and do nothing forever, assuming each time I tried to move the motor, I used the wrong step.
Is there a mechanism for handling this potential problem?
Thanks
It won't do nothing forever. It will make a step or two towards whichever copy of that step is mechanically closest. Then it will stay there forever until you give it a different step instruction.
A stepper motor has no concept of time. It doesn't know anything about "before". All it knows is which coils are currently powered or unpowered. If you change to different coils (or off) then it will step almost instantaneously to a mechanical position corresponding to that electrical condition. If your software has correctly chosen an adjacent step then it will step smoothly to that desired step. If you choose the wrong step then the movement may be mechanically "backwards" from the intended step direction.
MorganS:
It won't do nothing forever. It will make a step or two towards whichever copy of that step is mechanically closest. Then it will stay there forever until you give it a different step instruction.
A stepper motor has no concept of time. It doesn't know anything about "before". All it knows is which coils are currently powered or unpowered. If you change to different coils (or off) then it will step almost instantaneously to a mechanical position corresponding to that electrical condition. If your software has correctly chosen an adjacent step then it will step smoothly to that desired step. If you choose the wrong step then the movement may be mechanically "backwards" from the intended step direction.
The motor I was using, a cheap 28BYJ - 48, would just sit there if the step code I sent was not within a full step of the right step code.
If you use a limit switch to define "home", as most people do, the problem goes away.
Once the stepper starts moving, it is synchronized with the step pattern produced by the driver.
Alternatively, in some cases you can simply use an end stop to define home. Give the motor enough steps to drive it into the end stop, and reset step count to zero. A stepper will not be damaged if it stalls.
jremington:
If you use a limit switch to define "home", as most people do, the problem goes away.
Once the stepper starts moving, it is synchronized with the step pattern produced by the driver.
Alternatively, in some cases you can simply use an end stop to define home. Give the motor enough steps to drive it into the end stop, and reset step count to zero. A stepper will not be damaged if it stalls.
You could say a stepper motor is permanently stalled, and it runs at stall current constantly!