diff --git a/Grbl_Esp32/data/config.yaml b/Grbl_Esp32/data/config.yaml index 5326c881..ac2ceb87 100644 --- a/Grbl_Esp32/data/config.yaml +++ b/Grbl_Esp32/data/config.yaml @@ -16,12 +16,12 @@ axes: shared_stepper_disable: gpio.13:high x: - steps_per_mm: 800 - max_rate: 2000 - acceleration: 25 - max_travel: 1000 + steps_per_mm: 1500 + max_rate: 50000 + acceleration: 5000 + max_travel: 100000 homing: - cycle: -1 + cycle: 0 mpos: 10 positive_direction: false feed_rate: 50.000 diff --git a/Grbl_Esp32/src/Machine/Axes.cpp b/Grbl_Esp32/src/Machine/Axes.cpp index bd043761..aeaf6f23 100644 --- a/Grbl_Esp32/src/Machine/Axes.cpp +++ b/Grbl_Esp32/src/Machine/Axes.cpp @@ -160,6 +160,7 @@ namespace Machine { a->unstep(); } } + config->_stepping->finishPulse(); } diff --git a/Grbl_Esp32/src/Stepper.cpp b/Grbl_Esp32/src/Stepper.cpp index 5ca3ee50..58ad3565 100644 --- a/Grbl_Esp32/src/Stepper.cpp +++ b/Grbl_Esp32/src/Stepper.cpp @@ -244,6 +244,7 @@ void IRAM_ATTR Stepper::pulse_func() { return; // Nothing to do but exit. } } + // Check probing state. if (sys_probe_state == ProbeState::Active && config->_probe->tripped()) { sys_probe_state = ProbeState::Off; diff --git a/Grbl_Esp32/src/Stepping.cpp b/Grbl_Esp32/src/Stepping.cpp index ac675230..5a4bfc1b 100644 --- a/Grbl_Esp32/src/Stepping.cpp +++ b/Grbl_Esp32/src/Stepping.cpp @@ -15,8 +15,6 @@ namespace Machine { { Stepping::I2S_STREAM, "I2S_stream" }, EnumItem(Stepping::RMT) }; - static std::atomic busy; - void Stepping::init() { info_serial("Step type:%s Pulse:%dus Dsbl Delay:%dus Dir Delay:%dus Idle Delay:%dms", // stepping->name(), @@ -39,8 +37,6 @@ namespace Machine { // Register pulse_func with the I2S subsystem // This could be done via the linker. // i2s_out_set_pulse_callback(Stepper::pulse_func); - - busy.store(false); } // Wait for motion to complete; the axes can still be moving @@ -83,7 +79,8 @@ namespace Machine { NOP(); } } - void Stepping::waitPulse() { + + void IRAM_ATTR Stepping::waitPulse() { uint64_t pulseEndTime; switch (_engine) { case I2S_STREAM: @@ -100,7 +97,8 @@ namespace Machine { return; } } - void Stepping::waitDirection() { + + void IRAM_ATTR Stepping::waitDirection() { if (_directionDelayUsecs) { // Stepper drivers need some time between changing direction and doing a pulse. switch (_engine) { @@ -108,7 +106,7 @@ namespace Machine { i2s_out_push_sample(_directionDelayUsecs); break; case stepper_id_t::I2S_STATIC: - case stepper_id_t::TIMED: { + case stepper_id_t::TIMED: // wait for step pulse time to complete...some time expired during code above // // If we are using GPIO stepping as opposed to RMT, record the @@ -116,14 +114,13 @@ namespace Machine { // If we are using RMT, we can't delay here. spinDelay(esp_timer_get_time(), _directionDelayUsecs); break; - case stepper_id_t::RMT: - break; - } + case stepper_id_t::RMT: + break; } } } - void Stepping::startPulseTimer() { + void IRAM_ATTR Stepping::startPulseTimer() { switch (_engine) { case stepper_id_t::I2S_STREAM: break; @@ -136,7 +133,7 @@ namespace Machine { } } - void Stepping::finishPulse() { + void IRAM_ATTR Stepping::finishPulse() { switch (_engine) { case stepper_id_t::I2S_STREAM: break; @@ -191,31 +188,25 @@ namespace Machine { // with probing and homing cycles that require true real-time positions. void IRAM_ATTR Stepping::onStepperDriverTimer() { // Timer ISR, normally takes a step. - + // // The intermediate handler clears the timer interrupt so we need not do it here + ++isr_count; - bool expected = false; - if (busy.compare_exchange_strong(expected, true)) { - ++isr_count; - - // Using autoReload results is less timing jitter so it is - // probably best to have it on. We keep the variable for - // convenience in debugging. - if (!autoReload) { - timerWrite(stepTimer, 0ULL); - } - - // It is tempting to defer this until after pulse_func(), - // but if pulse_func() determines that no more stepping - // is required and disables the timer, then that will be undone - // if the re-enable happens afterwards. - - timerAlarmEnable(stepTimer); - - Stepper::pulse_func(); - - busy.store(false); + // Using autoReload results is less timing jitter so it is + // probably best to have it on. We keep the variable for + // convenience in debugging. + if (!autoReload) { + timerWrite(stepTimer, 0ULL); } + + // It is tempting to defer this until after pulse_func(), + // but if pulse_func() determines that no more stepping + // is required and disables the timer, then that will be undone + // if the re-enable happens afterwards. + + timerAlarmEnable(stepTimer); + + Stepper::pulse_func(); } void Stepping::group(Configuration::HandlerBase& handler) { diff --git a/Grbl_Esp32/src/Stepping.h b/Grbl_Esp32/src/Stepping.h index 2e5acd14..c2c66178 100644 --- a/Grbl_Esp32/src/Stepping.h +++ b/Grbl_Esp32/src/Stepping.h @@ -19,7 +19,6 @@ */ #include "Configuration/Configurable.h" -// #include namespace Machine { class Stepping : public Configuration::Configurable { @@ -29,7 +28,7 @@ namespace Machine { private: static const int stepTimerNumber = 0; - static const bool autoReload = true; + static const bool autoReload = false; static hw_timer_t* stepTimer; static void onStepperDriverTimer(); diff --git a/UnitTests.vcxproj b/UnitTests.vcxproj index 1bfe2d52..8c9e5ce1 100644 --- a/UnitTests.vcxproj +++ b/UnitTests.vcxproj @@ -143,6 +143,7 @@ + @@ -276,6 +277,7 @@ + diff --git a/UnitTests.vcxproj.filters b/UnitTests.vcxproj.filters index 438d3d82..176ca0e4 100644 --- a/UnitTests.vcxproj.filters +++ b/UnitTests.vcxproj.filters @@ -507,6 +507,9 @@ X86TestSupport\soc + + src + @@ -854,6 +857,9 @@ X86TestSupport\driver + + src +