From 4acfd8d7c8973f6cc7b8a3eaa8ea9e82a92b018b Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 27 Oct 2021 19:10:36 -0400 Subject: stepper: Make step pulse duration customizable at run-time Remove the STEP_DELAY Kconfig option and replace it with a per-stepper step_pulse_duration printer.cfg config option. The AVR code will continue to have optimized code to step and "unstep" in the same function (which is automatically activated when the step delay is 40 ticks or less). This change removes the Kconfig option for single function step/unstep on 32bit processors. Signed-off-by: Kevin O'Connor --- klippy/stepper.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'klippy/stepper.py') diff --git a/klippy/stepper.py b/klippy/stepper.py index 013d667b..c5f81382 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -17,9 +17,10 @@ class error(Exception): # Interface to low-level mcu and chelper code class MCU_stepper: def __init__(self, name, step_pin_params, dir_pin_params, step_dist, - units_in_radians=False): + step_pulse_duration=None, units_in_radians=False): self._name = name self._step_dist = step_dist + self._step_pulse_duration = step_pulse_duration self._units_in_radians = units_in_radians self._mcu = step_pin_params['chip'] self._oid = oid = self._mcu.create_oid() @@ -58,9 +59,13 @@ class MCU_stepper: sk = ffi_main.gc(getattr(ffi_lib, alloc_func)(*params), ffi_lib.free) self.set_stepper_kinematics(sk) def _build_config(self): + if self._step_pulse_duration is None: + self._step_pulse_duration = .000002 + step_pulse_ticks = self._mcu.seconds_to_clock(self._step_pulse_duration) self._mcu.add_config_cmd( "config_stepper oid=%d step_pin=%s dir_pin=%s invert_step=%d" - % (self._oid, self._step_pin, self._dir_pin, self._invert_step)) + " step_pulse_ticks=%u" % (self._oid, self._step_pin, self._dir_pin, + self._invert_step, step_pulse_ticks)) self._mcu.add_config_cmd("reset_step_clock oid=%d clock=0" % (self._oid,), on_restart=True) step_cmd_tag = self._mcu.lookup_command_tag( @@ -73,9 +78,9 @@ class MCU_stepper: "stepper_get_position oid=%c", "stepper_position oid=%c pos=%i", oid=self._oid) max_error = self._mcu.get_max_stepper_error() + max_error_ticks = self._mcu.seconds_to_clock(max_error) ffi_main, ffi_lib = chelper.get_ffi() - ffi_lib.stepcompress_fill(self._stepqueue, - self._mcu.seconds_to_clock(max_error), + ffi_lib.stepcompress_fill(self._stepqueue, max_error_ticks, self._invert_dir, step_cmd_tag, dir_cmd_tag) def get_oid(self): return self._oid @@ -201,8 +206,10 @@ def PrinterStepper(config, units_in_radians=False): dir_pin = config.get('dir_pin') dir_pin_params = ppins.lookup_pin(dir_pin, can_invert=True) step_dist = parse_step_distance(config, units_in_radians, True) + step_pulse_duration = config.getfloat('step_pulse_duration', None, + minval=0., maxval=.001) mcu_stepper = MCU_stepper(name, step_pin_params, dir_pin_params, step_dist, - units_in_radians) + step_pulse_duration, units_in_radians) # Register with helper modules for mname in ['stepper_enable', 'force_move', 'motion_report']: m = printer.load_object(config, mname) -- cgit v1.2.3-70-g09d2