teemuatlut / TMCStepper

MIT License
514 stars 202 forks source link

TMC5161 Can't get high speed on motors #115

Open christophepersoz opened 4 years ago

christophepersoz commented 4 years ago

Hello,

I tried several examples and different parameters on the examples provided, and none of them allowed me to reach the 1/3 of the motor speed.

At this time, I'm running the driver TMC5161 from FYSETC on a Teensy3.6. There is no other components.

On the example Simple.ino for example, I modified it and used TMCStepper library to make it working. Here the code,

/**
 * Author Teemu Mäntykallio
 * Initializes the library and runs the stepper
 * motor in alternating directions.
 */

#include <TMCStepper.h>

#define EN_PIN           0 // Enable
#define DIR_PIN          8 // Direction
#define STEP_PIN         7 // Step
#define CS_PIN           10 // Chip select
#define SERIAL_PORT Serial // TMC2208/TMC2224 HardwareSerial port

#define R_SENSE 0.075f // Watterott TMC5160 uses 0.075

// Select your stepper driver type
TMC5160Stepper driver(CS_PIN, R_SENSE);

void setup() {
  pinMode(EN_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);
  digitalWrite(EN_PIN, LOW);      // Enable driver in hardware
  SPI.begin();                    // SPI drivers
  SERIAL_PORT.begin(115200);      // HW UART drivers
  while (!SERIAL_PORT) {}

  driver.begin();                 //  SPI: Init CS pins and possible SW SPI pins
  driver.toff(5);                 // Enables driver in software
  driver.rms_current(800);        // Set motor RMS current - 800mA
  driver.microsteps(16);          // Set microsteps to 1/16th

  driver.en_pwm_mode(true);       // Toggle stealthChop on TMC2130/2160/5130/5160 - quiet stepping
  driver.pwm_autoscale(true);     // Needed for stealthChop

   SERIAL_PORT.println("Start...");
}

bool shaft = false;

const uint8_t max_spd = 45;
const uint8_t min_spd = 180;
uint16_t spd = min_spd;

void loop() {
  // Run 8000 steps and switch direction in software  
  for (uint16_t i = 6000; i>0; i--) {
    digitalWriteFast(STEP_PIN, HIGH);
    delayMicroseconds(spd);
    digitalWriteFast(STEP_PIN, LOW);
    delayMicroseconds(spd);
  }
  //shaft = !shaft;
  //driver.shaft(shaft);
// only run in one way and reduce the delay on each loop to accelerate the steps
  if (!shaft)
  {
    if (spd < 85)
      spd -= 1;
    else
      spd -= 5;
    if (spd < max_spd)
      spd = min_spd;
    Serial.println(spd);
  }
  Serial.print('.');
}

On this exemple, arriving to a delayMicroseconds of 48, the motor start to lose steps and then skip all of them. But the point is that happens to a really low speed compare to what I can get by running the same motor on my old L6470 driver.

I also tried to drive the steps with the TeensyStep library, and the result is the same, the motor stop running at 2000 step/s with micro steps set to 1/16th. It's also a really low speed compare to what I'm getting on the L6470.

Does the 5160 register function are the same for the 5161? or Does anybody have the same issue or have and idea on what I'm doing wrong?

Thanks!

viktoschi commented 4 years ago

hi can you look on the PCB which sense resistor is soldered? on the btt 5161 we have R062 which means 0.062 try motorcurrent 580mA. apart from that 5160 has external mosfets. 5161 has internal mosfets. maybe it helps to study the datasheet from trinamic 5161.