Shop OBEX P1 Docs P2 Docs Learn Events
Stepper motor control — Parallax Forums

Stepper motor control

ManAtWorkManAtWork Posts: 2,176
edited 2020-02-29 15:08 in Propeller 2
I have to say in advance that I don't have the time to start another project as I'm still busy with my servo project. But it surely doesn't hurt to discuss some theoretical aspects and collect ideas how to possibly control stepper motors with the P2. I have several single axis and mult-axis solutions running with the P1. But because the P1 didn't have real ADCs or DACs I had to use external analogue circuitry to implement the current control loops. The P2 probably has enough computing power and the necessary gimmicks so that we could do everything digitally and only need a power stage (see picture).

First, we have to define the target applications. Small motors like the ones used in 3D printers (NEMA17 or smaller) usually require volages <40V and cutrrents <2A. There are ready-to-use ICs that include power stage and control logic and are so cheap that it doesn't make sense to build that with discrete parts. On the other side, if more than a few hundret watts of power is required (NEMA 42 or bigger) it no longer makes sense to use stepper motors. The bad efficiency of steppers produces lots of heat and servos with better performance are available for a comparable price.

So I think the best applications for stepper motors are the ones where simplicity is important and power requirement is between 50 and 400W per axis. For single axis drives the P2 is quite expensive. So it only makes sense to use it when multiple axes have to be controled by a single CPU or if functions are required that the P1 can't do (sensorless stall detection?).
1001 x 872 - 27K

Comments

  • A stepper motor is basically a 2-phase synchronous PM motor. To rotate it we need 4 half bridges that have to be driven with a PWM pattern that produces a sine shaped current in one winding and cosine current in the other. For full stepping (nobody uses this anymore) sine and cosine are aproxximated by two square waves shifted by 90°. Microstepping is done by using finer aproxximation. With a very large number of microsteps per full step or with clever filtering a perfect sine wave can be achieved.

    The key is how to measure the current. The simplest and cheapest solution is to use one shunt resistor per winding in the common source path of two half bridges (see schematic above). The disadvantage is that current can be measured only when voltage is applied to the winding and not in the free-wheeling phase. So a fast comperator or a sampling ADC has to be used. For example, a motor with 0.5 ohms winding resistance driven by 50V DC supply with 5A current needs a duty cycle of only 5%. So at 20kHz PWM frequency we only have 2.5µs minus blanking time required for the switching noise to coast away.

    To overcome this problem we could use 4 resistors instead of 2. That takes a little more money, board space, two more ADC pins and produces a little more heat. A solution I used in my servo project are hall based current sensors that are isolated. They can be used to measure current directly in the motor current path (AX, CX) and independent of ground. This way the current can be measured over the full PWM period and the sigma delta ADCs of the P2 could be used to measure the average current without a sample/hold circuit. The drawback is those sensors are quite expensive. Acceptable for a high power servo drive but not ideal for a multi axis stepper drive.
  • evanhevanh Posts: 15,916
    edited 2020-02-29 14:45
    Hmm, I think the defining characteristic of a stepper is it operates at 100% current nominally. Microstepping is just a blind modulated ratio, afaik. Current sense is only there for fault detection - To protect the power transistors.

    On the other hand, being able to arbitrarily set what is 100% current would be handy.

  • ManAtWorkManAtWork Posts: 2,176
    edited 2020-02-29 15:19
    Simple stepper drivers use a reference voltage that is compared to the voltage at the shunt resistor. Voltage is applied to the winding, by switching on two diagonally opposite transistors (for example T1A + T2B) until the reference is reached. Then you can switch either to free-wheeling (slow decay, T1A + T2A) or the opposite polarity (fast decay T1B + T2A).

    The reference can come from a simple voltage divider for full stepping or from a microprocessor to implement microstepping. Old analogue drives have used a resistor ladder as "analogue sine table".

    The "switch on until 100% is reached" strategy is somewhat imperfect as it only controls peak current and not average current. So the theoretically perfect sine wave gets distorted and the motor runs noisier.

    With the P1 based drives I used a clever switching strategy to use fast and slow decay alternatively to balance out the peak vs. average error. But this requires a relatively complex circuit with two opamps and four comperators and an additional opamp for resonance damping.

    With the P2 and its smartpins I thought it would be possible to implement the whole current control loops inside the P2. To achieve this it's necessary to actually measure the current.
  • BTW, the schematic shown in post #1 has a BOM cost of ~$3.50 and takes ~1 square inch of board space. It can output up to 4 or 5A at 48V depending on cooling. That is enough to make a small router run as fast as this:
    (The control box has two P1s inside)
  • evanhevanh Posts: 15,916
    Nice. Any specific homing for the two X axis motors?

  • The machine shown is very simple and has only one homing switch for both X motors. This is sufficient as the gantry is small and stiff enough so it can't twist. For larger machines I also support two separate homing switches to ensure that X is always right angle to Y.
Sign In or Register to comment.