Notifications
Clear all

TMC2130 Driver Infos and Modifications  

Page 1 / 2
  RSS
devilhunter
(@devilhunter)
Reputable Member
TMC2130 Driver Infos and Modifications

I would like to collect all Into we have on the TMC2130 stepper drivers and our implementation in the Ulimachine Einsy.
Perhaps we'll figure it out how to tune them better.

Info is all over the place, and while these drivers were made at the end of 2015, the implementation is still relatively new and infos about tuning them is scarce.
There are also a lot of modes on how to drive them, and most older infos out there about the TMC2130 is about upgrading older boards with TMC daughter boards and soldering mode bridges, our SPI implementation gives us some other headaches as well.

Here's hackaday's article about the TMC boards:
https://hackaday.com/2016/09/30/3d-printering-trinamic-tmc2130-stepper-motor-drivers-shifting-the-gears/

Marlin's help article about the TMC drivers:
http://marlinfw.org/docs/features/tmc_drivers.html

teemuatlut's TMC2130 Stepper driver implementation:
https://github.com/teemuatlut/TMC2130Stepper

Trinamic's TMC2130 Calculator:
https://www.trinamic.com/fileadmin/assets/Products/ICs_Documents/TMC5130_TMC2130_TMC2100_Calculations.xlsx
There are various calculations for power, Rsense, velocity and also a microstepping table, for optimizing step values.

Trinamic's Product Manual:
https://www.trinamic.com/fileadmin/assets/Products/ICs_Documents/TMC2130_datasheet.pdf
(Page 78 shows info about )

Trinamic's SpreadCycle Info: (Normal Mode)
https://www.trinamic.com/technology/adv-technologies/spreadcycle/
https://www.trinamic.com/fileadmin/assets/Support/Appnotes/AN001-spreadCycle.pdf

Trinamic's StealthChop Info: (Stealth Mode)
https://www.trinamic.com/technology/adv-technologies/stealthchop/
https://www.trinamic.com/fileadmin/assets/Support/Appnotes/AN015-stealthChop_Performance.pdf
https://www.trinamic.com/fileadmin/assets/Support/Appnotes/AN021-stealthChop_Performance_comparison.pdf

Trinamic's StallGuard2 Info: (Endstopless Homing + misstep detection)
https://www.trinamic.com/technology/adv-technologies/stallguard/
https://www.trinamic.com/fileadmin/assets/Support/Appnotes/AN002-stallGuard2.pdf

Trinamic's CoolStep Info: (may not be implemented) is implemented
https://www.trinamic.com/technology/adv-technologies/coolstep/
https://www.trinamic.com/fileadmin/assets/Support/Appnotes/AN009_Tuning_coolStep.pdf

Trinamic's DcStep Info: (may not be implemented)
https://www.trinamic.com/technology/adv-technologies/dcstep/
https://www.trinamic.com/fileadmin/assets/Support/Appnotes/AN003_-_dcStep_Basics_and_Wizard.pdf

Here are the currently known gcode commands for the TMC2130 drivers:
(also be careful what you are doing with those, keep your fingers off if you don't know what this is.)

Gcodes we found so far for the Prusa Firmware TMCs:
M910 - Reset and initialize the TMC2130 chips.
M911 - Holding current (Example: M911 X14 Y20 Z30 E36)
M912 - Running current (Example: M912 X14 Y20 Z30 E36)
M913 - Print the currently set TMC2130 current values
M914 - high power mode.
M915 - low power mode.
M916 - Set stallGuard threshold
M917 - Set PWM amplitude
M918 - Set PWM gradient

Interestingly, the some normal Gcodes in the Prusa firmware do something completely different to the TMCs than documented in marlin.
Marlin:
M122 - TMC debugging (with S0 or S1) (TMC_DEBUG needs to be set in Configuration_adv.h for this to work)
M906 - motor current in mAh
M906 S1 - Start adjusting current
M906 S0 - Stop adjusting current
M910 - Commit digipot/DAC value to external EEPROM via I2C.
M911 - Report the TMC stepper driver overtemperature pre-warn condition to the host.
M912 - Clear the stepper driver overtemperature pre-warn condition flag.
M914 - TMC Bump Sensitivity

...
Posted : 21/04/2018 1:09 pm
devilhunter
(@devilhunter)
Reputable Member
Topic starter answered:
Re: TMC2130 Driver Infos and Modifications

Here is @metacollin's implementation of the Einsy on the MK2, and his discoveries about the TMC2130


Hi, so I just discovered this thread, I'll be perfectly honest, I haven't read most of it yet, so I apologize if some (or even most) of this post is redundant. I just wanted to let everyone know that I've been running an MK2S with an Einsy board for a couple weeks now, and have everything working including stallguard and the endstop-less homing etc.

(Please forgive my atrocious wiring. I already know it's bad. I just don't care.) Here she is, in all her Einsy glory. Listen, can you hear that? Sweet sweet silence :). Everything works splendidly - homing without endstops, stallguard and counting missed steps, 256 microstep interpolation, all that good stuff. It feels like my MK2S is almost bullet proof now - I actually *can't* get it to screw up a print. Flawless operation is what you can expect! :).

Oh, and let's not forget stallGuard:

