Sensorless Homing with the TMC 2240 drivers

Basic Information:

Printer Model: Home Made
MCU / Printerboard: Manta M5P

Describe your issue:

Hi, I’m trying to set up Sensorless Homing with the TMC 2240 drivers, but I can’t.
If I try it with TMC 2209 or TMC 2130 then everything is fine.


[stepper_x]       # Motor 1  - left
step_pin: PC8
dir_pin: PC9
enable_pin: !PA15
microsteps: 16
rotation_distance: 40
homing_speed: 20
endstop_pin: tmc2240_stepper_x:virtual_endstop
homing_retract_dist: 0
position_endstop: 0
position_min:0
position_max: 278

[tmc2240 stepper_x]
cs_pin: PD9
spi_bus: spi2
diag1_pin: ^!PD3       # Pin connected to TMC DIAG1 pin (or use diag0_pin / DIAG0 pin)
driver_SGT: 60         # -64 is most sensitive value, 63 is least sensitive
run_current: 0.700
stealthchop_threshold: 0 #999999
interpolate: True

I tried all possible combinations of driver_SGT but without result.
The carrige just hits the end of the track and the motor steps skip.

I also tried diag1_pin and diag0_pin but everything behaves the same.

Thank you very much.
-Petr

Did you try

driver_SGT: -60

Good luck, hcet14

Yes -60 or 60 carriage will not stop

What about Configuration reference - Klipper documentation

#diag1_pin:
#   The micro-controller pin attached to one of the DIAG lines of the
#   TMC2240 chip. Only a single diag pin should be specified. The pin
#   is "active low" and is thus normally prefaced with "^!". Setting
#   this creates a "tmc2240_stepper_x:virtual_endstop" virtual pin
#   which may be used as the stepper's endstop_pin. Doing this enables
#   "sensorless homing". (Be sure to also set driver_SGT to an
#   appropriate sensitivity value.) The default is to not enable
#   sensorless homing.

??
i’m done… diag1_pin: ^!PD3

Is that good or bad?

It is the initial setting in the code snippet, so…

I have set : diag1_pin: ^!PD3
i also tried: diag0_pin: ^!PD3

nothing changes cariigae hits the end and won’t stop
Drivers are MKS TMC2240

I assume you have used the correct pin on the board for diag.

And the jumper is set?


from https://github.com/bigtreetech/Manta-M5P/blob/master/Hardware/BIGTREETECH%20MANTA%20M5P%20V1.0-SCH.pdf

I think that’s fine for M1, but I didn’t check the layouts of MKS TMC2240 against Manta M5P. Maybe there is the problem.

Adding my two cents here. I don’t have any experience with the '2240 but I do have quite a bit with the TMC2209 and sensorless homing.

First off, please post your klippy.log as well as more information about your printer. You were asked for your klippy.log with the original post and you haven’t put it in here. The information about your set up is woefully inadequate - you haven’t even indicated what kind of printer architecture you’re working with. I’m going to assume a Cartesian (separate X and Y) based on what I see here; if I’m wrong, please correct me. As the last piece of required information, please identify the '2240 driver modules you’re working with; I suspect the discussion about which diag pin is in use is irrelevant and leading in the wrong direction as, according to the datasheet, diag1 is also the UART pin.

You need to provide more information so that we can suggest appropriate courses of action.

Secondly, could you confirm the jumpers for your X/Y axes? You should have two jumpers for each of the axes, one for the serial communications and one for diag. @hcet14 put up a marked up section of the M5P’s schematic and I’ve added where the UART pins should be jumpered here:

The best way to confirm that you’ve put in the jumpers correctly is to post an image of the board with the driver module removed (so the jumper underneath it can be seen).

Third, please document how you’ve tested sensorless homing with different printer.cfg parameters. Putting the information together in a table is very helpful and will lead to getting things running for you faster.

A few comments from what I’ve seen of the conversation:

  1. I’m confused by the use of “1 to +64” and “-1 to -64” for the SGT thresholds in the '2240. When I look at the bit definition in the datasheet:

    it appears to me that the correct values should be 127 to 0. I know the datasheet specifies this, but I’m not sure how things are coded in Klipper (the documentation doesn’t list value ranges). I suggest that you assume the values are 127 (high sensitivity) to 0 until this is proven in error.
  2. When I set up sensorless homing, I find that it is a balance between stepper current and the threshold value. I suggest that you reduce your current and try a middle of the range value for SGT to see if the stall is detected.
  3. This goes back to the first comment but I don’t know how Klipper has coded things and I can’t find any examples of anybody getting sensorless homing working with the '2240. You correctly note that '2240’s DIAG output is opposite to the '2209’s but I don’t know if that is accounted for in the Klipper code. You should be checking the diag input as inverted and non-inverted.

