How's it going? This might be the wrong thread to ask this question, but hopefully someone knows about the Trinamic TMC2660 motor control chip. I am using the Mega 2560 for my project.
To start, here is the constructor for motor control:
TMC26XStepper tmc26XStepper = TMC26XStepper(200,CS,DIR,STEP,350);
All internal parameters for the chip are set via SPI. The 350 mA is the parameter to set the current that will flow through the motor coils. For mechanical reasons, I need to increase the current in order to get the motor to drive without jittering. (It's a 1.3 Amp Lin Engineering motor).
In the TMC26XStepper library (github - Trinamic), there is a function void setCurrent(unsigned long current)
. It seems that this can be called at any point in the program (and at best, probably not when the motor is actually running.)
When the constructor is created, setCurrent(350)
is called. When I need to run the motor (for a specific scenario), I would like to set the current to 600 mA. I am unable to do so. Even when I try to set the current to 350, my program stops working. In the setup()
function, the motor is driven once before the loop()
function begins. It has no problem doing so.
I will show you the code, and the error (after debugging) occurs during an SPI transfer.
#include "Vial_Control.h"
#include "Arduino.h"
#include <TMC26XStepper.h>
TMC26XStepper tmc26XStepper = TMC26XStepper(200,CS,DIR,STEP,350);
// CS - 46, DIR - 44, STEP - 45
/** this function sets the initial motor settings....in relation to the current, these may be irrelevant, but you never know. I call this in `setup()` **/
void Vial_Control::vialBegin()
{
tmc26XStepper.setSpreadCycleChopper(2,24,8,6,0);
tmc26XStepper.setMicrosteps(32);
tmc26XStepper.setStallGuardThreshold(8,0);
tmc26XStepper.start();
digitalWrite(direction, HIGH);
}
/** This is the function I use to drive the motor, which can happen at any point in time during the program lifecycle. I wish to set the current before the drive occurs. **/
void Vial_Control::selection()
{
tmc26XStepper.setCurrent(600);
// delay(1000) - I tried seeing if this would help, it didn't.
moveMotor();
}
In order to keep this post from getting longer, here's the Github link to the TMC26XStepper library:
https://github.com/trinamic/TMC26XStepper
The important functions to look at in relation to my issue are
void setCurrent(unsigned long current)
and
inline void send262(unsigned long datagram)
send262
is the last function in the .cpp file.
Here's a step-by-step list of events before the error.
- I initiate a drive in the motor.
-
void selection()
is called. -
tmc26XStepper.setCurrent(600)
is called. - All procedures in that function run smoothly, until the end, when...
- the first
send262(...)
gets called afterif (started)
is evaluated. - Debugging it, I find that
i_datagram = SPI.transfer((datagram >> 16) & 0xff);
gets "stuck".
Is there something that would cause the SPI transfer to get hung up like that? If you need more information, I will provide it.
Thank you,
Anthony