I back ported the MK3 firmware to work with the MK2S. There are still a couple of bugs I need to solve but you can check out my (in progress and on going) changes at my github fork of the MK3 v3.1.13 firmware. Be sure to checkout the 'MK24' branch (so, just shy of a MK2.5. Once my MK2.5 upgrade kit comes, I plan to make a 'MK2.8' version of the firmware which will essentially give you a MK3 minus the more rigid frame and faster print speeds that come with it).

I'm also an electrical engineer who specializes in switch mode power supplies, magnetics, motor control, that sort of thing. I have some important information about the steppers and TMC2130 drivers, but I'll get to that in a bit.

So, here is the short list of minor changes you will need to make:

Hardware:
1. You don't need to replace any connectors if you cut off their latchy bits with wire snips. This might sound barbaric, but trust me, replacing the connectors is a substantially larger pain in the butt than you might imagine. That said, you only really need to modify the PINDA connector. You can still connect it by leaving the pin furthest from the USB port on the Einsy board unconnected, the pinout is the same but with an extra pin added to that side for the temperature sensor. Here is a connection diagram that shows individual pin functions instead of just connector labels which I found extremely helpful.

2. The 12V power connectors can be removed just by loosening the screws. Then put the bare wire ends into the Einsy's screw terminals. This is easy and you can always reattach the 12V power connectors later if you want.

3. No way around it, you will need new 5V fans. But they're very inexpensive. You can print out a simple and effective adapter and buy the 40mm 5V Noctua fan, and a 5V blower from many places, as someone in the US, I got both on Amazon. Noctua for $14 and 5V blower for $9. Note, the 5V blower is not a 3 wire one, and is lacking the tachometer functionality. I've had a hard time finding a 3 pin blower that is both 5V and the right size. But knowing the RPM for the print fan (vs the hotend cooling fan) isn't too useful anyway.

4. Where we're going... we don't need end stops. Put the end stop switches down your sink's garbage disposal if you want. You aren't going to need them anymore. Or, less extreme, just don't bother connecting them (you'd have to alter the connectors to do so anyway.

5. Don't worry about the filament runout sensor. My MK3 firmware fork lets you enable or disable all filament runout sensor/autoloading functionality as needed by commenting or uncommenting out a couple #defines in the configuration_prusa file. However, I have no idea if enabling it actually works, as I have no way of testing it (yet).

6. Using 24V as the motor drive voltage is absolutely a requirement. No amount of software changes will permit the TMC2130s to correctly drive the stepper motors at 12V. Oh, and to make this clear: the MK2S and MK3 use the same motors. Or at least nearly identical. Stepper motors don't have true voltage ratings like brushed DC motors, only a max voltage limited by their windings (usually 48V+) and a maximum current. So your MK2's motors are not '12V steppers', nor are the MK3's 24V ones. They're the same. Which is why no changes are required to any of the TMC2130 settings in the MK3 firmware to work any less than flawlessly with the MK2S steppers :D.

I don't expect anyone to take my word for it, but the reasons are complicated and long so I moved them to the Appendix at the end of this post.

Using 24V is actually cheap, simple, and easy, it really is nowhere near as bad is it sounds! There is good news!

7. You can continue to use your 12V power supply for the heavy lifting, like the heated bed. I looked at how they have their power rails setup in the Einsy Schematics (this works for the mini rambo as well), and there is absolutely no problems with using different voltages for your heat bed vs. main power. You can continue to use your 12V power supply for the heavy lifting. You hook 12V up to the bed power input, and 24V up to the main power input. Since the fan voltages are now regulated by a buck converter down to 5V, they still get 5V. Same with the PINDA probe. The only thing that will see the raw 24V is the motors and the hotend heater cartridge.... at least if you connect it as is. Which leads me to...

8. You can continue to power your hotend from the 12V supply as well! Yes, even with 24V connected to the main power. You just have to be a little clever in how you wire it.

The heater is controlled by a N-channel MOSFET. What this means is that one of the two pins on the heater power output connector on the Einsy board is connected to whatever is powering our motors/whatever is connected to the main power input. So if that is 24V, there is 24V on that pin. It is never switched off, it is always connected. What IS switched off is the ground. An N-channel mosfet works by, effectively, 'disconnecting' something from ground when off, and connecting it to ground when on.

