aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/tmc5160.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2021-10-24 20:03:42 -0400
committerKevin O'Connor <kevin@koconnor.net>2021-10-27 12:13:38 -0400
commit86fee2d517861546c7ba78cc1b59b83c2738ace4 (patch)
tree8b8df969438bd345fbbfbc79961c15df785f2a0d /klippy/extras/tmc5160.py
parent627c1c5d2a9d655d52960a17be7acff928d7ada2 (diff)
downloadkutter-86fee2d517861546c7ba78cc1b59b83c2738ace4.tar.gz
kutter-86fee2d517861546c7ba78cc1b59b83c2738ace4.tar.xz
kutter-86fee2d517861546c7ba78cc1b59b83c2738ace4.zip
tmc: Track requested hold_current so SET_TMC_CURRENT doesn't reduce it
The code automatically reduces the hold_current so that it is no greater than the run_current. However, this could lead to confusing behavior if one reduced and then increased the run_current via SET_TMC_CURRENT commands. To avoid that, this change adds support for tracking the requested hold_current - thus changes to run_current don't subtly alter the hold_current. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/tmc5160.py')
-rw-r--r--klippy/extras/tmc5160.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/klippy/extras/tmc5160.py b/klippy/extras/tmc5160.py
index fae17226..4d970271 100644
--- a/klippy/extras/tmc5160.py
+++ b/klippy/extras/tmc5160.py
@@ -235,8 +235,9 @@ class TMC5160CurrentHelper:
self.fields = mcu_tmc.get_fields()
run_current = config.getfloat('run_current',
above=0., maxval=MAX_CURRENT)
- hold_current = config.getfloat('hold_current', run_current,
+ hold_current = config.getfloat('hold_current', MAX_CURRENT,
above=0., maxval=MAX_CURRENT)
+ self.req_hold_current = hold_current
self.sense_resistor = config.getfloat('sense_resistor', 0.075, above=0.)
self._set_globalscaler(run_current)
irun, ihold = self._calc_current(run_current, hold_current)
@@ -271,8 +272,9 @@ class TMC5160CurrentHelper:
def get_current(self):
run_current = self._calc_current_from_field("irun")
hold_current = self._calc_current_from_field("ihold")
- return run_current, hold_current, MAX_CURRENT
+ return run_current, hold_current, self.req_hold_current, MAX_CURRENT
def set_current(self, run_current, hold_current, print_time):
+ self.req_hold_current = hold_current
irun, ihold = self._calc_current(run_current, hold_current)
self.fields.set_field("ihold", ihold)
val = self.fields.set_field("irun", irun)