Craos
February 5, 2024, 9:15am
1
Hi, I would like to control sliding doors using a stepper motor or normal one. The issue is, I need a feedback giving me information, that the door cannot move for a reason. As far as I know, it is possible to read current from some stepper drivers or it is possible to get information about "missed step". May be TMC2208 driver can provide this information. Please, could anybody point me in right direction? I am not able to find any detailed information about this.
gcjr
February 5, 2024, 12:19pm
2
most h-bridges , which could be used to drive a stepper motor allow a sense resistor to measure current in order to detect a stalled motor
An encoder on the stepper would be the best solution.
If you told the motor to go 5 steps and the encoder says 0 then you know there is a problem.
Sounds like you could use the "stall guard" feature, but this exists on TMC2209 and not TMC2208.
opened 06:57PM - 05 Feb 21 UTC
Hi all,
I am trying to set up a small machine using the TMC 2209 driver and wan… t to use the sensorless homing feature. So my idea is to have the stepper run until it reaches the end and have it stop when the driver reports a stall.
I am running this on an Arduino Uno using the CNC shield. I got the thing up and running with the driver in UART mode, communication appears to work, I can control the stepper and query the driver. But I do not find any documentation what it actually is reporting and how I can use that to detect the stall.
Below is my code, bits and pieces copied together from various examples. After setting up the driver it is executing a home() function that should stop when the driver reports the stall. What is the correct code piece to make that work? Also it appears that reading the driver.SG_result() function is rather slow, so I might need another approach to have get the motor run at a higher speed during homing (it is rather slow now).
Any help is highly appreciated!
Best regards
Reiner
```cpp
/**
* Author Teemu Mäntykallio
* Initializes the library and runs the stepper
* motor in alternating directions.
*/
#include <MultiStepper.h>
#include <TMCStepper_UTILITY.h>
#include <TMCStepper.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
#define DIR_PIN_X 5 // Direction
#define STEP_PIN_X 2 // Step
#define SW_RX_X 10 // TMC2208/TMC2224 SoftwareSerial receive pin
#define SW_TX_X 9 // TMC2208/TMC2224 SoftwareSerial transmit pin
#define DRIVER_ADDRESS 0b00 // TMC2209 Driver address according to MS1 and MS2
#define R_SENSE 0.11f // Match to your driver
TMC2209Stepper driver_x(SW_RX_X, SW_TX_X, R_SENSE, DRIVER_ADDRESS);
#define STALL_VALUE 100 // [0..255]
bool shaft = true;
#include <AccelStepper.h>
AccelStepper stepper = AccelStepper(stepper.DRIVER, STEP_PIN_X, DIR_PIN_X);
void home() {
driver_x.shaft(false);
lcd.setCursor(0, 1);
lcd.print("Going home");
bool run = true;
while (run) {
digitalWrite(STEP_PIN_X, HIGH);
delayMicroseconds(100);
digitalWrite(STEP_PIN_X, LOW);
delayMicroseconds(100);
if (driver_x.SG_RESULT() > 100)
run = false;
}
driver_x.shaft(shaft);
}
void setup() {
Serial.begin(115200); // Init serial port and set baudrate
while (!Serial); // Wait for serial port to connect
Serial.println("\nStart...");
pinMode(STEP_PIN_X, OUTPUT);
pinMode(DIR_PIN_X, OUTPUT);
// Enable one according to your setup
driver_x.beginSerial(115200); // SW UART drivers
driver_x.begin(); // SPI: Init CS pins and possible SW SPI pins
// UART: Init SW UART (if selected) with default 115200 baudrate
driver_x.toff(5); // Enables driver in software
driver_x.rms_current(400); // Set motor RMS current
driver_x.microsteps(16); // Set microsteps to 1/16th
//driver.en_spreadCycle(false); // Toggle spreadCycle on TMC2208/2209/2224
driver_x.pwm_autoscale(true); // Needed for stealthChop
driver_x.shaft(shaft);
driver_x.TCOOLTHRS(0xFFFFF); // 20bit max
driver_x.semin(5);
driver_x.semax(2);
driver_x.sedn(0b01);
driver_x.SGTHRS(STALL_VALUE);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("INIT");
home();
}
int count = 0;
void loop() {
lcd.setCursor(10, 3);
lcd.print(count++);
static uint32_t last_time = 0;
uint32_t ms = millis();
// Run 5000 steps and switch direction in software
for (uint16_t i = 100; i > 0; i--) {
digitalWrite(STEP_PIN_X, HIGH);
delayMicroseconds(100);
digitalWrite(STEP_PIN_X, LOW);
delayMicroseconds(100);
}
delay(150);
shaft = !shaft;
driver_x.shaft(shaft);
for (uint16_t i = 100; i > 0; i--) {
digitalWrite(STEP_PIN_X, HIGH);
delayMicroseconds(100);
digitalWrite(STEP_PIN_X, LOW);
delayMicroseconds(100);
}
shaft = !shaft;
driver_x.shaft(shaft);
delay(1000);
delay(100);
Serial.print(driver_x.SG_RESULT(), DEC);
Serial.print(" ");
Serial.println(driver_x.cs2rms(driver_x.cs_actual()), DEC);
}
```
You cannot detect a stalled stepper simply by measuring the current. This is only possible with 'normal' DC motors