And ground is ground. That means that, as long as they share a common ground (which they do - the grounds of both bed and main power are connected by the Einsy's copper pours), we can connect one wire of the heater cartridge to any voltage, and the heater MOSFET switch will still turn it on and off exactly as before. Again, any voltage as long as that voltage shares a common ground with the main power - which, if the 12V supply is connected to the bed power input, is the case for our original 12V supply.

So all you have to do is cut the positive wire of the heater cartridge near its connector, strip the insulation off a bit, then splice it to the second 12V positive wire (since one of the 12V pairs is now sitting unused) by whatever means you like (solder, crimp, twist it really good and pray), and leave the remaining wire in the connector, connected to the Einsy's heater port as normal. Now your 12V supply is powering everything except the motors.

I'll draw a diagram tomorrow, sorry.

9. Your 24V supply can be a $9 wallwart! At 24V, even after bumping up the current by a fair amount (which I needed to do because something sticky got spilled on a leadscrew and 8mm ground rod... don't ask lol), all 5 motors combined never draw more than 700mA RMS at 24V. This drops to less than 600mA RMS at 28V. So something as modest as a 24V 1A power supply isn't just adequate, but will give you 30-40% headroom beyond the required current. This is seriously all you need. ($9)

There is already adequate decoupling on the Einsy board, the power supply does not need any real output capacitance or filtering. I am printing with my MK2S right now piping 28V down about 8 feet of speaker wire connected to the crappiest chinese mystery wallwart I could find, and there are no problems whatsoever.

This might weird people out, having two separate things powering the printer, but it is not a problem, and the boards are designed to be operated like this - that's the entire point of having separate bed and main power connections. They have oring diodes where needed. The schematic labels the bed and main power rails as 12V3 and 12V2 I believe, but these are just names - they are not necessarily intended to only work at 12V. And clearly this is the case, as the MK3 connects them both to 24V rather than 12V. Beyond that, they need not be the same voltage. Plenty of people use them with different voltages. And the entire board will act as if it is 'on' (ATMega booted and operating, LCD on, etc.) as long as any one of the two voltages is turned on. So it doesn't matter if you have only the 24V on, or only the 12V on, or which order you turn them on or off. Though, with 12V off, the heated bed and hotend heater will not work, obviously. But to turn the printer on and off, you just turn both supplies on, or off, with any amount of delay in between, and in any order. It's fool proof, and it just works. And all of this is by design and qualifies as an intendedusage case of both the Einsy and rambo mini.

OK, so I need to go to bed, this turned into a very long post, but in a few days I should have things tested well enough that I might be comfortable sharing a (TOTALLY UNSUPPORTED AND USED AT YOUR OWN RISK AND RESPONSIBILITY) firmware hex people can flash. Until then, more adventurous people are welcome to download my firmware from github - it compiles directly in the arudino IDE and should be flashed from it as well. Only to an Einsy board though, of course.

For those curious about what had to be changed, I had to adjust some of the calibration parameters (the calibration points changed position slightly with the MK3), change the position of the PINDA probe, fully enclose various filament runout sensor, heatbed v2, and power panic-specific code in #ifdef compiler directives to permit the disabling of those features... I am probably forgetting something but its all visible in the diffs on git.

Appendix:

Why won't 12V work as the motor drive voltage when using the TMC2130 drivers?

The TMC2130s are definitely the reason Prusa increased the voltage of the MK3 to 24V - out of necessity. I know this is not the news many of you wanted to hear, but the simple fact is that if you want to use the TMC2130 drivers to drive your motors, you need to use at least 24V (higher is even better - 28V seems to be the sweet spot for me).

The reasons are, unfortunately, neither singular nor simple. There are several compounding factors behind this, but I'll touch on them briefly for those interested.

• The loud whine is due to the motors' coil inductance. What you're hearing is the PWM chopping frequency. It should be around 26kHz, but at 12V, the drivers can't ramp up the current fast enough at a cycle-to-cycle level, so they compensate by reducing the PWM/chopping frequency. And it gets reduced straight into the audible range of human hearing. The whining you hear is the motor coils vibrating, and this is not a quiet sound. It is loud enough to be painful to my ears if I am within 3 feet of the printer.

• Overmodulation when motors are moving. At 12V, as soon as the motors begin turning at even fairly low speeds, the back EMF becomes too high. Back EMF is a voltage opposing the drive voltage... you know how the LCD lights up when you manually move the steppers but the printer is off? That's due to back EMF. It happens whenever the motor is moving, including moving under power. When this gets too close to the maximum drive voltage (12V) minus the resistive loses of the motor coils, this forces the TMC2130 drivers into their overmodulation region. This wasn't an issue for the A3982 because at 1/16th microstepping, these spikes were too fast and were outside the driver's modulation bandwidth.

Uh, this one is hard to explain. I suppose one might think of overmodulation as analogous to the distortion region of an audio amplifier. Or if anyone here is into hamatuer radio, I mean it in exactly the same way you understand overmodulation, but it is modulating coil phase current instead of radio.

You know how a smaller audio device, if you turn the volume up too high, begins to produce very unpleasant, distorted sound? You can kind of think of it as a similar effect in the motors. I looked at the phase current waveforms on my oscilloscope, and it became quite dirty as the motors began moving, heavily distorted with nasty harmonics. As a bonus, this also generates additional (and even more irritating) audible noise. It makes the driver chips have to dissipate a lot more heat than they would normally, and generally degrades all-around stepper performance, current regulation, and microstepping behavior. You can expect to see jerky, and intermittent movement (with the pauses marking periods of hundreds of skipped microsteps, all unnoticed by the firmware) at low to medium speeds (and faster) as a result of this.

• For the same reasons as overmodulation, stallGuard2 (required for calibration and all sorts of other minutia in the MK3 firmware) will never work with these motors at 12V. stallGuard2 requires the drive voltage to be greater than the resistive voltage losses plus the back emf voltage to correctly measure/detect a stall or missed step, and unfortunately, for all but the lowest speeds, 12V is not high enough to meet this requirement.

• The driver chips dissipate more power at 12V due to the above, and I would question their ability to not overheat in these conditions.

I really want to drive this home to hopefully save someone from wasting their time trying to use 12V. The only possible 'solution' would involve turning off 256 microstep interpolation and running the chips at 1/16th microstep mode, which would also disable stealth chop, stallGuard2, and every reason for even bothering to upgrade to the Einsy with it.

...
Posted : 21/04/2018 1:10 pm
devilhunter
(@devilhunter)
Reputable Member
Topic starter answered:
Re: TMC2130 Driver Infos and Modifications

Here is @metacollin's TMC2130 current calculation



Yeah, the Einsy works the same way in terms of setting the current, except that the current isn't given in mA anymore. In the Configuration_prusa.h file, near the bottom of the TMC2130 section, you'll find:

#define TMC2130_CURRENTS_H {16, 20, 28, 36} // default holding currents for all axes
#define TMC2130_CURRENTS_R {16, 20, 28, 36} // default running currents for all axes
#define TMC2130_UNLOAD_CURRENT_R 12 // lowe current for M600 to protect filament sensor

Those correspond to the X, Y, Z, and Extruder axes. Each number can be anywhere between 0 to 63. The actual current values can be calculated thusly:
CodeCogsEqn (2).gif

This is determined by the value of the current sense resistor used on the Einsy, which is 0.22Ω. While the TMC2130s in that package can do up to 1.4A RMS per phase, the Einsy board has limited the maximum current (63 in the firmware) to about 0.96A.

The current is limited to .96A because the driver chips should, theoretically, not overheat even if the user sets a maximum current value (63) for a given motor in the firmware. So if your extruder motor needed 800mA, the TMC drivers should work fine.

BUT, its actually a lot more complicated than that. Firstly, the extruder is kind of a unique load in that it needs to apply a large amount of torque from the very start of movement, and if it can't produce more than that amount, we get those dreaded clicking noises instead of extruding filament.

The thing is, the torque being produced by the motor actually varies over the step. And the peak torque is not at the start of the step, but part of the way through.

This is actually a sort of subtle detail that makes the TMC2130 chips really shine, and why they, for all intents and purposes, can achieve the same torque and speed performance from the same motors using less current. Most stepper drivers will control the phase current so it approximates a sine wave. The TMC2130 lets you tune the shape and phase of this wave and alter how the torque varies over the course of a step.

In fact, a lot of their neat special features/modes like stealth chop etc. are, at least in part, enabled by this control. Which brings us back to the higher voltage. Unless a motor has very low winding inductance, the TMC2130 won't be able to make the current ramp up quickly enough at, say, 12V, but it can make the current shoot up twice as fast with 24V. This lets the motor shift the strongest part of a step towards the start of the step, where before, we were actually kind of giving the motors more current than needed if one only went by the peak torque generated by that current. We needed a certain amount of torque to be able to even begin the step under load, so the currents had to be increased to compensate. If you can get peak torque a lot quicker at the start of the step, then you don't need to compensate as much, and ultimately, you get more step for less current.

Really, stepper motor performance is largely determined by the driver, and not the motor. In fact, I would think you could get away with using the stock prusa motors to drive that titan extruder if you just use the Einsy and its drivers. But a extra chub stepper motor won't hurt matters heh.

Long story short, you can expect better torque, more torque at higher speeds, and higher maximum speeds simply by switching to the TMC2130 drivers and upping the voltage. And you can bump the voltage up to as high as 36V according to ultimachine, and you actually just sort of get a free lunch here: the extra voltage will increase the strength and performance of the motors even if the drive current stays fixed.

Case in point, the Prusa motors used on the order of ~1800mA total, but as near as I can tell, slightly BETTER performance is achieved with the same motors at under 700mA total current draw. Just by using the TMC driver chips and 24V.

TLDR: I think you'll have no problem running those beefier motors, and you will need to run them at substantially less current.

Just expect to spend some time experimenting to dial in the current values, and start lower than you normally would. You'll also need to adjust the sg threshould values. Increasing current will usually require increasing the sg thresholds as well, otherwise you will start getting false positives for motor stall/step skipping. But all of this is clearly labeled and well organized as #defines in the Configuration_prusa.h file, so it is mostly just a matter of playing with the values, uploading to the Einsy, test, rinse, and repeat.

...
Posted : 21/04/2018 1:11 pm
devilhunter
(@devilhunter)
Reputable Member
Topic starter answered:
Re: TMC2130 Driver Infos and Modifications

Here are @metacollin's Gcode discoveries.


The Unofficial TMC2130 Gcode Guide
Now with even fewer mistakes!
Last updated April 4th, 2018.

Obsolete gcodes (these no longer work with the TMC2130):
M907 - Sets digital trimpot motor current using axis codes.
M908 - Control digital trimpot directly.

To apply changed settings:
M910 - Reset and initialize the TMC2130 chips.
Most setting changes won't go into effect until this code is sent.

Current settings:
M911 - Holding current
M912 - Running current
Set the above TMC2130 currents. Must be given in current scalar values (0 to 63).
Example: M911 X14 Y20 Z30 E36

M913 - Print the currently set TMC2130 current values

Miscellaneous:
M914 - Set normal (high power) mode.
This engages spreadCycle mode on the TMC2130.

M915 - Set silent (low power) mode.
This engages stealthChop mode on the TMC2130. This will disable stallGuard functionality.

M916 - Set sg_thrs (stallGuard threshold).
Changes sensitivity of stallGuard. Lower numbers increase sensitivity, higher numbers decrease it.
If this value is too low, you'll get false positives. Too high, and missed steps will go undetected.
Example: M916 X3 Y3 Z3 E3

Here be dragons
It's best to avoid playing with these values unless you know what you're doing. I've done my best to explain their function, but consult the TMC2130 datasheet for full documentation:
https://www.trinamic.com/fileadmin/assets/Products/ICs_Documents/TMC2130_datasheet.pdf
M917 - Set pwm_ampl (PWM amplitude).
Note: the steps/s threshold is set to 0 in the Prusa firmware, meaning that stealthChop
and spreadCycle will never change while the motors are active, so pwm_ampl isn't actually
used for anything.

This is the maximum voltage amplitude that stealthChop can be set to when returning to
stealthChop mode from spreadCycle mode. There is a steps/s threshold where the driver
switches from stealthChop to spreadCycle mode even in silent mode, and when this
happens, the last voltage needed to achieve desired motor current (which varies with step
rate due to back EMF canceling out some of the voltage on the motor windings is stored
internally by the TMC2130. When the step/s slows to below the switch-over threshold,
this voltage amplitude is recalled and used as the starting point for stealthChop as it
re-engages. If this value is incorrect, you will suffer speed-dependent motor jerks whenever
the driver switches back to stealthChop from spreadCycle. This will almost certainly ruin
a print in progress.
Example: M917 X230 Y235 Z200 E240

M918 - Set pwm_grad (PWM gradient)
Only used in silent/stealthChop mode. This limits how fast the current can be ramped up
or down in the motors per each half-cycle. Higher numbers mean faster current ramps.
Faster ramps will permit stealthChop to achieve faster acceleration but at the price of
poorer current regulation. Valid values are 0-15.
Examples: M918 X2 Y2 Z4 E4

...
Posted : 21/04/2018 1:12 pm
devilhunter
(@devilhunter)
Reputable Member
Topic starter answered:
Re: TMC2130 Driver Infos and Modifications

TMC Driver debugging:

TMC Driver debugging is working in Marlin with the TMC_DEBUG flag uncommented.
This should be the output:
SENDING:M122
X Y
Enabled false false
Set current 850 850
RMS current 826 826
MAX current 1165 1165
Run current 26/31 26/31
Hold current 13/31 13/31
CS actual 13/31 13/31
PWM scale 41 41
vsense 1=.18 1=.18
stealthChop true true
msteps 16 16
tstep 1048575 1048575
pwm
threshold 0 0
[mm/s] - -
OT prewarn false false
OT prewarn has
been triggered false false
off time 5 5
blank time 24 24
hysterisis
-end 2 2
-start 3 3
Stallguard thrs 0 0
DRVSTATUS X Y
stallguard
sg_result 0 0
fsactive
stst X X
olb
ola
s2gb
s2ga
otpw
ot
'Driver registers:'
X = 0x80:0D:00:00
Y = 0x80:0D:00:00

This is set in Configuration_adv.h
https://github.com/MarlinFirmware/Marlin/blob/ac3fab7a9680a880fd1b113be7e758c6dabb2a57/Marlin/Configuration_adv.h

It is currently missing in Prusa's fork:
https://github.com/prusa3d/Prusa-Firmware/blob/4811561ec7e01cc476e5836e239a466c77b7bd61/Firmware/Configuration_adv.h

...
Posted : 21/04/2018 1:19 pm
devilhunter
(@devilhunter)
Reputable Member
Topic starter answered:
Re: TMC2130 Driver Infos and Modifications

TMC 2130 Sine-Wave Look-up Table

I believe some of the the current extrusion issues on the MK3 firmware stem from that that nobody tried to optimize the sine wave lookup table (or microstepping table) before. Not Marlin, and therefore not the Prusa Fork of Marlin.

@jakub.d, am i wrong?

Edit: ok, im wrong. see comments further down.
There is some algorithmic linearity and current code for the sine wave form here
https://github.com/prusa3d/Prusa-Firmware/blob/MK3/Firmware/tmc2130.cpp
see tmc2130_get_wave and tmc2130_set_wave
Perhaps a more static approach would be better than a algorithmic approach?

From the TMC2130 datasheet:

The TMC2130 provides a programmable look-up table for storing the microstep current wave. As a default, the table is pre-programmed with a sine wave, which is a good starting point for most stepper motors. Reprogramming the table to a motor specific wave allows drastically improved microstepping especially with low-cost motors.

also:
In order to minimize required memory and the amount of data to be programmed, only a quarter of the wave becomes stored. The internal microstep table maps the microstep wave from 0° to 90°. It becomes symmetrically extended to 360°. When reading out the table the 10-bit microstep counter MSCNT addresses the fully extended wave table. The table is stored in an incremental fashion, using each one bit per entry. Therefore only 256 bits (ofs00 to ofs255) are required to store the quarter wave. These bits are mapped to eight 32 bit registers. Each ofs bit controls the addition of an inclination Wx or Wx+1 when advancing one step in the table. When Wx is 0, a 1 bit in the table at the actual microstep position means “add one” when advancing to the next microstep. As the wave can have a higher inclination than 1, the base inclinations Wx can be programmed to -1, 0, 1, or 2 using up to four flexible programmable segments within the quarter wave. This way even a negative inclination can be realized. The four inclination segments are controlled by the position registers X1 to X3. Inclination segment 0 goes from microstep position 0 to X1-1 and its base inclination is controlled by W0, segment 1 goes from X1 to X2-1 with its base inclination controlled by W1, etc.
When modifying the wave, care must be taken to ensure a smooth and symmetrical zero transition when the quarter wave becomes expanded to a full wave. The maximum resulting swing of the wave should be adjusted to a range of -248 to 248, in order to give the best possible resolution while leaving headroom for the hysteresis based chopper to add an offset.

Microstepping – extremely improved with low cost motors Motor – runs smooth and quiet Torque – reduced mechanical resonances yields improved torque
When the microstep sequencer advances within the table, it calculates the actual current values for the motor coils with each microstep and stores them to the registers CUR_A and CUR_B. However the incremental coding requires an absolute initialization, especially when the microstep table becomes modified. Therefore CUR_A and CUR_B become initialized whenever MSCNT passes zero.
Two registers control the starting values of the tables:
- As the starting value at zero is not necessarily 0 (it might be 1 or 2), it can be programmed into the starting point register START_SIN.
- In the same way, the start of the second wave for the second motor coil needs to be stored in START_SIN90. This register stores the resulting table entry for a phase shift of 90° for a 2phase motor.
Hint Refer chapter 5.5 for the register set and for the default table function stored in the drivers. The default table is a good base for realizing an own table. The TMC2130-EVAL comes with a calculation tool for own waves.
Initialization example for the default microstep table:
MSLUT[0]= %10101010101010101011010101010100 = 0xAAAAB554
MSLUT[1]= %01001010100101010101010010101010 = 0x4A9554AA
MSLUT[2]= %00100100010010010010100100101001 = 0x24492929
MSLUT[3]= %00010000000100000100001000100010 = 0x10104222
MSLUT[4]= %11111011111111111111111111111111 = 0xFBFFFFFF
MSLUT[5]= %10110101101110110111011101111101 = 0xB5BB777D
MSLUT[6]= %01001001001010010101010101010110 = 0x49295556
MSLUT[7]= %00000000010000000100001000100010 = 0x00404222
MSLUTSEL= 0xFFFF8056: X1=128, X2=255, X3=255 W3=%01, W2=%01, W1=%01, W0=%10
MSLUTSTART= 0x00F70000: START_SIN_0= 0, START_SIN90= 247

...
Posted : 21/04/2018 1:51 pm
devilhunter
(@devilhunter)
Reputable Member
Topic starter answered:
Re: TMC2130 Driver Infos and Modifications

Also a quick note on Microstepping:

A common misconception is that microstepping increases machine accuracy.

Microstepping was developed to allow a stepper motor driven machine to have a smoother trajectory from one step to the next. It was invented (but never patented) in 1974 by Larry Durkos, a mechanical engineer for a medical equipment vendor while working on a blood analysis machine with a 20" diameter vial conveyor turntable which tended to spill the liquid due to the jerkiness of the full step mode drive. Nowadays microstepping is commonly used to increase theoretical machine resolution while minimizing noise and vibration.

Actually, microstepping is very inaccurate, for three reasons.

One, microstepping is accomplished by shifting the current in one motor coil from one polarity to the opposite polarity in some finite number of increments, to achieve one full step as a series of micro steps. The problem is that the exact position of the rotor between steps is not tightly or linearly proportional with current. Microstepping controllers must apply an approximately sinusoidal current waveform to obtain approximately uniform motion with each microstep. Any given motor's response to any given amount of current is arbitrary, based not on current, but on the motor's electrical and mechanical characteristics. So no two stepper motors ever have exactly the same response or reach exactly the same microstep position as any given amount of current is applied. So having imperfect motors (and imperfect wiring) and approximate current values applied, one can only achieve an approximate microstep position.

Two, friction and load variation causes a shift in the actual position obtained against any given amount of current applied. Problem number one is such that even with a perfect friction free motor with no load, the exact rotor position is ambiguous. Problem number two then eponentially exacerbates problem number one in accounting for how real world friction and load variation works against being able to acheive any given position with any given current on any given motor. A loaded motor will not reach the same position as when unloaded with the same amount of current applied, because some of the current is used to overcome the load resistance, so less current is available to reach the desired position.

Under the arbitrary conditions of problem one, and the varying conditions of problem two, microstep positions are much less accurate than full or half step positions, which don't vary with current or load like microstepping does.

Third, during a microstep, the current applied is partial, which means the torque developed is partial. Simply put, the motor is weaker when less than full current is applied, as opposed to when full current is applied in a normal full step position. At certain microstep positions, mainly half way between a full and a half step, the loss of power (torque) leads to a dramatic loss of ability to reach the next desired microstep position from the previous, under load.

If we consider that full stepping provides 100% rated power, we can estimate the approximate power output of less than full step operation as follows. Half stepping yields 70% of full power. 1/4 microstepping yields 40% power, 1/8 microsteppig yields 20% full power, 1/16 yields 10%, 1/32 yields 5%, 1/64 yields 2.5%, 128 yields 1.2%, and 1/256 microstepping can only achieve 0.6% of full power toward reaching and holding at an intermediate step position. Depending on the load, intermediate microsteps might only move a fraction of the intended (unloaded) distance. Only when the step sequence coincides with a full or half step is the rotor position likely to be where intended.

The benefit of smoother operation and higher theoretical machine resolution with microstepping is offset by much lower power and not much accuracy compared to full or half step operations. Not only does the microstepping controller cost a lot more, but it also requires a much larger motor and more power to achieve the required torque to move the designated load through microstep positions.

For heavily loaded motors and/or for higher positional accuracy it is often more practical to gear down the drive system to achieve micro sized motion using full or half step operation. Half stepping with 1:4 geardown provides the same machine resolution as a 1/8 microstepper with much higher accuracy and torque, and especially more holding torque. The miniscule backlash in a 1:4 kevlar reinforced timing belt drive is comparable in magnitude with a microstepper's inherent positional variation. Any gearing inaccuracy due to backlash is very consistent whereas microstepping inaccuracy varies with rotor position. Gearing multiplies consistent full motor torque to the load, while microstepping torque varies with rotor position, and rotor positional accuracy varies with loading.

Now, microstepping does have three advantages over geared down whole step mode operation.

One, it is quieter and smoother. As the microstepper applies reduced current, the resulting motion is less energetic, and each step is that much less instantaneous, so the same amount of kinetic energy (motion) occurs over a longer time frame. Much like moving something by hitting it with a hammer. If you hit it with full power (full stepping) the load will move farther and incur more shock than if you just gently tap on it (microstepping). But as the load increases, tapping is less effective. Mid step microstepping is more like tapping while moving over bumps. The taps are less effective in some places and more effective between bumps. Using a geardown is more like using a come-along. The motion is not as shocking and it doesn't matter if the load is large or small, and the rate of motion is more consistent, reliable and predictable.

Two, microstepping is faster than half or full stepping. Even before it is geared down, a whole stepped motor's top speed is lower than if it were microstepped because the velocity is more intermittant. Both start from each full step with the same speed, but all steppers essentially stop at each subsequent step, and take off again to proceed to the next step. With whole steps, the stop and go action is very abrupt and definite. With microstepping the action is less abrupt and each step position is less definite, so the rotor inertia does not stop as abruptly or completely. Much like a rolling stop at a stop sign compared to a complete stop.

Three, microstepping can be used to produce much smoother very slow motion. Even with high gear reduction, low speed full stepping operation is really jerky. Microstepping between full steps reduces that low frequncy vibration. So microstepping can be employed in a full step strategy to get the best of both modes. The only problem with that is that most generic control systems do not have any features to impliment mixed step mode operation.

Generally speaking, for light loading, high speed, and slightly less than perfect accuracy under load, microstepping is the way to go. For heavier loads and higher precision, microstepping is less effective, though not entirely without merit. A hybrid solution that utilizes microstepping to effect whole step movement is best.

...
Posted : 21/04/2018 2:18 pm
stahlfabrik
(@stahlfabrik)
Honorable Member
Re: TMC2130 Driver Infos and Modifications

Great work!

You will crack that nut I am sure

Posted : 21/04/2018 3:44 pm
moggieuk
(@moggieuk)
Eminent Member
Re: TMC2130 Driver Infos and Modifications


TMC 2130 Sine-Wave Look-up Table

I believe some of the the current extrusion issues on the MK3 firmware stem from that that nobody tried to optimize the sine wave lookup table (or microstepping table) before. Not Marlin, and therefore not the Prusa Fork of Marlin.

Isn't the 'tmc2130_set_wave()' method in 'tmc2130.cpp' setting the current wave? The coded logic isn't clear to me but it does look like it modifies the default wave.

Edit: It looks like only the extruder motor is modified from the default sine wave. There appears to be a few algorithms built in with the ability to switch them via the 'D2130' debug command. Debug commands are not enabled and would require recompiling with DEBUG_DCODES defined.

Examples given in code:

* Example:
* D2130E?wave //print extruder microstep linearity compensation curve
* D2130E!wave0 //disable extruder linearity compensation curve, (sine curve is used)
* D2130E!wave220 // (sin(x))^1.1 extruder microstep compensation curve used

My general sense after a quick browse through the code is that this feature of the TMC2130 **is** something that Prusa has been playing with. There are EXPERIMENTAL flags in the code that demonstrate that it has been tinkered with for X,Y,Z axis as well although these currently turned off. It does look like the extruder current wave is modified (perhaps incorrectly). One other thing I noticed was that the micro-stepping of the extruder motor was changed from 64 --> 32 after the 3.1.0 firmware release.

Posted : 21/04/2018 6:06 pm
EC
 EC
(@ec)
Re: TMC2130 Driver Infos and Modifications

Me thinks Sr. Prusa needs to get an engineer from Trinamic involved (someone who actually knows what's going on vs his team) to fix this mess.

Posted : 21/04/2018 6:35 pm
devilhunter
(@devilhunter)
Reputable Member
Topic starter answered:
Re: TMC2130 Driver Infos and Modifications



TMC 2130 Sine-Wave Look-up Table

I believe some of the the current extrusion issues on the MK3 firmware stem from that that nobody tried to optimize the sine wave lookup table (or microstepping table) before. Not Marlin, and therefore not the Prusa Fork of Marlin.

Isn't the 'tmc2130_set_wave()' method in 'tmc2130.cpp' setting the current wave? The coded logic isn't clear to me but it does look like it modifies the default wave.

Edit: It looks like only the extruder motor is modified from the default sine wave. There appears to be a few algorithms built in with the ability to switch them via the 'D2130' debug command. Debug commands are not enabled and would require recompiling with DEBUG_DCODES defined.

Examples given in code:

* Example:
* D2130E?wave //print extruder microstep linearity compensation curve
* D2130E!wave0 //disable extruder linearity compensation curve, (sine curve is used)
* D2130E!wave220 // (sin(x))^1.1 extruder microstep compensation curve used

nice catch!

Other implementations on github take a different approach.

like TinWhiskers' implementaion
https://github.com/TinWhiskers/tmc2130/blob/master/tmc2130.cpp
The part with the hard MSLUT lookup tables (set_mslut)

the TMC2130 wave compression algorithm section in tmc2130_set_wave seems like a good place to start, perhaps someone actually did try to optimize the sine wave for them.
Have we anything to compare them against?

...
Posted : 21/04/2018 6:42 pm
moggieuk
(@moggieuk)
Eminent Member
Re: TMC2130 Driver Infos and Modifications

I think the first step would be to compile the latest firmware with debugging enabled. Then (carefully, because the debug flag opens up a whole bunch of bad stuff) we should be able to at least experiment with the different current waves that can be programmed with the D2130 command. I suspect that the cheap motors used on the Prusa differ quite a bit in electrical characteristics which explains why some users seem to have a worse time with this than other. For me personally, I can see the extrusion artifact, but it is not as pronounced as some pictures I've seen.

(I edited my last post, but I also saw that the micro-stepping was reduced from 64 --> 32 after 3.1.0 firmware)

Re: alternative implementations. It looks as though Prusa has taken an algorithmic approach to setting current wave, whist TinWhiskers has taken the more raw static configuration approach... Both have metric. But the static config approach is definitely more tunable, but in theory at least, unnecessary. Also, TinWhiskers appears not to be doing anything -- just setting to default values(?)

Posted : 21/04/2018 6:52 pm
reid.b
(@reid-b)
Reputable Member
Re: TMC2130 Driver Infos and Modifications

There is an experimental menu that allows you to change the stepper linearity lettings via the LCD. I was able to compile it by disabling the other features offered in this menu (if they are enabled the MK3 doesn't boot up at all, I haven't figured out why that is). I'm running some 20mm perimeter prints now to see what kind of differences one can effect by playing with these settings.

Posted : 22/04/2018 12:00 am
reid.b
(@reid-b)
Reputable Member
Re: TMC2130 Driver Infos and Modifications

Don't try the EXPERIMENTAL_FEATURES at all- the AVR gets totally trashed when any of the Experimental features are enabled. I gave up and went back to DCODEs.

Posted : 22/04/2018 9:41 am
moggieuk
(@moggieuk)
Eminent Member
Re: TMC2130 Driver Infos and Modifications


Don't try the EXPERIMENTAL_FEATURES at all- the AVR gets totally trashed when any of the Experimental features are enabled. I gave up and went back to DCODEs.

Thanks for the heads up!

Posted : 22/04/2018 4:47 pm
sean.h8
(@sean-h8)
Honorable Member
Re: TMC2130 Driver Infos and Modifications

So, I realized I'm an idiot.

Just gonna leave this here.

Hi, I'm Sean. I used to work on CNC machines.
I try to not make mistakes, but the decision is YOURS.
Please feel free to donate to my filament/maintance fund....
Posted : 23/04/2018 12:50 am
Lee
 Lee
(@lee)
Trusted Member
Re: TMC2130 Driver Infos and Modifications

//

Posted : 23/04/2018 1:22 am
sean.h8
(@sean-h8)
Honorable Member
Re: TMC2130 Driver Infos and Modifications

So many of your posts seem wilfully cryptic.

I'm not one to brag about almost blowing up my printer.
Extruder motor @ 96c when I first noticed it.

Left motor at full power after a test. I'm surprised the mounting system I have didn't melt.


Here's the test with proper lighting.

And because everyone tells me my print quality is low and I don't know what I'm doing.


There it is with the light angled to make it look better,not worse.

Hi, I'm Sean. I used to work on CNC machines.
I try to not make mistakes, but the decision is YOURS.
Please feel free to donate to my filament/maintance fund....
Posted : 23/04/2018 1:26 am
reid.b
(@reid-b)
Reputable Member
Re: TMC2130 Driver Infos and Modifications

I have exhausted all avenues changing the Microstepping table, disabling MicroPlyer, cranking current up and down, and various other changes (and I dare say my printer has pretty darn good quality all things being equal.) Nothing I have tried improves extrusion problems, nor does it appear to me that E-Correction does anything for moire problems. I'm fearing our issues may have to do with the Bondtech, or perhaps the stepper motors provided by Prusa.

I've got about 30 20mm perimeter cubes and other things- been at this all day long. Very frustrating...

Posted : 23/04/2018 7:03 am
ray.a2
(@ray-a2)
Eminent Member
Re: TMC2130 Driver Infos and Modifications

What is odd, is that the Trinamic drivers are supposedly made to even work with cheap steppers. There are a couple year old posts of other people having similar extrusion being fixed by changing the driver settings.

Its almost like some of the trinamic settings for these steppers might be hard coded somewhere and these settings are not having any visible effect.

Posted : 23/04/2018 5:12 pm
Page 1 / 2
Share: