Trinamic drivers are a marvel of engineering. However they combined many things in a single chip that it is hard to make it all work right. Well, it is hard for me at least, if you have mastered these drivers please let me know.
It started when I tried to test if the Marlin firmware for my board would agree to move the stepper motors around. To test the motor driver signals on the board I modified one of the tmc2130 arduino library samples like this, and it was spinning the motor. Alas my enthusiasm was short lived, when I tried to move the motor with Marlin, it would stutter and vibrate, but no motion.
Hmm, I checked and re-checked all the tmc2130 driver settings back and forth. Read the datasheet 3 times – nothing. I was going back and forth between the marlin firmware and my little test program to figure out what was wrong. Finally I was able to isolate the issue to the number of microsteps the driver was configured to take.
Now to be fair the microstepping configuration was not the issue per se, it was a setting I can change to introduce the same problem in my test program as well.
Let’s take a step back and explain what this all means. Stepper motors come in many different configurations. We’ll focus on bipolar 2 phase motors – these are the most common stepper type used for 3D printers. By far the majority of these motors are manufactured to make 200 steps per full rotation. Each step being 1.8°. There also high resolution motors which make 400 steps per rotation or 0.9° for each step. For the purpose of this description the difference is irrelevant.
In the 1.8° motors, it is common to say the 200 steps are “full steps”. In other words the rotor rotates from one stable position to another. In electrical terms, each motor coil is energized fully in one direction or the other.
Clever folk however discovered that they could achieve better precision if they don’t fully energize the motor coils – hence micro-stepping. The most obvious downside of the microstepping is reduced motor holding torque. There are different microstepping options offered by different stepper motor driver chips. Most common are 2, 4, 8 or 16 microsteps. This means that the driver would use 400, 800, 1600, 3200 microsteps to make a full rotation of the motor shaft. Some drivers offer 32 microsteps as option. The tmc2130 and other drivers from Trinamic also offer 64, 128 as well as whooping 256 microsteps. That is astounding 51, 200 microsteps per rotation or about 0.007° per microstep.
Before you get too excited, keep in mind each increase of the microstepping level comes at the expense of decrease in torque.
All these wanders aside, what was my issue with microstepping? I made a simple observation: my test program was driving the motor stepping pin at about 48kHz; with the default settings (256 microsteps) the motor would move, but when I switch to 16 microsteps the motor would make a high pitch sound, but not move. Why? I was puzzled.
Another week of experiments and I discovered the most benign of reasons – I was driving the step pin too fast. In the 256 microsteps configuration the motor speed would be a little under 56 rpm. In the 16 microsteps configuration it would be about 900 rpm. This was above the physical capabilities of the motor with that setup. I found this calculator and it seems with 0.6A current at 12V this motor could theoretically do about 850 rpm max. Practical measurements showed that even at 32 microsteps the motor has trouble moving. At 64 microsteps it was working.
But why does this matter? Well I found that marlin’s default speed is a 300mm/s. I did not change the default axis per mm configuration it was set to 78.74 for 16 microsteps. This would translate to 23,622 microsteps/s or 443 rpm for the motor. Practical test showed this motor was able to achieve about 230rpm max.
Now what? Very simple – I lowered the motor default speed in marlin and was able to issue commands to move the axis 😉
While I was investigating the issue. I got myself a current probe for my oscilloscope. I was able to shoot a few pretty pictures of the driver current of the motor coil trough some different driver settings.
The current probe I got was Hantek C-65:
Picture of the motor driven with full steps an no load. This graph represents the current that goes trough one of the motor coils. There are two coils that drive the motor, the current trough the other coil is identical, but shifted one quarter pulse (90°). The current swings from positive to negative each 2 full steps.
Current waveform with the driver configured for 2 microsteps and 600mA RMS current:
Waveform for 4 microsteps configuration:
Waveform with 16 microsteps:
The waveform with 256 microsteps looks like a smooth sine wave. Sorry I dodn’t manage to get a picture.
This driver has an interesting feature – microstep interpolation. When you enable it, the driver uses 256 microsteps internally and whatever you had configured externally. For example here is the waveform with 2 microsteps and interpolation enabled:
The following is the waveform for full step (no microstepping) and interpolation enabled:
The last image I thought was cool was a capture of the driver waveform changing when the motor is stalled. The configuration is 256 microsteps, with 300mA current. I was trying to stop the motor by holding the shaft with my hand.