stepper: Support step on both edges with custom minimum pulse duration
Add support for "step on both edges" to the main stepper_event_full() code. This makes that mode of operation available even when the micro-controller is not compiled for "optimized step on both edges". It also enables the custom pulse duration support (step_pulse_ticks) when in "step on both edges" mode. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Printer stepper support
|
||||
#
|
||||
# Copyright (C) 2016-2021 Kevin O'Connor <kevin@koconnor.net>
|
||||
# Copyright (C) 2016-2025 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import math, logging, collections
|
||||
@@ -14,7 +14,8 @@ class error(Exception):
|
||||
# Steppers
|
||||
######################################################################
|
||||
|
||||
MIN_BOTH_EDGE_DURATION = 0.000000200
|
||||
MIN_BOTH_EDGE_DURATION = 0.000000500
|
||||
MIN_OPTIMIZED_BOTH_EDGE_DURATION = 0.000000150
|
||||
|
||||
# Interface to low-level mcu and chelper code
|
||||
class MCU_stepper:
|
||||
@@ -75,13 +76,33 @@ class MCU_stepper:
|
||||
if self._step_pulse_duration is None:
|
||||
self._step_pulse_duration = .000002
|
||||
invert_step = self._invert_step
|
||||
sbe = int(self._mcu.get_constants().get('STEPPER_BOTH_EDGE', '0'))
|
||||
if (self._req_step_both_edge and sbe
|
||||
and self._step_pulse_duration <= MIN_BOTH_EDGE_DURATION):
|
||||
# Enable stepper optimized step on both edges
|
||||
# Check if can enable "step on both edges"
|
||||
constants = self._mcu.get_constants()
|
||||
ssbe = int(constants.get('STEPPER_STEP_BOTH_EDGE', '0'))
|
||||
sbe = int(constants.get('STEPPER_BOTH_EDGE', '0'))
|
||||
sou = int(constants.get('STEPPER_OPTIMIZED_UNSTEP', '0'))
|
||||
want_both_edges = self._req_step_both_edge
|
||||
if self._step_pulse_duration > MIN_BOTH_EDGE_DURATION:
|
||||
# If user has requested a very large step pulse duration
|
||||
# then disable step on both edges (rise and fall times may
|
||||
# not be symetric)
|
||||
want_both_edges = False
|
||||
elif sbe and self._step_pulse_duration>MIN_OPTIMIZED_BOTH_EDGE_DURATION:
|
||||
# Older MCU and user has requested large pulse duration
|
||||
want_both_edges = False
|
||||
elif not sbe and not ssbe:
|
||||
# Older MCU that doesn't support step on both edges
|
||||
want_both_edges = False
|
||||
elif sou:
|
||||
# MCU has optimized step/unstep - better to use that
|
||||
want_both_edges = False
|
||||
if want_both_edges:
|
||||
self._step_both_edge = True
|
||||
self._step_pulse_duration = 0.
|
||||
invert_step = -1
|
||||
if sbe:
|
||||
# Older MCU requires setting step_pulse_ticks=0 to enable
|
||||
self._step_pulse_duration = 0.
|
||||
# Configure stepper object
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user