Trinamic Driver Usage - bdring/Grbl_Esp32 GitHub Wiki

Trinamic Driver Support

Basic Trinamic Driver Support

Note: If you are planning on using TMC5160 drivers, see this page first

This page is for using Trinamic drivers under firmware control. It is not for Trinamic drivers used in StepStick or Standalone mode. These would be used just like normal StepStick drivers.

Grbl_ESP32 supports 2 types of Trinamic drivers. There is the SPI type and UART Type.

SPI Drivers

Currently you can only use the default SPI. Your PCB should use GPIO_NUM_32 for MOSI, GPIO_PIN_19 for MISO, and GPIO_NUM_18 for SCK.

Driver part number

For each Trinamic driver you use, you need to add a #define X_TRINAMIC_DRIVER nnnn for each axis, with nnnn being the driver model number as an integer. Currently this is limited 2130 and 5160.

CS (Chip Select) Pin

You can use separate CS pins for each driver or use a single CS pin if the drivers are wired in a daisy chain mode. If you use the daisy chain mode you must add #define TRINAMIC_DAISY_CHAIN to your machine definition file. For each motor you need to define the CS pin with #define X_CS_PIN pin. If you use daisy chain mode, each motor should use the same pin number.

UART Drivers

These use a UART to talk to the drivers. Grbl_ESP32 currently supports the TMC2209

UART settings

You must provide information about the UART with

#define TMC_UART                UART_NUM_1
#define TMC_UART_RX             GPIO_NUM_21
#define TMC_UART_TX             GPIO_NUM_22  

Addresses

Each chip must have an address. This is defined by the circuit. Define it like #define X_DRIVER_ADDRESS n, where n iss the address. This is typically 0-3.

Things common to both types

Driver Enable

  • You can use a single enable pin for all drivers with #define STEPPERS_DISABLE_PIN pin
  • You can define an enable for each motor with #define X_DISABLE_PIN pin
  • You can use the SPI to enable with #define USE_TRINAMIC_ENABLE

Sense Resistor Value

You must tell the firmware the value of each driver's sense resistors. This is required for the firmware to properly set the motor current with a #define X_RSENSE 0.11. Each motor has a default defined that is usually correct and is set like this #define X_RSENSE TMC2130_RSENSE_DEFAULT.

The rest of the stuff like step. direction, etc are the same as normal motor drivers.

Run Modes

There are run modes for normal operation and homing.

  • #define TRINAMIC_UART_RUN_MODE xxx
  • TRINAMIC_UART_HOMING_MODE xxx

The valid values for xxx are

  • TrinamicUartMode :: StealthChop
  • TrinamicUartMode :: StallGuard
  • TrinamicUartMode :: CoolStep

Here is a section of a machine definition file for reference.

// SPI Daisy chain style with software enable

#define TRINAMIC_DAISY_CHAIN
#define USE_TRINAMIC_ENABLE
	
#define X_TRINAMIC_DRIVER       2130        // Which Driver Type?
#define X_RSENSE                TMC2130_RSENSE_DEFAULT
#define X_CS_PIN                GPIO_NUM_17  // Daisy Chain, all share same CS pin
#define X_STEP_PIN              GPIO_NUM_12
#define X_DIRECTION_PIN         GPIO_NUM_14

#define Y_TRINAMIC_DRIVER       2130        // Which Driver Type?
#define Y_RSENSE                TMC2130_RSENSE_DEFAULT
#define Y_CS_PIN                X_CS_PIN  // Daisy Chain, all share same CS pin
#define Y_STEP_PIN              GPIO_NUM_27
#define Y_DIRECTION_PIN         GPIO_NUM_26
// SPI with Individual CS and Single Enable

#define STEPPERS_DISABLE_PIN GPIO_NUM_13
	
#define X_TRINAMIC_DRIVER       2130        // Which Driver Type?
#define X_RSENSE                TMC2130_RSENSE_DEFAULT
#define X_CS_PIN                GPIO_NUM_17
#define X_STEP_PIN              GPIO_NUM_12
#define X_DIRECTION_PIN         GPIO_NUM_14

#define Y_TRINAMIC_DRIVER       2130        // Which Driver Type?
#define Y_RSENSE                TMC2130_RSENSE_DEFAULT
#define Y_CS_PIN                GPIO_NUM_16
#define Y_STEP_PIN              GPIO_NUM_27
#define Y_DIRECTION_PIN         GPIO_NUM_26
// UART Drivers

#define TRINAMIC_UART_RUN_MODE       TrinamicUartMode :: StealthChop
#define TRINAMIC_UART_HOMING_MODE    TrinamicUartMode :: StallGuard

#define TMC_UART                UART_NUM_1
#define TMC_UART_RX             GPIO_NUM_21
#define TMC_UART_TX             GPIO_NUM_22  

#define STEPPERS_DISABLE_PIN GPIO_NUM_13
	
#define X_TRINAMIC_DRIVER       2209
#define X_STEP_PIN              GPIO_NUM_26
#define X_DIRECTION_PIN         GPIO_NUM_27
#define X_RSENSE                TMC2209_RSENSE_DEFAULT
#define X_DRIVER_ADDRESS        0

#define Y_TRINAMIC_DRIVER       2209
#define Y_STEP_PIN              GPIO_NUM_33
#define Y_DIRECTION_PIN         GPIO_NUM_32
#define Y_RSENSE                TMC2209_RSENSE_DEFAULT
#define Y_DRIVER_ADDRESS        1

Daisy Chain Circuit Reference

$$ Settings

Several $$ settings are used for Trinamic motors. Read this section to see more details.

StallGaurd (SG)

SG is a feature of Trinamic motors where stalls can be detected and a signal can be routed to a pin. Some people like to use this to do sensorless homing. Basic Grbl does not support this. Advanced users can implement this using custom machine functions.

This requires good programming skills and and a thorough understanding of the SG feature. Feel free to ask question on Slack about this, but it will be a lower priority for devs to answer than standard Grbl support. Consider a donation to the project if you are asking a lot of questions :-)

Very basically...SG works by looking at changes in motor efficiency. If a motor is running under a light load it is more efficient, if it starts to stall, the efficiency lowers. The driver's ability to detect this is affected by many things. It has trouble detecting changes at very high step rates and very low step rates. You need to find the best speed to home at for it to work well. Your machine setup will also affect the baseline efficiency. Its normal load, the length and gauges of the wires, etc lower the efficiency. There are several parameters you can change to "tune" SG so it works on your machine. Finally, SG is not super accurate. At best it is accurate to a few full steps. Normal switches are typically more accurate.

See this link for StallGuard tuning

Troubleshooting

Note: The drivers will not response without primary motor voltage. The ESP32 can appear to be working with USB only, but the drivers will not respond.