TMC 2209 stepper motor current issue

Hey guys,

I have some issues setting the stepper motor current. I hope you can help me find the problem.

I'm using an ardunio Nano and the Bigtreetech 2209 Stepper driver to control a Nema 17 stepper.
Since I just want to let the motor rotate and adjust the speed and current, at this point, I copied a sample code and adjusted it slightly.

The circuit is powered by my lab power supply which tells me the actual amperag value at any time.

I'm trying to adjust the current value using the following code line:
TMCdriver.rms_current(2500);
A value of 2500RMS should already exceed the maximum amperage the TMC 2209 can handle.
However, the power supply tells me only 50-180mA of current is running. I already adjusted the value to all kinds of random numbers. Sometimes the actual current increased a tiny little bit, sometimes in decreased. Completely random. I couldn't find any coherence in the values. But, it never exceeded 180mA.

I already checked the max amperage value of my power supply and adjusted the potentiometer value on the 2209 board.
Nothing helped.

Does anybody have an idea and can help me?
I need the stepper to run on more than 1Amp of current in order to provide enough torque for my application.

Thanks in advance :slightly_smiling_face:

This is the code I'm using at the moment:

#include <TMCStepper.h>         // TMCstepper - https://github.com/teemuatlut/TMCStepper
#include <SoftwareSerial.h>     // Software serial for the UART to TMC2209 - https://www.arduino.cc/en/Reference/softwareSerial
#include <Streaming.h>          // For serial debugging output - https://www.arduino.cc/reference/en/libraries/streaming/

#define EN_PIN           4      // Enable - PURPLE
#define DIR_PIN          2      // Direction - WHITE
#define STEP_PIN         3      // Step - ORANGE
#define SW_SCK           5      // Software Slave Clock (SCK) - BLUE
#define SW_TX            7      // SoftwareSerial receive pin - BROWN
#define SW_RX            6      // SoftwareSerial transmit pin - YELLOW
#define DRIVER_ADDRESS   0b00   // TMC2209 Driver address according to MS1 and MS2
#define R_SENSE 0.11f           // SilentStepStick series use 0.11 ...and so does my fysetc TMC2209 (?)

SoftwareSerial SoftSerial(SW_RX, SW_TX);                          // Be sure to connect RX to TX and TX to RX between both devices

TMC2209Stepper TMCdriver(&SoftSerial, R_SENSE, DRIVER_ADDRESS);   // Create TMC driver

int accel;
long maxSpeed;
int speedChangeDelay;
bool dir = false;


//== Setup ===============================================================================

void setup() {

  Serial.begin(5760);               // initialize hardware serial for debugging
  SoftSerial.begin(5760);           // initialize software serial for UART motor control
  TMCdriver.beginSerial(5760);      // Initialize UART
  
  pinMode(EN_PIN, OUTPUT);           // Set pinmodes
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);
  digitalWrite(EN_PIN, LOW);         // Enable TMC2209 board  

  TMCdriver.begin();                                                                                                                                                                                                                                                                                                                            // UART: Init SW UART (if selected) with default 115200 baudrate
  TMCdriver.toff(5);                 // Enables driver in software
  TMCdriver.rms_current(2500);        // Set motor RMS current (mA) x1.414 = peak current
                                      // max current board = 2.8A peak = 2A RMS
  TMCdriver.microsteps(256);         // Set microsteps

  TMCdriver.en_spreadCycle(false);
  TMCdriver.pwm_autoscale(true);     // Needed for stealthChop



    accel = 1000;                                         // Speed increase/decrease amount
  maxSpeed = 10000;                                      // Maximum speed to be reached
  speedChangeDelay = 100;                                // Delay between speed changes
  
  for (long i = 0; i <= maxSpeed; i = i + accel){             // Speed up to maxSpeed
    TMCdriver.VACTUAL(i);                                     // Set motor speed
    Serial << TMCdriver.VACTUAL() << endl;
    delay(100);
  }
}

//== Loop =================================================================================

void loop() {
  
    TMCdriver.VACTUAL(maxSpeed);                                     // Set motor speed
    Serial << TMCdriver.VACTUAL() << endl;
    delay(10000);
  

  
 // dir = !dir; // REVERSE DIRECTION
 // TMCdriver.shaft(dir); // SET DIRECTION

}

The current is being pulsed with every step of the motor. You will not get an accurate reading from a bench supply current meter (is it analogue or digital meter) when you are in this situation. The only way to see the current waveform is to put a low value resistor between a coil and ground (about 0.5R or less) and measure the voltage across it with an oscilloscope.

Remember this will only give you half the current because there are two coils in your motor.

That is because your measurement is not the "actual" current.