I’m sure you’ll get '2240 sensorless homing to work, but it takes a bit of careful stepping through your options and documenting things so there’s no confusion.

Hello friends
it’s a coreXY system and all jumpers are correct.

I tested Sensorless Homing with TMC 2226 (TMC2209) drivers in UART mode
and with TMC 2130 drivers in SPI mode and everything was fine.

Then I wanted to try the TMC 2240 drivers in SPI mode from Makerbase but it didn’t work. Of course I tried the whole rosah -64 to 63 for the driver_SGT: parameter and changing the diag1_pin parameter: ^! but without result.

I ordered new 2240 drivers so I’ll wait for them to arrive and continue testing.

Thank you all
-Petr

1 Like

Can you do me a favor and try something around 0. Maybe 2?

I ordered new 2240 drivers so I’ll wait for them to arrive and continue testing.

Sorry for being such a pain in the neck, but it might saving you money. Maybe you didn’t place the order yet.

Since TMC2130 and TMC2240 are similar, I compared the datasheets of both ICs.

You may compare “Figure 14.1 Function principle of StallGuard2” from https://www.analog.com/media/en/technical-documentation/data-sheets/TMC2130_datasheet_rev1.16.pdf and
“Table 20. StallGuard2-Related Parameters” from https://www.analog.com/media/en/technical-documentation/data-sheets/TMC2240_datasheet_rev1.pdf. They are almost identical.

You may watch this https://www.youtube.com/watch?v=XCDQ6_OveIQ from timecode 11:50.

That’s why I asked you

Hi, thank you.
As I wrote above, guidance worked precisely with TMC 2209 and TMC 2130,
but no SGT value worked for TMC2240, so I am ordering new drivers.

Thanks everyone, I’ll get back to you when I have the new drivers.

-Petr

Hi everyone.
so I tried the TMC2240 drivers with the MKS Robin NANO V3.1 board
and it is the same as from the MANTA M5P board.

TMC 2130 and TMC 2226 drivers work correctly for sensorless homing.

Couldn’t there be a problem using [homing_override] in this ?

Macro:

[homing_override]
axes: z
set_position_z: 0
gcode:
  
   ##### get user defines position endstop Z or probe #####   
   {% set z_endstop_x = 130 %}
   {% set z_endstop_y = 150 %}
   {% set z_hop = 4 %}

   # Always use consistent run_current on A/B steppers during sensorless homing
    {% set RUN_CURRENT_X = printer.configfile.settings['tmc2240 stepper_x'].run_current|float %}
    {% set RUN_CURRENT_Y = printer.configfile.settings['tmc2240 stepper_y'].run_current|float %}
    {% set HOME_CURRENT = 0.700 %}     

   # Z-hop befor homing - lift nozzle
   G91; set relative
#   G0 Z{z_hop} F900 
   G90; set absolute

    # Set current during  Home XY    
    SET_TMC_CURRENT STEPPER=stepper_x CURRENT={HOME_CURRENT}
    SET_TMC_CURRENT STEPPER=stepper_y CURRENT={HOME_CURRENT}
   
     {% if "x" not in printer.toolhead.homed_axes %}
       G4 P2000   # Wait just a second… (give StallGuard registers time to clear)     
       G28 X0
       G1 X10 F1200       
     {% endif %}
     
     {% if "y" not in printer.toolhead.homed_axes %}    
       G4 P2000   # Wait just a second… (give StallGuard registers time to clear)
       G28 Y0
       G1 Y10 F1200      
     {% endif %}

    # Set current during print
    SET_TMC_CURRENT STEPPER=stepper_x CURRENT={RUN_CURRENT_X}
    SET_TMC_CURRENT STEPPER=stepper_y CURRENT={RUN_CURRENT_Y}

    
     ## XY Location of the Z probe
     G0 X{z_endstop_x} Y{z_endstop_y} F7200   
      ## HOME Z
#      G28 Z0   
      ## Elevator Z
#      G0 Z{z_hop} F1800      
      ```

klippy log:

klippy (4).log (1.4 MB)

printer configuration here:

In your https://github.com/DrumClock/CoreliX/blob/main/my_config/driver_TMC_2130.cfg
driver_SGT: 5 # -64 is most sensitive value, 63 is least sensitive

In your https://github.com/DrumClock/CoreliX/blob/main/my_config/driver_TMC_2240.cfg
driver_SGT: -60 # -64 is most sensitive value, 63 is least sensitive

Why do you use “driver_SGT: -60”?

That’s why I asked

Hi, the value - 60 was left there from testing.

Unfortunately, no value between -64 and 63 works for the TMC 2240.

I tried 0, 2 and - 2 nothing works.
Board and TMC are from Makerbase-mks.

It seems that the DIAG signal is not generated by the driver.