teemuatlut / TMC2130Stepper

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

Question: Right use of the library #31

Closed DaAndi89 closed 6 years ago

DaAndi89 commented 6 years ago

Hi guys,

hope you can help me. Since a week I´m tring to set up my tmc2130. I´ve the orginal (green) one from watterot. My supply voltage for the driver is 3.3V, VRef is at 1.1V, VM was tested between 12-18V. SPI Connection is open. My goal is the set the settings with SPI using the TMC2130Stepper library and controll the motor with the accelstepper library. I´m using a arduino uno. The stepper is a generic 1.8°/200 Steps stepper from adafruits. I want to create a controller for a camera slieder. Frist only the slieder than pan tilt astro functionality.

Problem what I have, is that my stepper runs only in low speeds. I´ve read that the arduino with its 16 Mhz is the limiting factor. But with a TB503A1 driver are getting much higher speeds. I only want the higher speed for position the camera on the slider during operation timelapse and so on the speeds that i can get at the moment are fine. But reference drive to the end stop and back i don´t want to wait für 5 min.

Below is my code example. At this configuration i need 3.4 seconds for a full rotaion. Is this a problem of my configuration of the tmc or do i´m using the tmc library in a wrong way or is this a problem with the accelstepper library.

Sorry for missusing your issue section teemuatlut but i couldn´t find you in a forum to ask you there.

#define EN_PIN    7  
#define DIR_PIN   8  
#define STEP_PIN  9  
#define CS_PIN    10 

#include <AccelStepper.h>
AccelStepper stepper(1, STEP_PIN, DIR_PIN); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

#include <TMC2130Stepper.h>
TMC2130Stepper driver = TMC2130Stepper(EN_PIN, DIR_PIN, STEP_PIN, CS_PIN);

void setup()
{  
    Serial.begin(9600);
    while(!Serial);
    Serial.println("Start...");

    driver.microsteps(0);   // Fullstep Mode
    driver.interpolate(1);  // Interpolate Fullstep to 256 Steps

/*
23.1
Initialization Example
SPI  datagram  example  sequence  to  enable the driver  for  step  and direction  operation  and  initialize the chopper for spreadCycle operation and for stealthChop at <60 RPM: 
SPI send:0xEC000100C3;      // CHOPCONF: TOFF=3, HSTRT=4, HEND=1, TBL=2, CHM=0 (spreadCycle)
SPI send:0x9000061F0A;      // IHOLD_IRUN: IHOLD=10,IRUN=31 (max. current), IHOLDDELAY=6
SPI send:0x910000000A;      // TPOWERDOWN=10: Delay before power down in stand still
SPI send: 0x8000000004;     // EN_PWM_MODE=1 enables stealthChop (with default PWM_CONF)
SPI send: 0x93000001F4;     // TPWM_THRS=500 yields a switching velocity about 35000 = ca. 30RPM
SPI send: 0xF0000401C8;     // PWM_CONF: AUTO=1, 2/1024 Fclk, Switch amplitude limit=200, Grad=1
*/

/*-----Initialization Example-----*/
/*-----Start-----*/

    driver.begin();
    driver.rms_current(600);

    driver.microsteps(0);   // Fullstep Mode          --> stepper won´t move without microsteps=0
    driver.interpolate(1);  // Interpolate Fullstep to 256 Steps    --> for smooth motion

    driver.off_time(3);               //TOFF=3
    driver.hysteresis_start(4);       //HSTRT=4
    driver.hysteresis_end(1);         //HEND=1
    driver.blank_time(36);            //TBL=2
    driver.chopper_mode(1);           //CHM=0

    driver.hold_current(10);          //IHOLD=10
    driver.run_current(31);           //IRUN=31
    driver.hold_delay(6);             //IHOLDDELAY=6

    driver.power_down_delay(10);      //TPOWERDOWN=10

    driver.stealthChop(1);            //EN_PWM_MODE

    driver.stealth_max_speed(500);    //TPWM_THRS

//  driver.                           //PWM_CONF: AUTO=1
    driver.stealth_freq(0);           //2/1024 Fclk
    driver.stealth_amplitude(200);    //Switch amplitude limit=200
    driver.stealth_gradient(1);       //Grad

/*-----End-----*/
/*-----Initialization Example-----*/

    digitalWrite(EN_PIN, LOW);

    stepper.setMaxSpeed(3500.0);
    stepper.setAcceleration(500.0);

}
void loop()
{    

    Serial.println(stepper.speed());              // Serial Monitor für Kontrolle der Einstellungen
    Serial.println(stepper.currentPosition());    // ---
    Serial.println(stepper.isRunning());          // ---

    stepper.moveTo(1000);                         // Läuft 5 Runden bei 200 Steps --> runs 5 rounds at 200 steps need approx. 3.4sec per round
    stepper.run();                                // Run Befehl

/*
  digitalWrite(STEP_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(STEP_PIN, LOW);
  delayMicroseconds(10);
*/    
}
teemuatlut commented 6 years ago

For one, you're trying to use both stealthChop and constant off time mode at the same time. The latter is a bit of a relic at this point Trinamic calls it the "classic" option. Remove driver.chopper_mode(1) from your setup.

You're also setting microsteps and interpolation twice. You're setting the current with rms_current and then overriding that with run_current and hold_current. Try to use on or the other approach.

I'd recommend not trying to set up stealthChop/spreadCycle transition thresholds before you have everything working first. Also the argument is not speed or rotations/steps/whatever. The argument is a TSTEP value which is a function of the internal driver clock frequency.

Hysteresis settings only apply to spreadCycle, so you can take them out too until you want to mix in spreadCycle for higher speeds.

3500 fullsteps/s seems quite high. That's 17.5 rounds/s for a 1.8 degree motor. Or about 700mm/s.

Basically try to simplify the set up as much as possible and build from there.