diff --git a/FluidNC/esp32/StepTimer.cpp b/FluidNC/esp32/StepTimer.cpp index 05336f6be..338698fbd 100644 --- a/FluidNC/esp32/StepTimer.cpp +++ b/FluidNC/esp32/StepTimer.cpp @@ -29,14 +29,21 @@ static void IRAM_ATTR timer_isr(void* arg) { } } +// Possibly-unnecessary optimization to avoid rewriting the alarm value +static uint32_t old_ticks = 0xffffffff; + void IRAM_ATTR stepTimerStart() { timer_ll_set_alarm_value(&TIMERG0, TIMER_0, 10ULL); // Interrupt very soon to start the stepping + old_ticks = 10ULL; timer_ll_set_alarm_enable(&TIMERG0, TIMER_0, true); timer_ll_set_counter_enable(&TIMERG0, TIMER_0, true); } void IRAM_ATTR stepTimerSetTicks(uint32_t ticks) { - timer_ll_set_alarm_value(&TIMERG0, TIMER_0, (uint64_t)ticks); + if (ticks != old_ticks) { + timer_ll_set_alarm_value(&TIMERG0, TIMER_0, (uint64_t)ticks); + old_ticks = ticks; + } } void IRAM_ATTR stepTimerStop() { @@ -61,7 +68,7 @@ void stepTimerInit(uint32_t frequency, bool (*callback)(void)) { timer_isr_callback = callback; esp_intr_alloc_intrstatus(timer_group_periph_signals.groups[TIMER_GROUP_0].t0_irq_id, - ESP_INTR_FLAG_IRAM, + ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LEVEL3, timer_ll_get_intr_status_reg(&TIMERG0), 1 << TIMER_0, timer_isr, diff --git a/FluidNC/esp32/i2s_engine.c b/FluidNC/esp32/i2s_engine.c index fe4df8c25..967161aa5 100644 --- a/FluidNC/esp32/i2s_engine.c +++ b/FluidNC/esp32/i2s_engine.c @@ -455,22 +455,24 @@ static IRAM_ATTR void finish_dir() { // push _pulse_counts copies of the memory variable to the // I2S FIFO, thus creating a pulse of the desired length. static IRAM_ATTR void finish_step() { - for (int i = 0; i < _pulse_counts; i++) { - I2S0.fifo_wr = new_port_data; + if (new_port_data == i2s_out_port_data) { + return; } for (int i = 0; i < _pulse_counts; i++) { - I2S0.fifo_wr = i2s_out_port_data; + I2S0.fifo_wr = new_port_data; } + // There is no need for multiple "step off" samples since the timer will not fire + // until the next time for a pulse. + I2S0.fifo_wr = i2s_out_port_data; } static IRAM_ATTR int start_unstep() { -#if 1 return 1; -#else - return 0; -#endif } +// Not called since start_unstep() returns 1 +static IRAM_ATTR void finish_unstep() {} + static uint32_t max_pulses_per_sec() { return 1000000 / (2 * _pulse_counts * I2S_OUT_USEC_PER_PULSE); } @@ -486,7 +488,7 @@ step_engine_t engine = { set_step_pin, finish_step, start_unstep, - finish_step, // finish_step and finish_unstep are the same + finish_unstep, max_pulses_per_sec }; diff --git a/FluidNC/src/Machine/Axis.cpp b/FluidNC/src/Machine/Axis.cpp index b206cb268..09199771f 100644 --- a/FluidNC/src/Machine/Axis.cpp +++ b/FluidNC/src/Machine/Axis.cpp @@ -7,7 +7,7 @@ namespace Machine { void Axis::group(Configuration::HandlerBase& handler) { handler.item("steps_per_mm", _stepsPerMm, 0.001, 100000.0); - handler.item("max_rate_mm_per_min", _maxRate, 0.001, 100000.0); + handler.item("max_rate_mm_per_min", _maxRate, 0.001, 200000.0); handler.item("acceleration_mm_per_sec2", _acceleration, 0.001, 100000.0); handler.item("max_travel_mm", _maxTravel, 0.1, 10000000.0); handler.item("soft_limits", _softLimits); diff --git a/FluidNC/src/Stepping.cpp b/FluidNC/src/Stepping.cpp index d9d30ccac..6e00043d5 100644 --- a/FluidNC/src/Stepping.cpp +++ b/FluidNC/src/Stepping.cpp @@ -151,6 +151,8 @@ void IRAM_ATTR Stepping::step(uint8_t step_mask, uint8_t dir_mask) { previous_dir_mask = dir_mask; } + step_engine->start_step(); + // Turn on step pulses for motors that are supposed to step now for (size_t axis = 0; axis < _n_active_axes; axis++) { if (bitnum_is_true(step_mask, axis)) { @@ -193,8 +195,7 @@ void IRAM_ATTR Stepping::waitDirection() {} // Called only from Stepper::pulse_func when a new segment is loaded // The argument is in units of ticks of the timer that generates ISRs void IRAM_ATTR Stepping::setTimerPeriod(uint16_t timerTicks) { - // stepTimerSetTicks((uint32_t)timerTicks * 3 / 10); - stepTimerSetTicks((uint32_t)timerTicks / 2); + stepTimerSetTicks((uint32_t)timerTicks); } // Called only from Stepper::wake_up which is not used in ISR context