TMCStepper
TMCStepper copied to clipboard
TMC2209 returns wrong microsteps from the REGISTRY when it is set to 4
I have noticed that when setting microsteps to 4, the TMC2209 does not return the correct value of 4 when reading from the Register Map, but 256, although the driver is, indeed, in 4 microsteps mode.
This only happens when the interpolation is disabled [driver.intpol(false);]. With it enabled, the returned value is correct.
Here is a code to set all 9 possible microsteps using the UART:
uint16_t MicroStep[9] = {0, 2, 4, 8, 16, 32, 64, 128, 256};
for (int16_t i = 0; i < 9; i++)
{
Serial.print("i=");
Serial.println(i);
Serial.print("set microsteps=");
Serial.println(MicroStep[i]);
driver.microsteps(MicroStep[i]);
Serial.print("get microsteps=");
Serial.println(driver.microsteps());
if (i == 0)
driver.VACTUAL(839);
else
driver.VACTUAL(839 * MicroStep[i]);
Serial.print("get VACTUAL=");
Serial.println(driver.VACTUAL());
Serial.println();
delay(4000);
}
The output from serial is:
i=0 set microsteps=0 get microsteps=0 get VACTUAL=839
i=1 set microsteps=2 get microsteps=2 get VACTUAL=1678
i=2 set microsteps=4 get microsteps=256 <<<<<<------------------ WRONG! get VACTUAL=3356
i=3 set microsteps=8 get microsteps=8 get VACTUAL=6712
i=4 set microsteps=16 get microsteps=16 get VACTUAL=13424
i=5 set microsteps=32 get microsteps=32 get VACTUAL=26848
i=6 set microsteps=64 get microsteps=64 get VACTUAL=53696
i=7 set microsteps=128 get microsteps=128 get VACTUAL=107392
i=8 set microsteps=256 get microsteps=256 get VACTUAL=214784
The motor is always spinning at exactly 3 RPM, so internally the driver TMC2209 is running with 4 microsteps, but it returns a wrong value when requesting the status for microsteps.
The library's code seems correct. Does the driver itself has a bug?