Validating TMC2240 operation on Manta M4P

Basic Information:

Printer Model: Sapphire Pro
MCU / Printerboard: BTT Manta M4P with BTT TMC2240 Driver Modules
Host / SBC: rPi CM4
klippy.log (127.6 KB)

I’ve been wanting to try out the TMC2240 and I finally have a few cycles to do so.

I’ve loaded four of them up on a Manta M4P and started working on the printer.cfg for a single one to see if SPI communications would work.

The expectation that I have to verify that SPI communications with the TMC2240 was working was a) I wouldn’t get any Klipper startup errors and b) its temperature would be reported on the Mainsail dashboard.

With this as my printer.cfg:

[include mainsail.cfg]
[mcu]
serial: /dev/serial/by-id/usb-Klipper_stm32g0b1xx_2700490009504B5735313920-if00
[temperature_sensor mcu_temp]
sensor_type: temperature_mcu

[temperature_sensor raspberry_pi]
sensor_type: temperature_host
min_temp: 10
max_temp: 100

[virtual_sdcard]
path: /home/biqu/printer_data/gcodes
on_error_gcode: CANCEL_PRINT

[printer]
kinematics: none
max_velocity: 1000
max_accel: 1000

[tmc2240 manual_stepper stepper_0]
cs_pin: PB12
#spi_speed:
spi_bus: spi1
#spi_software_sclk_pin:
#spi_software_mosi_pin:
#spi_software_miso_pin:
run_current: 0.580
#hold_current:
#rref: 12000
stealthchop_threshold: 999999
driver_SGT: 0
diag0_pin: PC0
#diag1_pin:
[manual_stepper stepper_0] # "X" Stepper on M4P
step_pin: PC6
dir_pin: PA14
enable_pin: !PC7
microsteps: 16
rotation_distance: 40
endstop_pin: tmc2240_stepper_0:virtual_endstop
position_min: 0
position_max: 40
velocity: 25
accel: 1000

I’m not getting any Klipper startup errors (passed test a)) but I’m getting something unexpected for the temperature reading:

There is definitely a “Manual Stepper” defined but with a temperature of “-°C”.

Anybody know what I’m doing wrong?

Thanx!

This is the only exception in the Klipper code, they are defined as “temperature_monitors”
So, they are only active if motors are enabled.
This is done that way because it is possible that the user can disable the power of the stepper driver with motor disable, and so the SPI read would fail.

Hope that clarifies a thing.


Btw, because of how they are used inside the code, they do use SG2 (like TMC5160), instead of SG4 (like TMC2209). Also, they do support jerkless switch of stealth to spread and vise versa.

IIRC they do support SPI 10MHz, so you can check the signal quality by trying to increase it from the current default of 4MHz


BTW2:

This funny thing can actually show how good your stepper motors are in a way :smiley:

TMC_CALIBRATE STEPPER=stepper_0

If both coils are symmetrical, they are pretty decent, I would say.
(phase offsets are in degrees).

Okay, thanx that’s really helpful - so, with what I’ve done above, I couldn’t be sure if I was actually communicating with the TMC2240.

Moving forward but not quite where I want to be yet.

I can enable the stepper and the temperature starts displaying (about 20C higher than I would expect and 10C higher than what I see using my thermal imager) - at the same time, the stepper output shaft cannot be moved easily, so I’m comfortable that this is working.

Next, I set the position to 0 and then move 20 mm (which is 180 degrees shaft rotation) which is expected.

When I try to do a homing operation (using MANUAL_STEPPER MOVE=40 STOP_ON_ENDSTOP=1 STEPPER=stepper_0) no movement and no error messages. I started with SGT set to 0 and then 32 and -32 to see if it was a range problem. There’s no movement regardless of the SGT value.

You can see the process here:

The stepper motor definition from my printer.cfg (which is basically the same as above) is:

[tmc2240 manual_stepper stepper_0]
cs_pin: PB12
#spi_speed:
spi_bus: spi1
#spi_software_sclk_pin:
#spi_software_mosi_pin:
#spi_software_miso_pin:
run_current: 0.580
#hold_current:
#rref: 12000
stealthchop_threshold: 999999
#driver_SGT: 0 # - Middle Value/No Movement
#driver_SGT: 32 # - Less Sensitive/No Movement
driver_SGT: -32 # - More Sensitive/No Movement
diag0_pin: PC0
#diag1_pin:
[manual_stepper stepper_0] # "X" Stepper on M4P
step_pin: PC6
dir_pin: PA14
enable_pin: !PC7
microsteps: 16
rotation_distance: 40
endstop_pin: tmc2240_stepper_0:virtual_endstop
position_min: 0
position_max: 40
velocity: 25
accel: 1000

I did confirm that the diag0 pin specified (PC0) is correct and the sensorless homing jumper (J23) is in place.

Any ideas what I’m doing wrong?

I thought the TMC2240 supports StallGuard2 and StallGuard4 Sensorless Motor Load
Detection https://www.analog.com/media/en/technical-documentation/data-sheets/tmc2240_datasheet.pdf.

I could remember this Sensorless Homing with the TMC 2240 drivers - #46 by DrumClock thread. You also were pretty involved.

^!PC0

I would guess it should be similar to the TMC2130/5160.
(And maybe diag1, depends on which pin is connected to the endstop).

Yes, this is what I meant, but Klipper only uses SG2 in TMC2240.

Well, that did something when I try to enable the motor (using MANUAL_STEPPER ENABLE=1 STEPPER=stepper_0):

klippy (1).log (632.3 KB)

Also tried it with SGT set to 0 as that’s the intermediate value with the same result.

It also does this when I return diag0_pin back to PC0.

