Sensorless Homing with the TMC 2240 drivers

Ok. What kind of TMC2130 drivers are you using? MKS, BTT, etc…?

How fast are you homing?
It should not be too slow to generate enough back EMF but also not too fast…

the TMC2130 driver is from BTT, but there is no problem with them, as I have already written several times. TMC 2240 are not functional…

… as recommended 1/2 [rotation_distance] so 20mm/s

Very strange!

The datasheet only gives the following:

Homing with StallGuard2
The homing of a linear drive requires moving the motor into the direction of a hard stop. As StallGuard2 needs a certain velocity to work (as set by TCOOLTHRS), make sure that the start point is far enough away from the hard stop to provide the distance required for the acceleration phase. After setting up SGT, start a motion into the direction of the hard stop and configure diag0_stall or diag1_stall to indicate the stall condition to the external controller using one of the diagnostic outputs. Once a stall is detected, the controller stops the motor. The stop condition also is indicated by the flag STALLGUARD in DRV_STATUS.

Can you maybe try with 40 mm/s?
Do you still home with reduced motor current or with run current?

Maybe.

This is what I found out about MKS TMC2240.

BTT might using DIAG1.

You could try to change your config using DIAG0.

Do you mean to reference this:

I’m not sure why you’re linking to a TMC2130 page.

Also, why isn’t there a schematic for this module? That would answer a lot of our questions.

Hi

  1. I don’t know why @hcet14 keeps referring to TMC 2130

  2. the TMC 2240 from makerbase MKS does not work for me

  3. tomorrow I will try to set DIAG0 and homing speed

Thanks

-Petr

scheme MKS TMC 2240

HI , I tried this:

  1. in the [stepper_x] section the following changes:
    a) homing_speed:20
    b) homing_speed:40
    c) endstop_pin: tmc2240_stepper_x:virtual_endstop
    d) enstop_pin: !PA15

  2. in the [tmc2240 stepper_x] section the following changes:
    a) diag1_pin: ^!PA15
    b) diag0_pin: ^!PA15
    c) diag1_pin: PA15 ( the motor did not even move after G28 X0)
    d) diag0_pin: PA15 ( the motor did not even move after G28 X0)
    e) driver_SGT: -60
    f) driver_SGT: 60
    g) driver_SGT: 0

All attempts did not result in the carriage stop function at the end stop.
The carrige hit the end and the engine started skipping.

Probably Klipper will not support sensorless homing for TMC 2240.

Does anyone have any ideas what else I should try?

Are you running on StealthChop or SpreadCycle?
Each mode uses a different StallGuard version, maybe this can help here testing the other mode.

Thanx for the schematic.

Looking at it, I don’t see anything surprising but I think you’re hung up on the diag0/diag1 pins issue.

Going by the Klipper documentation for the TMC2240

https://www.klipper3d.org/Config_Reference.html?h=tmc#tmc2240

as well as TMC2240 datasheet

the diag1 pin is used as the UART pin when you are in UART mode and does NOT provide any error outputs (like StallGuard output) in this mode. IF YOU ARE WORKING WITH THE BARE CHIP, you may diag1 as an error output when you are communicating with the TMC2240 when you are in SPI mode.

I emphasized “IF YOU ARE WORKING WITH THE BARE CHIP” because, if you look at the schematic you’ve provided, DIAG1/SW (the correct label) is combined with the SPI_CS line with a current limiting resistor (R2 on your schematic) - the current limiting resistor means that any output from DIAG1/SW will not change the SPI_CS value.

The net result of this is that you need to forget about diag1 all together. The Klipper documentation kind of notes that but doesn’t explicitly indicate that you will not be able to access pin_diag1.

Could you share your current printer.cfg and an image of your board for confirming the jumper positions to make sure they’re right (I asked for this previously and never got it). I want to confirm that there is no confusion as to what you are doing and what I and others are assuming.

From there, I will focus on the X axis and check that:

  1. You are communicating with the chip (ie no errors indicating that the driver chip’s registers can’t be accessed).
  2. The values for the homing movement speed, driver current, SGT value and whether you are running in StealthChop or SpreadCycle mode.
  3. Tune the values so that contact with the X axis stop is recognized.

As you are working with a CoreXY, the Y axis should use the same values as the X axis.

Once that’s done, you owe everybody here a beer.

I tried both StealthChop and SpreadCycle modes.
Nothing changes, sensorless homing doesn’t work.

Hi @mykepredko

here is the current setup for the TMC2240

I am attaching photos of the pins on the MKS board.



terminal listing (so SPI works)


