Pushing the Limits of Stepper Motor Control in 3D Printing
A guest blog by Jan Kotarski
In the 3D printing community, newcomers are often having a hard time understanding how stepper motors are really driven. Questions like “voltage rating for my motor is 4.6V, can I use it if my printer has a 12/24V power supply?” and similar pop out from time to time.
This is because most of the electronics we use every day use constant voltage supply with variable current and that’s what we are used to think about. A 12V LED strip will be powered by a stable, controlled 12V and the current consumption will increase as the number of diodes – the load – gets bigger.
Stepper motors are powered in a reverse way – the current is constant/controlled (more on that later) and the voltage required varies together with the load. That’s why in 3D printing 12V power supplies were replaced by 24V or even higher voltage supplies – because (apart from other benefits) this way the printer can deliver more power to the motors, reach higher movement speeds and be more dynamic, despite the set motor current staying at the same level.
But the typical power supply delivers constant voltage. How is it converted to regulated, controlled current? It’s the job of the stepper motor driver, like the TMC2208.
The current regulation is achieved using a technique called PWM (Pulse Width Modulation). Voltage is very quickly switched on and off using MOSFET transistors in a manner that results in the current flowing at a desired level. But this current control method will not work with a simple resistive load – the current regulation can only be achieved when driving coils – and they, together with magnets or other coils are making the stepper motor rotate. A coil – an inductor – has an interesting property – it “slows down” the current flow, adding “inertia” to it. That means that if a voltage is applied, the current flowing through an inductor will not rise immediately – but slowly. The same thing happens when the voltage is disabled – the current will not immediately drop to zero amperes but will decrease over time.
By the way, LEDs are actually current-controlled too – but in the case of a simple LED strip, a resistor is enough to regulate the current, so finally a LED strip is working as a constant voltage device.
The described current control method can be seen clearly on actual measurements:
The yellow curve represents current flowing through a motor coil, the cyan line shows the voltage being switched on/off. This measurement was taken during standby, when the motor was not rotating, but holding its position. The current is pretty much constant and the voltage is regularly switched on for a short period of time and then turned off again. Please note that this switching is happening over 30.000 times a second!
When the motor starts moving, that’s when the interesting stuff happens. The shape of the current waveform is not flat anymore – it’s a sine wave. To rotate the motor, the current needs to be changing to alternate the magnetic field, which results in motion. This principle is true for all brushless electric motors. The TMC2208 is actively measuring and regulating the current, creating a sine current shape with set amplitude and the effective voltage varies accordingly. Rotation speed depends on the frequency of the current sine wave.
Don’t worry about the waviness of the voltage measurement – it’s an artifact. The amplitude – seen at the bottom of the screen – is more or less equal to the supply voltage which I was using (32V). The RMS value is an indicator of “how much” effective voltage is delivered to the motor coil. In this case, the measured/calculated value is not very precise, but it shows that at this speed we deliver less than 40% of the nominal supply voltage.
When we zoom in, we can clearly see the mentioned special property of an inductor:
When the voltage is on, the current is rising, but quite slowly compared to how fast the voltage is rising/falling. When we turn off the voltage, current flowing through the coil falls, but again – quite slowly. Before it goes too low, the driver turns on the supply and the current goes up again. This is essentially how we keep the current at the required level. Please also note that the time how long the MOSFET switch is conducting (how long the voltage stays ON) depends on the “position” on the sine wave. When we look at the sine wave, we can see regions that change slowly (near the top/bottom) and which change faster (near zero on the Y-axis). If we want the current to follow this shape, we simply need to apply the voltage for a bit longer in the “fast region” of the sine wave!
The small irregularities, deviations from ideal, smooth sine shape are called ripples and are always present when a coil current is controlled with PWM.
Effects of the motor load
At this point, one very important question arises – what causes the required voltage (actual power delivered to the motor) to vary with changing load? That thing is called BEMF – Back ElectroMotoric Force – the inherent property of every electric motor. I don’t want to get into the physics details of this phenomenon in this article – simply speaking, the motor coil during spinning is generating a “counter” voltage, which is fighting with the voltage that we are applying from the power supply to the motor, that’s why it is called Back EMF. The higher the speed (or load), the higher the BEMF that we need to fight with.
BEMF is affected by three main factors:
- motor coil inductance – the smaller, the better;
- set current – the higher the current, the stronger the motor is, but so is generated BEMF;
- speed/mechanical load – of course the BEMF increases together with the load. That’s how the sensorless homing using StallGuard works – it measures the BEMF!
Actual influence of BEMF
On the measurement below, we can see an acceleration move and close-ups of two regions – with low/high speed.
When the speed was still quite low, the motor controller still had plenty of headroom to nicely regulate the current, so the sine wave can be considered ideal. But if we zoom in a bit later, we can see that the current looks more like a triangle, and the voltage is applied not very precisely. That’s because the controller had no voltage headroom to properly regulate the current and in effect, the sine wave gets distorted, although the motor is still operating.
Now that we understand how a stepper motor is controlled, we can get to the next point and answer the last question – what happens when the BEMF is so high that the mentioned “counter” voltage is getting too close to the supply voltage? One might guess that the motor will start losing steps – and that’s true, but not immediately! I was honestly surprised by how well the drivers and motors are handling extreme speeds. Let’s take a look:
This is the current flowing through the motor coil during a full move using a 24V power supply. The printer starts at standstill, then it accelerates to 900 mm/s at 9000 mm/s2 and then stops.
So, what is actually happening? In the beginning, the driver is able to maintain a prover sine wave, but a bit later, when the BEMF gets close to supply voltage, the waveform degrades, as we have seen above. But at that point the printer still did not reach the desired speed – soon the back voltage generated by the motor was so high that it was impossible to reach the set current value. It drops until the desired speed is achieved and then the amplitude gets stable, but we are not looking at a sine wave anymore – at that point, it is much closer to a square wave.
These results look pretty bad, but actually – they are ok! The machine was running with settings like that for over a year without problems. It is quite normal in high-speed applications. Of course, the torque is greatly decreased and the accuracy may not be perfect, but after slowing down, the motors regain nominal torque and the position is accurate. 900mm/s is the maximum speed that I considered safe before starting to lose steps.
I also tried to use raw data from the oscilloscope to calculate and show the averaged “voltage consumption” during operation. It proved to be a bit harder than I’d anticipated, so the results are only indicative – that’s why there are no numbers presented. Anyway:
The two graphs present voltage and current with “Local RMS”, which is more or less the averaged effective value. We can see that as the speed increases, we need to apply more and more voltage until we reach the limit and at that point the current is falling a bit. Two important conclusions come from these graphs:
- We can never deliver 100% of the supply voltage because we need the current to be changing -> we need some time for it to fall down;
- At high speeds, we are unable to deliver full power to the motor.
Benefits of higher supply voltage
Some of you could have realised that in most of the measurements I was using 32V, not 24V power supply. That’s true – I recently upgraded my machine to 32V and that’s why I decided to play around with my oscilloscope and compare both options.
Was it worth it? Definitely!
With move parameters like previously, the waveform shape looks much better and current amplitude is ~60% higher than before, which means better stability and higher margin before motors start losing steps. On the other hand, instead of a higher safety margin, I can print with quite high accelerations and even reach a speed of 1200mm/s! Not that it makes much sense for a filament printer.. but I’m really happy with the results.
Summary and recommendations
Even a few volts of difference will improve operation of our stepper motor driver or allow us to reach higher speeds. Sometimes higher printing speed will come with decreased print quality, but that’s often not a big issue and at the very least we can increase the travel speed, which will not only reduce print time but is also helpful for retraction tuning.
With all the knowledge we got, now we can choose motors for our machine more confidently. So:
- Keep the motor rated inductance and resistance as low as possible;
- For drivers like TMC2208 or TMC2130, 1.5 – 1.7A rated motor current should be optimal;
- For TMC2209, TMC2660 and TMC51X0, 2.0 – 2.5A rated motors will be OK;
- Choose motor power supply voltage as high as possible, but double-check ratings of your drivers and mainboard!
Personally, I think that in the next few years we will see more and more 36V and later 48V – ready motherboards for Reprap/commercial 3D printers, as our machines keep getting better and could make use of a speed boost. The only downside to it is that heaters are usually designed for 24V – but maybe that will change too! We will see.
- Siglent SDS 1104X-E Oscilloscope
- Hantek CC65 current probe
- 150W Mean Well power supply
- CoreXY 3D printer
- Custom TMC2208 board
You can learn more about PWM here:
July 30, 2021 / Corné Bekkers / 0