6 Pack StallGuard Setup - bdring/6-Pack_CNC_Controller GitHub Wiki
Overview
This is a quick overview of how to setup StallGuard on a 6 Pack Controller
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.
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 energy loss, like wiring and motor construction, the driver allows you to set the level where the stall is indicated.
The method does not work well 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.
First some general thoughts on when to use it.
In my experience it is not as accurate as basic mechanical switches. It appears to be accurate to within 1 to 2 full motors steps. This is fine for some machines, but if you are hoping for repeatability for use with fixtures and offsets, I would not recommend it. It is sensitive to speeds. You can usually find a good and reliable speed for homing, but using it with hard limits might not be reliable with high speed rapids or slow moves.
I have not tested it with auto squaring. That will make things even more complex.
Setting up the hardware
Drivers with StallGuard have a few extra pins than normal StepStick type drivers. They are located on the top edge of the module. The pin closer to the middle is the Diag1 pin. Grbl_ESP32 configures the driver to output a signal on this pin when a stall is detected.
This signal needs to get to the ESP32. All available pins on the ESP32 are broken out to the modules, so a set of jumpers allows you to use some of those pins. Place a jumper shunt on the signal you want to use.
This means that you should not use the associated module socket. There are labels to show you what pins are affected. Motor Socket 1 goes to the jumper for stallguard 1. Use the module pin label to determine which pin is affected.
You also need to make sure all of the other jumpers are set right. The Vcc should should be at 3.3V. This is because the 3.3V ESP32 is now connected directly to the drivers.
This set of 3 jumpers need to be connected to the SPI side. If you are using TMC5160, this jumper needs to be set on the TMC5160 side. It grounds a clock pin for modules that do not do that internally.
Setting up machine definition definition in firmware
You need to set the Trinamic modes of operation. Use these defined values.
#define TRINAMIC_RUN_MODE Motors::TrinamicMode::CoolStep // (can be any mode)
#define TRINAMIC_HOMING_MODE Motors::TrinamicMode::StallGuard // (required)
You also need to define limits pin for the axes you are using with Stallguard
#define X_LIMIT_PIN GPIO_NUM_33 // (Sg1 See Board Silkscreen)
Make sure the driver number and rsense values are correct for your drivers.
Setting Values
Set the settings below. X is used, but this applies to any axis with
-
Set $X/Current/Run to the value you will use on your machine
-
Set $Homing/Feed and **$Homing/Seek **to the same thing and a good starting value like (400mm/min)
-
Make sure $Homing/DirInvert is right for the axis
-
Turn on Stallguard Reporting with $Reporting/StallGuard=X
-
Check inversion
Testing and Tuning
Turn on the display of StallGuard data with $Report/StallGuard=X. 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.
[MSG:X Stallguard 0 SG_Val: 0168 Rate: 00352 mm/min SG_Setting:5]
[MSG:X Stallguard 0 SG_Val: 0087 Rate: 00400 mm/min SG_Setting:5]
[MSG:X Stallguard 0 SG_Val: 0072 Rate: 00400 mm/min SG_Setting:5]
[MSG:X Stallguard 1 SG_Val: 0000 Rate: 00400 mm/min SG_Setting:5]
This is what the values mean...
- X This is the axis being displayed
- Stallguard 0 This shows whether a stall has been detected. 1=stall detected.
- SG_Val: 0168 This is the current value of the Stallguard sensor. You want to get this to 0000
- Rate: 400 This is the current step rate Grbl_ESP32 is producing. This should be close to your $HomingSeek value, but will rise and lower due to acceleration and deceleration
- SG_Setting:5 This is the current $xStallGuard setting.
Set the $HomingSeek to a mid range value like 400mm/min.
Set the $StallGuardTuning to a typical value of 10.
Home using $HX. Add a load to the motor close to stalling it. Watch the values.
You want the value to drop to 0 and the SG to change from 0 to 1.
Try different speeds and $xStallGuard values.
Lower values = $xStallGuard lower make it more sensitive.
Try adjusting $xStallGuard up and down until you get a the best sensitivity without false triggers. Record your result.
Try different $HomingSeek values with the same process.
Use the best combination of values you find.