diff --git a/klippy/extras/tmc2130.py b/klippy/extras/tmc2130.py index adc2d7511..408471725 100644 --- a/klippy/extras/tmc2130.py +++ b/klippy/extras/tmc2130.py @@ -201,6 +201,7 @@ class TMC2130CurrentHelper(tmc.BaseTMCCurrentHelper): def __init__(self, config, mcu_tmc): super().__init__(config, mcu_tmc, MAX_CURRENT) + self.cs = config.getint('driver_cs', None, maxval=31, minval=0) vsense, irun, ihold = self._calc_current( self.req_run_current, self.req_hold_current ) @@ -213,10 +214,13 @@ def _calc_current_bits(self, current, vsense): vref = 0.32 if vsense: vref = 0.18 - cs = ( - int(32.0 * sense_resistor * current * math.sqrt(2.0) / vref + 0.5) - - 1 - ) + if self.cs is None: + cs = ( + int(32.0 * sense_resistor * current * math.sqrt(2.0) / vref + 0.5) + - 1 + ) + else: + cs = self.cs return max(0, min(31, cs)) def _calc_current_from_bits(self, cs, vsense): @@ -237,7 +241,7 @@ def _calc_current(self, run_current, hold_current): if abs(run_current - cur2) < abs(run_current - cur): vsense = False irun = irun2 - ihold = self._calc_current_bits(min(hold_current, run_current), vsense) + ihold = int(min((hold_current / run_current) * irun, irun)) return vsense, irun, ihold def get_current(self):