From 5d591fd91d95562bfe7e2886de34a7e6e3e28e11 Mon Sep 17 00:00:00 2001 From: Mihai <299015+mh-dm@users.noreply.github.com> Date: Mon, 9 Dec 2024 02:55:16 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Improve=20pulse=20timing,?= =?UTF-8?q?=20fix=20LPC176x=20jitter=20(#27131)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/module/stepper.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index b1573f2be9..5083c0a4d2 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -1498,6 +1498,12 @@ void Stepper::apply_directions() { */ HAL_STEP_TIMER_ISR() { + #ifndef __AVR__ + // Disable interrupts, to avoid ISR preemption while we reprogram the period + // (AVR enters the ISR with global interrupts disabled, so no need to do it here) + hal.isr_off(); + #endif + HAL_timer_isr_prologue(MF_TIMER_STEP); Stepper::isr(); @@ -1515,12 +1521,6 @@ void Stepper::isr() { static hal_timer_t nextMainISR = 0; // Interval until the next main Stepper Pulse phase (0 = Now) - #ifndef __AVR__ - // Disable interrupts, to avoid ISR preemption while we reprogram the period - // (AVR enters the ISR with global interrupts disabled, so no need to do it here) - hal.isr_off(); - #endif - // Program timer compare for the maximum period, so it does NOT // flag an interrupt while this ISR is running - So changes from small // periods to big periods are respected and the timer does not reset to 0 @@ -1542,8 +1542,6 @@ void Stepper::isr() { // We need this variable here to be able to use it in the following loop hal_timer_t min_ticks; do { - // Enable ISRs to reduce USART processing latency - hal.isr_on(); hal_timer_t interval = 0; @@ -1559,6 +1557,10 @@ void Stepper::isr() { ftMotion_nextAuxISR = (STEPPER_TIMER_RATE) / 400; } } + + // Enable ISRs to reduce latency for higher priority ISRs, or all ISRs if no prioritization. + hal.isr_on(); + interval = _MIN(nextMainISR, ftMotion_nextAuxISR); nextMainISR -= interval; ftMotion_nextAuxISR -= interval; @@ -1586,6 +1588,9 @@ void Stepper::isr() { if (is_babystep) nextBabystepISR = babystepping_isr(); #endif + // Enable ISRs to reduce latency for higher priority ISRs, or all ISRs if no prioritization. + hal.isr_on(); + // ^== Time critical. NOTHING besides pulse generation should be above here!!! if (!nextMainISR) nextMainISR = block_phase_isr(); // Manage acc/deceleration, get next block