mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-14 10:17:56 -06:00
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 <kevin@koconnor.net>
This commit is contained in:
parent
913d099261
commit
4acfd8d7c8
6 changed files with 69 additions and 96 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue