janelia-arduino / TMC2209

The TMC2209 is an ultra-silent motor driver IC for two phase stepper motors with both UART serial and step and direction interfaces.
Other
178 stars 28 forks source link

Driver must be reset by removing power #76

Open SoupySoups opened 2 months ago

SoupySoups commented 2 months ago

This issue has been driving me crazy. I have a single driver board with an esp32 and seem to be having some weird behavior. Here is my schematic (sorry for the awful layout, I usually have time to do better) schem There are a couple undesired behaviors that I have found:

  1. Upon being stalled (on purpose by my hand) the motor will kinda just give up. There is lots of torque but it will die and not work again. Resetting does not help. The only thing that causes the motor to live again is to remove then apply motor power again.

Motor is being powered via a barrel jack, @24v with up to 8A at its disposal.

peterpolidoro commented 2 months ago

By reset, do you mean you setup the driver again? Is your step and direction controller also resetting to zero velocity and then accelerating again back up to your desired speed? Once the motor stalls and slips, the current signals will be out of sync with the motor windings. After you detect a stall, you should probably stop the controller step pulses, wait for a time for everything to stop and settle, then accelerate again back up to velocity. Even doing that, do you still need to reset power to the driver? If so, can you please include your code so I can see what might be happening with the driver?

SoupySoups commented 2 months ago

When I say reset, I have been using the blanket method of changing the enable pin of the esp32 which completely restarts it. Not included in this code sample (because it does not have an effect to this issue) I do have an acceleration function that allows me to get higher speeds.

Here is my code

#include <TMC2209.h>

HardwareSerial & serial_stream = Serial1;

const int RX_TMC = 17;
const int TX_TMC = 18;
const int EN_TMC = 4;
const int STEP_TMC = 5;
const int DIR_TMC = 6;

const uint8_t RUN_CURRENT_PERCENT = 100;

// Instantiate TMC2209
TMC2209 stepper_driver;

void setup()
{
  Serial.begin(115200);

  stepper_driver.setup(serial_stream, 115200, TMC2209::SERIAL_ADDRESS_0, RX_TMC, TX_TMC);
  stepper_driver.setAllCurrentValues(RUN_CURRENT_PERCENT, RUN_CURRENT_PERCENT, 1000);
  stepper_driver.setMicrostepsPerStep(32);
  stepper_driver.enable();
}

void loop()
{
  if (not stepper_driver.isSetupAndCommunicating()) {
    Serial.println("Stepper driver not setup and communicating!");
    return;
  }

  stepper_driver.moveAtVelocity(10000);

  delay(5);
}

Im not sure im using the term stall correctly. There are no vibrations, no movement, nothing. How would I detect such a "stall"? I have looked at the status struct, no data seems to be different from when it is moving and when it is not.

SoupySoups commented 2 months ago

https://github.com/janelia-arduino/TMC2209/assets/101527636/30f8f5a3-decb-4f2e-a933-c618e4b8147f

Here is it in real life.

peterpolidoro commented 2 months ago

I am not sure what is the problem exactly. Try putting a delay(4000); after stepper_driver.enable(); in the setup. Maybe the driver needs a little time to settle after stalling and then being commanded to stop before being commanded to move at a new velocity.

SoupySoups commented 2 months ago

Same result. Is there any reason why it would give up? Not only is it stalling but the tmc stops outputting signals when it is stopped. I know this library comes with many of the safer parameters set, is there a chance that there is some setting set to protect the hardware?

peterpolidoro commented 2 months ago

The driver might shut itself down if it is getting too hot. The datasheet also says:

A motor stall or a sudden change in the motor velocity may lead to the driver detecting a short circuit or to a state of automatic current regulation, from which it cannot recover. Clear the error flags and restart the motor from zero velocity to recover from this situation.

I will add a function to read the global status and another to clear the global status. Then on reset I will make it clear the global status by default. That might fix your problem, I will let you know when I update the version.

peterpolidoro commented 2 months ago

Ok I have updated the library to version 9.4.0. This version automatically clears the drive error when it resets. You can also call clearDriveError() to clear it yourself to recover from a stall without resetting. Can you please try that version and see if it works for you?

SoupySoups commented 2 months ago

Apologies for the delayed response. None of the temperature statuses have been triggered when the behavior occurs. Version 9.4.0 does not solve the problem. Calling any of the new functions within the loop does not change anything. Additionally, using the code

  TMC2209::GlobalStatus gstat = stepper_driver.getGlobalStatus();

  Serial.println("GlobalStat:");
  Serial.print(" - reset: ");
  Serial.println(gstat.reset);
  Serial.print(" - drv_err: ");
  Serial.println(gstat.drv_err);
  Serial.print(" - reserved: ");
  Serial.println(gstat.reserved);
  Serial.print(" - uv_cp: ");
  Serial.println(gstat.uv_cp);

Reveals that no values change in the time that the motor is running vs the time in which it has stopped.

SoupySoups commented 2 months ago
GlobalStat:
 - reset: 1
 - drv_err: 0
 - reserved: 69246976
 - uv_cp: 0
SoupySoups commented 2 months ago

It seems to not be an issue when stealthchop is disabled but I cant get reliable operation without stealthchop. (Especially at low speeds)

peterpolidoro commented 2 months ago

Only stealthchop, that is interesting. I am not sure what is happening, I will have to dig through the datasheet when I have more time. Is the speed you are jumping to very fast? The datasheet does say you may need to increment the speed in steps when using moveAtVelocity. I am not sure why it would work at first and then stop working after a stall though. Does the driver seemed disabled or is it still attempting to spin the motor? Other TMC drivers have an option to stop on stall detection, but I do not think the TMC2209 has this option.

SoupySoups commented 2 months ago

no the speed is not fast at all, my accel function starts at 0. The driver is completely disabled, no attempt to spin.

SoupySoups commented 2 months ago

At lower speeds it will even give up without any torque. It will move a little bit, a couple of steps, then give up.