teemuatlut / TMC2130Stepper

Arduino library for Trinamic TMC2130 Stepper driver
MIT License
159 stars 50 forks source link

How to control with SPI Mode? (without STEP Pin) Example needed #68

Closed martinmatias closed 5 years ago

martinmatias commented 5 years ago

Hi All, I want to move stepper motor through control TMC2130. I undestand that it can be done using using only SPI (I mean without EN, STEP and DIR PINS). How that possible?

After setting direct_mode to 1 dont know how to move the stepper.

I have succesfully run all examples, I have SPI connection OK (using arduino UNO and ESP8266) and checked SPI connection (it works OK)

Regards Martin

teemuatlut commented 5 years ago

With direct mode you have to control the coil currents manually using the XDIRECT register, or with methods coil_A and coil_B. What values to use becomes clear when you examine how the stepper motor works in principle.

By the sound of it, you'd likely rather want to use a driver from the TMC5xxx range and make use of the ramp generator, but I don't know if this is a possibility for you.

martinmatias commented 5 years ago

Hi, thanks for your reply. I'm working on a project (blinds control, nothing to do with 3D printer). Until I found TMC2XXX I was using pololu a4988 controlled using ESP8266 wifi module. a4988 is a little bit noisy and needed sensors at both ends (I was using hall sensor effect, whitch require a cable trough all the blind length). I thought that TMC2130 would reduce noise and with Stallguard2 can avoid sensors. So, can you provide few examples about how to use XDIRECT register? If I have to be switching betwen coil_A and coil_B per every movement I think it would not be possible.

If not, is there any example using stallguard2 and a library like AccelStepper.h? TMC2130_AccelStepper example dont allow to use stallguard (I think). Also, I've succesfully made stallguard example work on Arduino UNO, but then I've tried to modify code to move through loop (like simple example) but see that DRV_STATUS() value didnt change anymore (like many issues posted here regarding Interrupts).

Any idea or solution would be appreciated. Regards Martin

teemuatlut commented 5 years ago

Using the XDIRECT register is no different from the others, but you'd have to track your own sine wave. The mode I think is mainly meant to be used with an external motion controller. Be it your main MCU or another external controller that handles position to coil current logic.

This bit from the datasheet (p29) makes me think that direct mode is not your best solution:

coolStep and stallGuard only can be used, when additionally supplying a STEP signal.

I don't have another example to be used with the AccelStepper but as stallGuard works best when the stepping is done in an interrupt, I think you could get somewhere if the stepper.run(); command is placed in the ISR. Overall using stallGuard is just setting the correct settings and stepping at uniform intervals (ISR).

martinmatias commented 5 years ago

OK, I agree with you. If stallguard only can be used with STEP signal only, SPI mode is not what I'm looking for, I'll try placing stepper.run() inside ISR and then comment into another user for other if they want to use it. I'll close this issue. Regards Martin

elavarasibaskar commented 3 years ago

Hi,

Do you have any update on using the stepper.run() inside ISR to enable StallGuard cause I also have the same kind of application where I need to use Coolstep, StallGuard feature and also enabling SPI mode from where I can control both Step and Direction without using Step and Direction pin externally. Any help on this will be really helpful. Thanks in Advance.

teemuatlut commented 3 years ago

It sounds more like you should rather be using the TMC5160 / 5161 / 5130, which support the internal ramp generator.

The TMC2130 isn't really well suited to be used without step and dir lines.

elavarasibaskar commented 3 years ago

@teemuatlut Thanks for the info.