Stepper motor control
ManAtWork
Posts: 2,176
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?).
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?).
Comments
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.
On the other hand, being able to arbitrarily set what is 100% current would be handy.
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.
(The control box has two P1s inside)