terjeio / Trinamic-library

Plain C library for Trinamic TMC2130 stepper drivers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TMC2209 - $14x setting is being affected by VREF pot

shilrobot opened this issue · comments

I am trying out grblHAL on an STM32F4Discovery board with a BigTreeTech TMC2209 v1.3 driver board. I noticed a significant discrepancy in the current measurements I was getting from running motors when I used it in pure STEP/DIR mode with no UART control and setting current via potentiometer, versus using UART control and setting the current digitally using $140. The UART control mode was reading something like half of the current of the STEP/DIR mode.

After some investigating I discovered that changing the potentiometer still affects the current even when using $14x to configure the current. In other words, I actually played with the potentiometer while the motor was running and could see the current changing.

Looking at the source code, I can see in tmc2209.c in TMC2209_Init:

// Use default settings (from OTP) for these:
//  driver->gconf.reg.I_scale_analog = 1;
//  driver->gconf.reg.internal_Rsense = 0;
//  driver->gconf.reg.en_spreadcycle = 0;
//  driver->gconf.reg.multistep_filt = 1;

I admit it is not ultra clear in the datasheet, but it appears that when I_SCALE_ANALOG is left at 1, then the value on the TMC2209 VREF pin still modulates the actual output current, whereas if you set it to zero it uses an internal reference. After doing some digging it seems like Marlin explicitly sets this setting to 0 as does the Arduino TMC2209 library ( https://github.com/janelia-arduino/TMC2209 ).

I changed my TMC2209_Init setup to set I_SCALE_ANALOG to 0 in TMC2209_Init and it then made my readings insensitive to changing the VREF potentiometer, and gave me values about what I expect.

I do have some concerns that the straightforward fix could drastically change the current values people with existing machines will get after a firmware update. If they set their current limits based off of motor datasheets, I would guess they would mostly be OK, but if it they set this value empirically based on how hot the motors got or something it could be a nasty surprise.

For reference it appears another workaround might be to set VREF to 2.5V via the potentiometer, which if I am reading the datasheet right should result in 100% of the value set via $14x to be used.