️ Improve pulse timing, fix LPC176x jitter (#27131)

This commit is contained in:
Mihai 2024-12-09 02:55:16 +02:00 committed by GitHub
parent 854da5fd9e
commit 5d591fd91d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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