TMCStepper icon indicating copy to clipboard operation
TMCStepper copied to clipboard

Calculating values for TPWMTHRS and TCOOLTHRS

Open phodgers opened this issue 4 years ago • 1 comments
trafficstars

Hello,

I'm trying to work out values for TPWMTHRS and TCOOLTHRS. According to the datasheet for TMC2160 it says...

Actual measured time between two 1/256 microsteps derived from the step input frequency in units of 1/fCLK. Measured value is (2^20)-1 in case of overflow or stand still.

So this a measurement of a period between two successive step inputs from my external controller? My motor is 200 steps per revolution and 1/16 microstepping from my external controller. My TMC2160-BOB has been wired with clock input tied to GND, so it is running on internal clock at 12 MHz (fCLK). The internal microstepping takes it to 256 steps, so 200 x 256 = 51200 steps/revolution.

My leadscrew is 6mm lead, so if I want say 30 mm/s threshold for TPWMTHRS, that implies I will need to generate steps for 5 revolutions/s = 5 x 51200 = 256000 steps/s (call this ctrlCLK).

For the TSTEP measurement above, is it saying that it is a count of the number of 1/fCLK periods in the period between my controller sent steps? So the calculation is (1/ctrlCLK)/(1/fCLK) = fCLK/ctrlCLK.

So for 30 mm/s threshold on my 200 step motor with 6mm lead TSTEP should be 12000000/256000 = 47 (0x2F) and for 1 mm/s should be 12000000/8533.333333 = 1406 (0x57E).

Also, in practise, are TPWMTHRS and TCOOLTHRS normally set as the same value, since TPWMTHRS is the upper limit for stealthChop and TCOOLTHRS is the lower limit for CoolStep to take over from stealthChop? So the TSTEP value for TCOOLTHRS should always be equal to or less than TPWMTHRS (since TSTEP is a time period, with lower values representing higher step frequency/speed).

I think it would be useful if example values for both TPWMTHRS and TCOOLTHRS should be given in the example code to help point the new user in the right direction.

phodgers avatar Sep 06 '21 11:09 phodgers

That's how it goes. You can also refer to the Marlin implementation here: https://github.com/MarlinFirmware/Marlin/blob/718227a94c0cb163a73f0f288be6f7b864b7127a/Marlin/src/feature/tmc_util.h#L44-L46 The difference is that the f_clk is 12.65MHz and the parameters can be given as arguments. If you doubt the math, you can always verify by reading the TSTEP value.

CoolStep threshold and the pwm threshold do not need to be the same but often if you want coolstep, you want it more as a feature enabled when in spreadCycle mode.

teemuatlut avatar Sep 10 '21 20:09 teemuatlut