Connect with us

Stepper motor circuit

Discussion in '8bit Microcontrollers' started by zalzon, Dec 27, 2003.

Scroll to continue with content
  1. zalzon

    zalzon Guest

    Hi,
    i have a pic microcontroller putting out signals to 4 pins. I
    need to turn a unipolar stepper motor (6 wires). Can someone suggest
    a circuit to do this?

    I don't want to use an allegro or whatever else controller chip. I'd
    like to build the circuit myself. I hope its not too hard?

    Would I need to build an H-bridge circuit and what wires from the
    motor go where? Specifically I would like to know if the center tap
    needs to be used or should it just be wired up as a bipolar stepper
    motor would.

    I've been fiddling around with npn and pnp transistors on a
    breadboard. So far I have only succeeded in exhausting myself without
    getting the motor to turn.

    Some suggestions or diagrams if u please.


    a very merry christmas & a happy nu year.
     
  2. koool~

    koool~ Guest

    <Snip>

    Hi Zalzon,

    This topic and its variants have been previously discussed here at
    great length. You really should do the research before asking the
    group for information so easily found at Google.

    A Google search of "microcontroller "stepper motor"" turns up over
    6300 hits. On the first page of links, this one appears:

    www.imagesco.com/articles/picstepper/01.html

    (NOTE: no personal affiliation with the site)

    There is information here on interfacing the controller to the motor,
    and some sample code. I hope this gets you going, Zalzon.

    M/C & H/N to you as well.

    koool~
     
  3. It's *easier* to use the center tap. An H-bridge is more complex, and
    generally has higher losses, but is required to drive a bipolar motor.
    If you try to drive a unipolar as a bipolar (which I don't recommend)
    you'll have to reduce the coil current from nominal.
    Google for them and you'll find LOTS of them. You just need 4 NPN
    transistors (or, better, MOSFETs or darlingtons) to drive the ends of
    the two coils. Then sequence them one way or the other (4 states) to
    get the motor to run one way or the other.

    Unless your required performance is very low, you'll probably want to
    implement a chopper drive to control the current through the coils to
    get fast response without burning up the motor coils at slow speeds.
    If your application does not require high static torque you can also
    reduce the coil current from the maximum shortly after the motor has
    stopped. This will help it run cooler when it's just sitting there.
    Best regards,
    Spehro Pefhany
     
  4. There are quite a few different ways to drive stepper motors, some
    simple and some quite complicated, though all of them can be built of
    simple components no more complicated than transistors and
    comparators. The point is that motors (and anything that makes use
    the force of magnetic fields produced by current in coils of wire)
    needs an increasing voltage to make it go faster. This is a result of
    the basic inductor formula that relates voltage applied to the rate of
    change of current through an inductor: V=L*(di/dt).

    So, the simplest circuits (4 power switches and 4 catch diodes to a
    zener voltage clamp) that use the resistance of the coils to limit the
    current are the slowest, since they stabilize the coil currents via
    the L/R time constant, with L and R being the properties of the motor
    coils themselves. This simple approach can be sped up a bit by adding
    more resistance external to the motor to lower this time constant
    (L/(Rmotor+Rexternal). Of course, this requires more supply voltage
    to get the same current, and this extra voltage goes back to the first
    point in explaining how it can make the motor go a bit faster.

    If this is not fast enough, you will have to either use even bigger
    resistors and supply voltage, or change to a switching regulator
    approach that applies the full supply voltage to the motor coils till
    the current reaches the desired value (based on the motor L/R time
    constant) and then short circuit the winding so the current circulates
    while running down. By the time you build in the ability to perform
    this current regulation trick and also get the current to go either
    way through the two windings, you have reconstructed the H bridge
    chips that Allegro makes.
     
  5. PlucknGro

    PlucknGro Guest

    Thanks all. That was one of my problems. I was trying to use an
    H-bridge to drive a unipolar stepper motor! yikes.

    I now use 4 NPN transistors. When I switched it on, the shaft gently
    rocked back and forth. I could not understand why this was happening.
    It should be turning from step to step not be stuck rocking back and
    forth on the first step. This is a low current stepper motor by the
    way. 0.17A, 5.3V DC

    I found if i gave it a slight nudge it would move forward and then
    stalled again. I surmised that the rotor did not have enough inertia
    to get to the next step. I fiddled with the time delay between each
    pulse from the PIC port. Finally it managed to turn. But if it faces
    even a little resistance, its stalls into rocking back and forth.

    The motor does not seem to have sufficient inertia when moving from
    step to step. Is there any way of overcoming this? Right now it has
    enough torque to maybe turn a CD and not drive a small robot car which
    is what I was hoping to use it for.

    I'm using this pulse sequence : 0001, 0010, 0100, 1000
     
  6. A.M.

    A.M. Guest

    Does it seem to 'chatter' when it runs? It may be that you have the
    windings mixed up. Try systematically varying the connections to
    determine the correct order.

    You might also try half-stepping...

    1100 0100 0110 0010 0011 0001 1001 1000


    PlucknGro wrote:
     
  7. But if you have a six wire motor (two center tapped coils, you can
    certainly drive it from an H bridge by using either half of each of
    the center tapped coils, or by using the whole coils. One gives more
    speed per volt, and one gives more torque per amp. The only real
    problem for dual H bridge operation occurs in motors with the two
    center taps tied together, internally (5 wire motors).
     
  8. That is not a valid pattern for a two phase motor. The full step
    pattern (assuming the first two bits are the drivers for the two
    halves of one coil) would be:

    0101 1001 1010 0110

    One half of each winding on at all times, with each pair toggling
    alternately. There is also a half step mode that takes 8 steps to
    complete a cycle that alternated between having one coil powered and
    two coils powered.

    0001 0101 0100 0110 0010 1010 1000 1001

    The full step mode has higher peak torque, assuming all coil currents
    are the same, but it is easy to add series resistors to the center
    taps to make the torque smooth for the half step mode. This consists
    of a common resistor to the supply that feeds a pair of resistors that
    connect to the two center taps. With the right choice of resistors,
    the break away torque with one coil holding (and sharing the common
    resistor with no one) can be made equal to the break away torque when
    two coils are on, but sharing the common resistor.

    I Found the right two currents for one motor by making a lever out of
    steel wire ( a coat hanger) that was wound into a tight fitting coil
    at one end to be pushed on to the motor shaft. I hung a small weight
    on the lever that was near the break away torque at normal motor
    current for on coil half. Using a current limited supply, I slowly
    lowered the current till the motor would not hold the weight with the
    lever sticking out sideways and noted what the minimum hold current
    was. Then I energized two coils in series and repeated the
    experiment. This gave me the two coil current that had the same
    holding torque as a larger single coil current. With the resistors
    adjusted to produce these two currents, the motor torque was smooth
    more drop put resistant than when having the same coil current,
    whether one or two coils were in operation.
     
  9. Don Bruder

    Don Bruder Guest

    Not clear on what you mean by using it as a pulse sequence...

    Are you saying you're broadside-loading a decoder that puts a 1 on the
    output corresponding to the value you load?

    Or have you got something else in mind, and I'm just confused?

    FWIW:
    When I did this little tinker a few months ago, I used a hex counter IC
    with parallel outputs and a clock source as the heart of the beast. I
    set things up with some logic gates to make a "mod 4" function on the
    counter's outputs, and set things up so the counter just kept ticking
    over as long as there was power. I decoded the output from the mod 4 via
    some more logic gates to give me four output pins, 0, 1, 2, and 3. At
    any given moment, the output pin corresponding to the current value of
    the counter mod 4 was high, while the other 3 outputs were low. From
    there, it was just a matter of tying into the four transistors to switch
    them on and off to make the motor run.

    I had a 0Hz-25Khz variable clock source handy, and found that my motor
    tended to go into fibrillation at around 16KHz, give or take a little.
    Slower was fine, and would turn steadily, with or without a load, but up
    in the neighborhood of 13-14KHz, it started losing torque in a big way,
    and if I kept turning up the frequency, eventually just sat there and
    buzzed as the critical frequency (somewhere above 16KHz, but below
    20KHz) was reached. Memory is foggy, and I don't have my notes in front
    of me to figure out exactly why/how, but I seem to recall figuring out
    that running the clock at about 7KHz was "optimal" for what I was trying
    to do - That would turn the motor fast enough to be useful, and do it
    under the load I was wanting it to work for, without making much noise
    or "letting the smoke out".
     
  10. Don Bruder

    Don Bruder Guest

    Not clear on what you mean by using it as a pulse sequence...

    Are you saying you're broadside-loading a decoder that puts a 1 on the
    output corresponding to the value you load?

    Or have you got something else in mind, and I'm just confused?

    FWIW:
    When I did pretty much this same little tinker a few months ago, I used
    a hex counter IC with parallel outputs and a clock source as the heart
    of the beast. I set things up with some logic gates to make a "mod 4"
    function on the counter's outputs, and set things up so the counter just
    kept ticking over as long as there was power. I decoded the output from
    the mod 4 via some more logic gates to give me four output pins, 0, 1,
    2, and 3. At any given moment, the output pin corresponding to the
    current value of the counter mod 4 was high, while the other 3 outputs
    were low. From there, it was just a matter of tying into the four
    transistors to switch them on and off to make the motor run.

    I had a 0Hz-25Khz variable clock source handy, and found that my motor
    tended to go into fibrillation at around 16KHz, give or take a little.
    Slower was fine, and would turn steadily, with or without a load, but up
    in the neighborhood of 13-14KHz, it started losing torque in a big way,
    and if I kept turning up the frequency, eventually just sat there and
    buzzed as the critical frequency (somewhere above 16KHz, but below
    20KHz) was reached. Memory is foggy, and I don't have my notes in front
    of me to figure out exactly why/how, but I seem to recall figuring out
    that running the clock at about 7KHz was "optimal" for what I was trying
    to do - That would turn the motor fast enough to be useful, and do it
    under the load I was wanting it to work for, without making much noise
    or "letting the smoke out".
     
  11. zalzon

    zalzon Guest

    Right on John. The above two sequences worked though I don't quite
    have a good understanding why the sequence is such.

    Its way over my head John :) I'm was just hoping to get the thing
    turning. It does 'stick' a little as you say. I would think that the
    current to the leads has to vary with the load in order to prevent
    this sticking. I guess that's what you were trying to describe to me.

    Thanks all.
     
  12. zalzon

    zalzon Guest

    Definately confused :)

    Well I'm using a microcontroller, not digital IC/logic chips which I
    presume would be hell to successfully get working with stepper motors.
     
  13. Bill Garber

    Bill Garber Guest

    : On Mon, 29 Dec 2003 03:39:57 GMT, Don Bruder <>
    wrote:
    :
    : >> I'm using this pulse sequence : 0001, 0010, 0100, 1000
    : >
    : >Not clear on what you mean by using it as a pulse sequence...
    : >
    : >Are you saying you're broadside-loading a decoder that puts a
    1 on the
    : >output corresponding to the value you load?
    : >
    : >Or have you got something else in mind, and I'm just confused?
    :
    : Definately confused :)
    :
    : Well I'm using a microcontroller, not digital IC/logic chips
    which I
    : presume would be hell to successfully get working with stepper
    motors.

    Dumb question here, but why not simply use a stepper
    motor controller IC?

    Bill @ GarberStreet Enterprizez };-)
    Web Site - http://garberstreet.netfirms.com
    Email -
    Remove - SPAM and X to contact me
     
  14. Don Bruder

    Don Bruder Guest

    Actually, it was a piece of cake for me. Hardest part was trying to
    locate the right output transistors in the scrap-pile that serves as my
    "parts store".

    A bi-directional 4-bit synchronous counter (a ripple counter would
    undoubtedly have worked just as well, but I had a synchronous version
    sitting near the top of the junkbox, and stopped looking when I found
    that one) with parallel outputs was wired so that it just sat there
    counting from 0 to 16 (or 16 to 0, dpending on rotation direction
    desired) and rolling to start. I used a handful of ANDs and NANDs to do
    a "mod 4" (0 mod 4 = 0, 1 mod 4 = 1, 4 mod 4 = 0, 5 mod 4 = 1, etc)
    operation to give me 4 sequences of 0, 1, 2, 3 (or 3, 2, 1, 0) per full
    count. I then fed that output into another group of ANDs and NANDs whose
    final output was on four independent wires I called (originally
    enough...) Phase 0 through Phase 3. When the counter mod four was 0,
    Phase 0 went high, and the rest went low, when the counter mod 4 was 1,
    Phase 1 went high, and the rest went low, and so on. Each of the phases
    controlled one of four transistors, which were in turn wired to the
    phases of the motor as on/off switches. Ignoring the transistors and the
    clock source, I think it was a total of 6 chips.

    Simple as pie! :)
     
  15. Don Bruder

    Don Bruder Guest

    In my case, it was because a stepper-motor controller IC would have cost
    money, and this was a "Can we do it out of the junkbox with a budget of
    exactly US $0.00?" project. Besides... It was fun figuring out how to
    make it happen :)

    Seems I recall Zalzon mentioning that he was wanting (for reasons either
    unspecified by him, or forgotten by me) to do it "from scratch" for some
    reason.
     
  16. Think of the coils as hands lined up passing a bucket full of water
    along the line. The first pattern has two hands carrying the bucket
    at all times. As one hand lets go on one side, a new hand grabs on on
    the other side, shifting the bucket from between the first two hands,
    to between the second and third. Etc. All stable positions consist of
    the bucket hanging between a pair of hands.

    The next pattern has just one hand holding the bucket, then the next
    hand in line grabs on, and the bucket shifts from under the first
    hand, to between these two hands. Then the first hand lets go, and
    the bucket hangs under the second hand. Then a third hand grabs on
    and the bucket hangs between the second and third hand, etc. So the
    bucket alternated between hanging on a single hand, to hanging between
    a pair of hands.

    Fairly obviously a positions where two hands support the bucket
    (resist torque that would drag the rotor out of lock) is stronger than
    a position held by just one hand. So the second pattern generally has
    strong and weak positions.
    Using the above analogy, I was just trying to make the single hand
    positions stronger, and weaken the two handed positions, so that the
    strength of the torque was constant at any step position. As long as
    you have more torque than you need at all positions, and are not
    concerned with two acceleration rates at alternate half steps, it
    makes little difference. Just trying ot get your mind inside the
    mechanism.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-