And there is no command that I can see that lets me set something like:
driver.setSpeed
//or
driver.runSpeed;
Which are commands that the drivers in MobaTools and AccelStepper seem to have..and I don't believe I can use MobaTools or AccelSteppel to initalize the same driver at the same time, to run those commands.
The code in #38 shows that the dir and step pins are initialized, as far as I can tell. I am struggling to find a correlation between the datasheet's explanations and the commands in the TMC2209 library, though.
Maybe think of it as needing one driver to do the software/UART configuration and a separate second driver to do the STEP/DIR acceleration/targeting/stepping/motion control. It looks like you setup both drivers in #38, but you don't seem to use the fastAccelStepper motion control driver in loop(). I can't test your code since I don't have your hardware setup.
Can you use a plain STEP/DIR FastAccelStepper example like:
...but modified to work with your current hardware and wiring?
The follow code does seem to work better. I misinterpreted the "setSpeedInUs" control at first, it needs to be descending in value (in microseconds)..
Using this code, the motor seems to eventually reach a speed that it finds unsustainable and starts to crash out, for lack of a better term. It gets substantially noisier and more "vocal" when this happens.
Just to make sure I understand a few things correctly:
//this sets a maximum or target speed?
stepper->setSpeedInUs(90); // the parameter is us/step !!!
//does this perpetually accelerate, even once the max speed is reached?
stepper->setAcceleration(1000);
//this is the total number of steps before the motor just stops ? is it necessary?
stepper->move(100000);
I will look a little closer at the documentation for FastAccelStepper to hopefully answer these questions. Full code below for people playing along at home.
#include "FastAccelStepper.h"
#include <TMCStepper.h>
// As in StepperDemo for Motor 1 on AVR
//#define dirPinStepper 5
//#define enablePinStepper 6
//#define stepPinStepper 9 // OC1A in case of AVR
// As in StepperDemo for Motor 1 on ESP32
#define dirPinStepper 15
#define stepPinStepper 2
#define RXD2 16
#define TXD2 17
#define SHAFT true
#define SERIAL_PORT_2 Serial2 // TMC2208/TMC2224 HardwareSerial port - pins 16 & 17
#define DRIVER_ADDRESS_1 0b00 // TMC2209 Driver address according to MS1 and MS2
#define R_SENSE 0.11f // E_SENSE for current calc, SilentStepStick series use 0.11
FastAccelStepperEngine engine = FastAccelStepperEngine();
FastAccelStepper *stepper = NULL;
TMC2209Stepper driver(&SERIAL_PORT_2, R_SENSE, DRIVER_ADDRESS_1); // Create TMC driver
void setup() {
driver.begin();
driver.pdn_disable(true); // Use PDN/UART pin for communication
driver.toff(5); // [1..15] enable driver in software
driver.blank_time(24); // [16, 24, 36, 54]
driver.I_scale_analog(false); // Use internal voltage reference
driver.rms_current(1500); // motor RMS current (mA) "rms_current will by default set ihold to 50% of irun but you can set your own ratio with additional second argument; rms_current(1000, 0.3)."
driver.microsteps(1);
engine.init();
stepper = engine.stepperConnectToPin(stepPinStepper);
if (stepper) {
stepper->setDirectionPin(dirPinStepper);
//stepper->setEnablePin(enablePinStepper);
stepper->setAutoEnable(true);
// If auto enable/disable need delays, just add (one or both):
// stepper->setDelayToEnable(50);
// stepper->setDelayToDisable(1000);
stepper->setSpeedInUs(90); // the parameter is us/step !!!
stepper->setAcceleration(1000);
stepper->move(1000000);
}
}
void loop() {}
Hi @DaveX -
Thanks for talking this through with me. I've been going on a month now, mainly with this one objective of getting this stepper to go faster.
This is the motor I'm using: https://www.omc-stepperonline.com/download/17HS19-2004S1.pdf
I haven't been able to find any information on PPS, though. On the site, it said it was a "12V" motor, but my understanding is that these motors can often be run at 24 - and perhaps that would help the situation?
The load right now is non-existent. I am simply trying to get it to spin as fast as possible - I know there are major torque losses at the high speeds, but this has become a "single goal" project at this point.
I should say that the above code seems to produce problems at about 90/100 microseconds per step - this would be 10 rotations per second, or 600 RPM, by my math.
Which looks like they tested their 17HS19-2004S1 up to 1200 rpm with 24V and 2.4A. The "1600 Microstep" looks more like 1600step/rev or 1/8 microstep from the 32000pps = 1200RPM numbers on the chart.
These sorts of high-tech motor drivers do current limiting so they can apply high voltages for very short amounts of time to keep the average currents from burning up things. As you accelerate, if the higher-speed torque isn't strong enough to actually accelerate the rotation, you'll see problems like skipped steps and loss of speed as the coil forcing gets out of phase with the rotor-stator alignment.
With no load, it seems entirely possible to use this motor at 24V, the TMC2209's default/non-UART 1/8 microstepping and set for a current limit that doesn't overheat your driver. (1A?)
An Uno running FastAccelStepper seems capable of delivering 32000pps to multiple stepper drivers per this simulation:
If your physical motor can't keep up with the steps, maybe increase the supply voltage and slow down the acceleration so the speed increases don't need as much torque.