The other thing is that as the coil of the motor is an inductive load that will shift the phase of the current and the voltage to almost 90 degrees. The power supply will only be registering the current's vector as projected onto the real axis, not the vector itself.

Did you connect the motor PSU correctly?
Are the current sense resistors okay?
A circuit diagram may be helpful.

Setting stepper current is tricky. Modern stepper drivers use a switch-mode technique that in effect transforms the current down between the stepper and the supply. The driver is rated in terms of the motor current but the supply current is less by a significant factor, in theory by the ratio of (motor voltage)/(supply voltage) (though motor voltage isn't a useful measure).

Also the current in the motor is not sinusoidal so talk of quadrature phase shift is not helpful. The correct way to set the current is via the Vref on the PCB as described in the manual

I think that you should be able to pick up the voltage as described in the Polulu data sheet for the DRV8825 - you use a small screwdriver to adjust the potentiometer with one lead of your DMM clipped to the blade and the other to 0V. Calculate the voltage corresponding to the motor current you want, for a NEMA17 unless you're doing something needing a lot of torque no more than 500mA probably.

Thank you all for your quick answers.

I have to accumulate all the information you gave me and try to understand everything.

you are compeletely right. The current is pulsed, which is why, the power supply will never read it properly.
Unfortunately, I don't hava an oscilloscope at hand. However, I was just wondering if a large capacitor would help recifying the current to measure it properly.
At the end, the precise amperage measurement isn't the point that concerns me.
I just want it to be as large as possible to gain maximum torque.

I already tweaked the vref potentiometer a few times, but I couldn't witness a an increase in torque.

I will post a picture of my breadboard wiring asap.

Tanks a lot :slight_smile:

IMG_2578

This is the breadboard I'm actually working with.

I will list down the output pins of the driver, as well.

GND: -GND
VDD: -5V Arduino and 22uF Cap to GND
B2: -Stepper
B1: -Stepper
A1: -Stepper
A2: -Stepper
GND: - GND (All share the same GND)
VM: -24V Power Supply

EN: -D4
MS1: -
MS2: -
PDN: -D7
PDN: -D6
CLK: -D5
STEP: -D3
DIR: -D2

I just took my multimeter to measure the Vreff value and compared it with the amperage value my power supply indicated.
I repeated this using different rms_current values in the arduino file.

First:
tweaking the Vreff potentiometer does only slightly influence the measured value:
first example: counterclockwise: .129V, clockwise: .108v

rms current: 10 - > vreff: .048V ; .088A
rms current: 50 - > vreff: .70V ; .098A
rms current: 100 - > vreff: .230V ; .123A
rms current: 500 - > vreff: .148V ; .073A
rms current: 1000 - > vreff: .134V ; .066A
rms current: 1500 - > vreff: .141V ; .071A
rms current: 2000 - > vreff: .140V ; .071A
rms current: 2500 - > vreff: .134V ; .067A
rms current: 10000 - > vreff: .154V ; .077A

I don't see a correlation here. However, if I repeat to select a particular value, I measure different results.
Nevertheless, the amperage correlates somehow with the torque I measure using my fingers.

To be clear, the power supply current is not pulsed, and actually nor is the motor current really. The motor windings are driven with varying pulse widths but have commutating diodes so the current flows continuously (though with ripples) at a value set by the pulse width in use. The pulse width is changed from step to step to vary the current to achieve the desired microstepping profile.

I understood this point. However, I just used the measurements because that was the sole opportunity I had.
Nevertheless, what counts is the torque at the stepper motor drive. And this somehow correlates with that values, but is way to less compared to what I need.

Like I already said:
In general, I just want to provide the motor as much current as possible to gain max torque.

Maybe you need a bigger stepper, Nema23 or 34? I use a NEMA 23 high torque on the big mill X feed, I'll check what current. What are you trying to drive?

Current / voltage phase shift happens no matter what the shape of the current waveform. So it is helpful in understanding why the bench power supply is not giving the correct reading.

To be clear this is BS.

1 Like

At the end, I'm trying to drive a dosing pump. Therefore, I want to use as much torque, as possible.

However, what concerns me the most at the moment is the incomprehensible relation between the values I set using the stepper, in the current line and the actual torque.
That just doesn't make sense to me

I suspect that is because you are not actually measuring the torque with any detail but just sensing how you hard you have to squeeze your fingers on the shaft to stop the motor.

It could be that your motor is close to stalling anyway due to too higher step speed, and the changes you are making, are insufficient to demonstrate this torque, to your way of measuring it.

But basically it comes down to physics the more current you actually get in the windings the more torque you will have. Stepping too fast is just one reason you might not get enough current in the windings before the next step. There is also your power supplies' ability to delver the current, the supply ripple and the supply voltage needing to be higher. This last one is cured by having a power supply with a higher voltage.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.