teemuatlut / TMCStepper

MIT License
503 stars 196 forks source link

Stall guard not working with TMC2209 #190

Open pardovot opened 3 years ago

pardovot commented 3 years ago

Hey, I'm trying to use stall guard with TMC2209, and a few months ago I used the following example: https://gist.github.com/metalinspired/dcfe07ed0b9f42870eb54dcf8e29c126

Which published by metalinspired here: https://github.com/teemuatlut/TMCStepper/issues/129

Everything worked fine, but then a few weeks later when I tried that again it simply stopped working for me, I'm trying to troubleshoot that for a few months no with no results.

Things I've tried so far: Higher sensitivity ofc, tried it with 255, didn't work. Make sure that the RX, TX, EN pins are connected correctly. Tried different arduino boards(2x nano, 2x uno). Tried different TMC2209 drivers(I have a few, the same with all of them). Tried to reinstall the TMCStepper library. Tried to change the relevant parameters for stall guard(current, velocity, acceleration, TCOOLTHRS, SGTHRS). Tried to use different motors.

As for what actually happens: By using the monitor plotter, I can see that the SG_RESULT is indeed going below the stall guard value set by the driver.SGTHRS, and yet nothing happens when the motor stalls, DIAG pin doesn't change at all. When checking the driver.SGTHRS() value(which should return the stall value set to it), it seems to return the correct value which I've initially set. I can generally implement my own stall logic, but driver.SGTHRS seemed to work with the best accuracy when I first tested it and it worked.

I really have no idea what could've change, and I'm a bit lost, hopefully someone could help me troubleshoot this. BTW, I don't think it's an issue with the library, but I just have no idea what could be wrong with my setup.

Thanks.

teemuatlut commented 3 years ago

SGTHRS is a write-only register so the value read back is always the one cached by the register. It doesn't actually read anything from the driver.

Stallguard is gated by TPWMTHRS and TCOOLTHRS. I see your example sets the latter but I think it would be good to set both.

For debugging purposes you can monitor the mode the driver is in. For stallguard 4 it shouldn't switch to spreadCycle. If you have reason to question your connection from the diag output to your MCU, I believe you should be able to read the pin status from IOIN register.