StallGuard Tuning - Longus/FluidNC GitHub Wiki

Overview

Trinamic drivers have 2 basic modes. SteathChop is the super quiet mode and CoolStep is a mode where the driver can dynamically increase the current when the motor is under load. Since CoolStep can determine the load, in many cases it can sense when the motor is about to stall or has already stalled. For further reading, Trinamic has an app note about StallGuard.

It does this by measuring the ratio of energy sent to the motor and energy returned. As the load on a motor increases, less energy is returned. When the returned energy falls to a certain point, the driver will indicate a stall. Since there are many sources of power loss, like wiring and motor design, the driver allows you to set the level where the stall is indicated.

Each machine needs to be tuned for motor size/current, speeds, mass, etc. It is a slow and time consuming process. The firmware can only help a little because this is purely a driver features.

The method does not work at very low and very high speeds. You must test your system to determine a good speed to for stall detection to avoid missed stalls or false indications.

Is StallGuard right for you?

At best it is accurate to about 1-2 full steps. Most basic switches will be more accurate. The accuracy may be fine for X and Y on a 3D printer or pen plotter, but probably not for a router or laser engraver.

  • Due to it not working well at low and and high speeds, it is not recommended for use with hard limits (full time limit detection).
  • It has not been tested with dual motor axes.
  • It will not work with CoreXY, because 2 motors are used for each axis move.
  • It is not recommended for machine like routers that can have high loads on the axes.

Config File Setup

Here are the config file setting that apply to Stallguard homing. You still need all the other settings, but these specifically apply to this mode.

  • Set homing/feed_mm_per_min and seek_mm_per_min to the same value and to a medium speed. StallGuard is less sensitive at high and low speeds.
  • The diag1 pin on the stepper driver should directly connect to the limit switch input. Typically this is active high.
  • Select a middle range value for stallguard, like 15. This will be tuned later.
  • Set stallguard_debug to false. It will be set to true when tuning.
  • homing_mode must be StallGuard
homing:     
      feed_mm_per_min: 200.000
      seek_mm_per_min: 200.000
motor0:
      limit_neg_pin: gpio.4:high
      tmc_2209:      
        stallguard: 15
        stallguard_debug: false
        homing_mode: StallGuard

Testing and Tuning

Turn on the display of StallGuard data with $/axes/x/motor0/tmc_2209/stallguard_debug=true. This will cause StallGuard data to be output to the USB/Serial port. It must use the serial port for best speed and timing of the data. The data will look like this. These are 4 readings directly before a stall was detected. Note: Only use this reporting when tuning. Turn off the reporting when running normal gcode.

[MSG:INFO: X Axis SG_Val: 206   Rate: 200.000 mm/min SG_Setting:30]
[MSG:INFO: X Axis SG_Val: 168   Rate: 200.000 mm/min SG_Setting:30]
[MSG:INFO: X Axis SG_Val: 70    Rate: 200.000 mm/min SG_Setting:30]
[MSG:INFO: X Axis SG_Val: 0     Rate: 200.000 mm/min SG_Setting:30]

This is what the values mean...

  • X Axis This is the axis being displayed
  • SG_Val: 0168 This is the current value of the StallGuard sensor. You want to get this to 0. The reporting is slowed down to prevent interfering with the motion, so you may not actually see it a get to a 0 when it triggers.
  • Rate: 200 mm/min This is the current step rate Grbl_ESP32 is producing. This should be close to your $/axes/x/homing/seek_mm_per_min (or feed) value, but will rise and lower due to acceleration and deceleration
  • SG_Setting:30 This is the current $/axes/x/motor0/tmc_2209/stallguard setting.

Home using $HX. Add a load to the motor close to stalling it. Watch the values.

You want SG_Val: to drop to 0.

Try different speeds and $/axes/x/motor0/tmc_2209/stallguard values.

Lower values = $/axes/x/motor0/tmc_2209/stallguard lower make it more sensitive.

Try adjusting $/axes/x/motor0/tmc_2209/stallguard up and down until you get a the best sensitivity without false triggers. Record your result.

Try different homing speed values with the same process.

Use the best combination of values you find.