8:37  SG4_IND: 00000002 sg4_ind_0=2
8:37  SG4_RESULT: 00000004 sg4_result=4
8:37  SG4_THRS: 00000200 sg4_angle_offset=1
8:37  PWM_AUTO: 0000001d pwm_ofs_auto=29
8:37  PWM_SCALE: 00000000
8:37  PWMCONF: c40c001d pwm_ofs=29 pwm_autoscale=1 pwm_autograd=1 pwm_reg=4 pwm_lim=12
8:37  DRV_STATUS: 80000261 sg_result=609 stst=1
8:37  COOLCONF: 00050000 sgt=5
8:37  CHOPCONF: 34410153 toff=3 hstrt=5 hend=2 tbl=2 tpfd=4 mres=4(16usteps) intpol=1 dedge=1
8:37  MSCURACT: 00930139 cur_a=-199 cur_b=147
8:37  MSCNT: 00000368 mscnt=872
8:37  ADC_TEMP: 000008cc adc_temp=0x08cc(27.8C)
8:37  ADC_VSUPPLY_AIN: 02db099f adc_vsupply=2463 adc_ain=731
8:37  THIGH: 00000000
8:37  TCOOLTHRS: 000fffff tcoolthrs=1048575
8:37  TPWMTHRS: 000fffff tpwmthrs=1048575
8:37  TSTEP: 000fffff tstep=1048575
8:37  TPOWERDOWN: 0000000a tpowerdown=10
8:37  IHOLD_IRUN: 04061f1f ihold=31 irun=31 iholddelay=6 irundelay=4
8:37  GLOBALSCALER: 000000a3 globalscaler=163
8:37  DRV_CONF: 00000001 current_range=1
8:37  IOIN: 4001303c encb=1 enca=1 drv_enn=1 encn=1 output=1 ext_res_det=1 silicon_rv=1 version=0x40
8:37  GSTAT: 00000000
8:37  GCONF: 0000000c en_pwm_mode=1 multistep_filt=1
8:37  ========== Queried registers ==========
8:37  MSLUTSTART: 00f70000 start_sin90=247
8:37  MSLUTSEL: ffff8056 w0=2 w1=1 w2=1 w3=1 x1=128 x2=255 x3=255
8:37  MSLUT7: 00404222 mslut7=4211234
8:37  MSLUT6: 49295556 mslut6=1227445590
8:37  MSLUT5: b5bb777d mslut5=3048961917
8:37  MSLUT4: fbffffff mslut4=4227858431
8:37  MSLUT3: 10104222 mslut3=269500962
8:37  MSLUT2: 24492929 mslut2=608774441
8:37  MSLUT1: 4a9554aa mslut1=1251300522
8:37  MSLUT0: aaaab554 mslut0=2863314260
8:37  ========== Write-only registers ==========
8:37  DUMP_TMC STEPPER=stepper_x

and SET_TMC_CURRENT

8:42  Run Current: 0.90A Hold Current: 0.90A
8:42  SET_TMC_CURRENT STEPPER=stepper_x CURRENT=0.9
8:42  Run Current: 0.10A Hold Current: 0.10A
8:42  SET_TMC_CURRENT STEPPER=stepper_x CURRENT=0.1

Good stuff. That looks like what I’m asking for - you’re early posts didn’t have a complete SPI set up and it didn’t sound like you were in communications with the driver module.

Now, going to point 2. Could you create a table (I normally use a spreadsheet) listing the parameters you are using, namely:

  • Driver current (run_current or, to change for a test, SET_TMC_CURRENT)
  • Homing speed (homing_speed:)
  • Running mode (StealthChop or SpreadCycle): (stealthchop_threshold: <== Most people set this to 999999 to ensure StealthChop is always active and I recommend that you use this for these tests)
  • SGT Value (driver_SGT:) I’m not sure how the values are passed to the TMC2240 so I think you’ll have to try values in the range of 127 and 0 as well as -64 to + 63 (which is 127 to 0 in a 7 bit world) with the higher the most significant bit the higher the sensitivity.

I believe that these are the four parameters that are the critical ones for StallGuard/Sensorless homing.

Once you have the table created, try a few different values, post them here and we’ll figure out how to get things running.

Hi @mykepredko

thanks a lot, i figured it out.
It’s very sensitive, so I don’t know how it will behave when something wears out.

2 Likes

Congratulations! I’m very happy for you and hopefully the information here will be of use to somebody else.

I’m surprised at the sensitivity value - when I’m working with a TMC2209, the range is generally 3-5 units.

Great job!

Yes, me too. If I do an XY movement test at F36000 speed, it must be stealthchop_threshold:0
otherwise the TMC driver error will occur and the movement will stop.

max_velocity: 600
max_accel: 6000
max_accel_to_decel:6000

“F36000”? Or do you mean F600 (which matches what you have below it)?

F36000 will have your carriage moving at 130 km/h. I wouldn’t be surprised if the TMC chip throws an error at that speed.

i mean … 600 mm/s = G1 x… y … F 36000 (mm/min)

That’s still pretty fast - the maximum speed I run at is 1/3 that (200 mm/s) on my CoreXY’s and Voron 2.4.

Maybe this should go into another topic.