I'm trying to use the TMC2130 v3 stepper driver to generate step pulses itself, w/o sending step/dir commands, offloading the MCU.
My HW conf is arduino mega r3 with RAMPS 1.4 shield and 5 Bigtreetech TMC2130 v3 configured in SPI mode.
Wiring is proven correct, since I can configure the drivers over SPI (e.g. microstepping mode, max current etc), then I can spin the motors with step/dir command generated by the MCU.
However, when trying to set the TMC drivers to generate step pulses on their own (using conf registers), motors are inert.
I'm using the TMC2130Stepper or the newer TMCStepper libs - unfortunately all examples are using step/dir mode as opposed to standalone pulse generation by the driver.
Anyone who ever succeeded to drive the TMC2130 stepper driver over SPI w/o issuing step commands from the MCU, pretty please advise.
Below a sample code that seems correct to me yet doesn't spin the motor
#include <SPI.h>
// Define TMC2130 register addresses
#define GCONF_REGISTER 0x00
#define IHOLD_IRUN_REGISTER 0x10
#define TPOWERDOWN_REGISTER 0x18
#define TSTEP_REGISTER 0x2F
#define TPWMTHRS_REGISTER 0x90
// Define SPI pins
#define SS_PIN 32 // Slave Select pin
#define ENABLE_PIN 38
// Define constants for configuration
#define STEPS_PER_SECOND 1000 // Desired speed in steps per second
void setup() {
pinMode(ENABLE_PIN, OUTPUT); digitalWrite(ENABLE_PIN, LOW); // enable motor
SPI.begin(); // Initialize SPI communication
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0)); // Configure SPI settings
// Configure TMC2130 registers
writeRegister(GCONF_REGISTER, 0x00010101); // Use StealthChop for all axes
writeRegister(IHOLD_IRUN_REGISTER, 0x00011F00); // Current: 1.0A, Hold current: 0.7A
writeRegister(TPOWERDOWN_REGISTER, 0x00000000); // Set TMC2130 in normal mode (not powered down)
setStepRate(STEPS_PER_SECOND); // Set step rate
SPI.endTransaction();
}
void loop() {
// nothing here, driver should handle pulse generation
}
void writeRegister(uint8_t address, uint32_t data) {
// Send the address and data to the TMC2130
digitalWrite(SS_PIN, LOW); // Select the TMC2130
SPI.transfer(address | 0x80); // Set the write command bit
SPI.transfer((data >> 24) & 0xFF); // Send the MSB
SPI.transfer((data >> 16) & 0xFF);
SPI.transfer((data >> 8) & 0xFF);
SPI.transfer(data & 0xFF); // Send the LSB
digitalWrite(SS_PIN, HIGH); // Deselect the TMC2130
}
void setStepRate(uint32_t stepsPerSecond) {
// Calculate the value to be written to the TSTEP register for desired steps per second
// The formula is: TSTEP = 2^20 / stepsPerSecond
uint32_t tstep = (1048576 / stepsPerSecond) - 1;
writeRegister(TSTEP_REGISTER, tstep);
}
Indeed, datasheet advises to rely on an external sine generator e.g. TMC4361 or TMC429 - in which case, from the TMC2130 perspective there is no real diff between getting step commands from the MCU or an external generator - can't see the point why they yield different operation modes...
I had the misfortunate idea of asking chatGPT, hence the confusion
prompt:
can i program the tmc2130 stepper driver to generate pulses on its own, without having the MCU to send step commands?
chatGPT:
Yes, you can configure the TMC2130 stepper driver to operate in "standalone" mode where it can generate pulses on its own without the need for the MCU to continuously send step commands. This feature is often referred to as "StealthChop" mode in Trinamic stepper motor drivers, including the TMC2130.
In StealthChop mode, the driver can generate its own step pulses based on the configuration parameters set via SPI (Serial Peripheral Interface) communication. These parameters include speed, acceleration, and other motion-related settings. Once configured, the TMC2130 can autonomously control the stepper motor without real-time commands from the MCU.
However, please note that while standalone operation is possible, the MCU is typically still involved in setting up the initial parameters and handling higher-level control tasks. So, although the MCU doesn't need to continuously send step commands during motion, it is still responsible for initializing the driver and providing high-level commands or adjustments as needed.
Additionally, the exact steps to configure the TMC2130 for standalone operation would depend on the specific implementation and the firmware/library you're using. Be sure to consult the datasheet and application notes provided by Trinamic for detailed instructions on configuring the driver for your particular application.
chatGPT is not highly regarded on this forum, as it produces more nonsense than useful code.
This "Once configured, the TMC2130 can autonomously control the stepper motor without real-time commands from the MCU" is clearly nonsense. Additional parameters, such as number of steps to execute, would be required.
I can see why
Still it seemed to actually make sense for a second... since the driver gets a clock signal from the MCU, in theory it could use it to generate pulses for a constant speed, based on momentary register config. Changing the speed could be possible via register changes.
Thanks a lot for clarifying. Topic closed as far as i'm concerned... wish i didn't lost a day exploring this, and your time to reply to a rather silly question.