I’m not sure what’s happening here. There’s absolutely no change from last night (haven’t even rebooted the M4P).

Ideas?

Yeah, I referenced that when I was first trying things - that’s why I started with diag0_pin set to 0 as that’s what @DrumClock used for his SGT value.

Okay, I made some progress here.

I moved the stepper to the “Y” driver and everything worked without the issue reported previously.

NOTE: “X” and “Y” are how the drivers are referenced in the User Manual, schematics and pinout drawing, so I’m following that convention here even though when you look at how I set up the manual_stepper definitions I used stepper_0 and stepper_1

I then went through the test process for run_current of 0.58A and 0.30A, as well as stealthchop_threshold of 0 and 999999 to find what I thought was the right SGT value.

The results are as follows (using my half-assed binary search approach):

driver_SGT: 32 #  0.30A/stealthchop_threshold: 0/Check 1/Move to Grind against post with message "No trigger on manual_stepper stepper_1 after full movement"
driver_SGT: 16 #  0.30A/stealthchop_threshold: 0/Check 2/Move to Grind against post with message "No trigger on manual_stepper stepper_1 after full movement"
driver_SGT:  8 #  0.30A/stealthchop_threshold: 0/Check 3/Move to Grind against post with message "No trigger on manual_stepper stepper_1 after full movement"
driver_SGT:  4 #  0.30A/stealthchop_threshold: 0/Check 4/Move to Grind against post with message "No trigger on manual_stepper stepper_1 after full movement"
driver_SGT:  2 #  0.30A/stealthchop_threshold: 0/Check 5/Seems to work Correctly <== This is the middle point
driver_SGT:  0 #  0.30A/stealthchop_threshold: 0/Check 6/Partial move - no message
driver_SGT:  1 #  0.30A/stealthchop_threshold: 0/Check 7/Seems to work Correctly
driver_SGT:  3 #  0.30A/stealthchop_threshold: 0/Check 8/Seems to work Correctly
driver_SGT: 32 #  0.30A/stealthchop_threshold: 999999/Check 1/Move to Grind against post with message "No trigger on manual_stepper stepper_1 after full movement"
driver_SGT: 16 #  0.30A/stealthchop_threshold: 999999/Check 2/Move to Grind against post with message "No trigger on manual_stepper stepper_1 after full movement"
driver_SGT:  8 #  0.30A/stealthchop_threshold: 999999/Check 3/Move to Grind against post with message "No trigger on manual_stepper stepper_1 after full movement"
driver_SGT:  4 #  0.30A/stealthchop_threshold: 999999/Check 4/Move to Grind against post with message "No trigger on manual_stepper stepper_1 after full movement"
driver_SGT:  0 #  0.30A/stealthchop_threshold: 999999/Check 5/Partial move - no message
driver_SGT:  2 #  0.30A/stealthchop_threshold: 999999/Check 6/Seems to work Correctly <== This is the middle point
driver_SGT:  1 #  0.30A/stealthchop_threshold: 999999/Check 7/Seems to work Correctly
driver_SGT:  3 #  0.30A/stealthchop_threshold: 999999/Check 8/Seems to work Correctly
driver_SGT: 32 #  0.58A/stealthchop_threshold: 999999/Check 1/Move to Grind against post with message "No trigger on manual_stepper stepper_1 after full movement"
driver_SGT: 16 #  0.58A/stealthchop_threshold: 999999/Check 2/Move to Grind against post with message "No trigger on manual_stepper stepper_1 after full movement"
driver_SGT:  8 #  0.58A/stealthchop_threshold: 999999/Check 3/Move to Grind against post with message "No trigger on manual_stepper stepper_1 after full movement"
driver_SGT:  4 #  0.58A/stealthchop_threshold: 999999/Check 4/Seems to work Correctly
driver_SGT:  2 #  0.58A/stealthchop_threshold: 999999/Check 5/Seems to work Correctly
driver_SGT:  0 #  0.58A/stealthchop_threshold: 999999/Check 6/Partial move - no message
driver_SGT:  1 #  0.58A/stealthchop_threshold: 999999/Check 7/Partial move - no message
driver_SGT:  3 #  0.58A/stealthchop_threshold: 999999/Check 8/Seems to work Correctly <== This is the middle point
driver_SGT:  5 #  0.58A/stealthchop_threshold: 999999/Check 9/Move to Grind against post with message "No trigger on manual_stepper stepper_1 after full movement"

So, I seemed to get a SGT value range of 3 for sensorless homing to work with the TMC2240 - this was surprising as I’m more familiar with the TMC2209 which has a threshold range of 20 to 40, depending on the application. The comment “This is the middle point” was put in when I determined that is was actually the middle point by seeing that the adjacent values also seemed to work correctly.

For poops and giggles, I connected another stepper motor to the “X” port (where I was having the problems reported above) - my expectation was I’d see the same results and I’d replace the TMC2240 driver module.

To my surprise, the original “X” axis driver ran fine and matched the results found for the “Y” axis driver.

Three comments:

  1. I was surprised to see that the rreported TMC2240 operating temperature was dependent on the run_current specification - the higher the run_current, the higher the initial and ongoing temperature.
  2. The SGT range is very narrow on the TMC2240. It seems to be rock solid in terms of repeatability. If you’re going to use the TMC2240 with sensorless homing, then you’re going to have to use an approach like I did above and determine all the SGT values that provide working sensorless homing and select one that’s in the middle.
  3. I have no idea why I had the “A” side short to ground. As I indicated, I turned off the drivers last night but left the board powered up. Mainsail was still active and I was still logged in with SSH so there doesn’t seem to have been a power glitch or any other problem. I’m going to watch this driver going forward…

So, the next step is to wire this M4P with the TMC2240s into a printer and see how it works.