From 04c75e4e226474fde87e9d3e9ea36d66ef1cd182 Mon Sep 17 00:00:00 2001 From: bdring Date: Sat, 27 Jun 2020 13:15:33 -0500 Subject: [PATCH] Fix spindle enable pin logic --- Grbl_Esp32/Spindles/DacSpindle.cpp | 4 ---- Grbl_Esp32/Spindles/PWMSpindle.cpp | 9 +++++---- Grbl_Esp32/Spindles/RelaySpindle.cpp | 3 --- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Grbl_Esp32/Spindles/DacSpindle.cpp b/Grbl_Esp32/Spindles/DacSpindle.cpp index a72c149d..0e51de67 100644 --- a/Grbl_Esp32/Spindles/DacSpindle.cpp +++ b/Grbl_Esp32/Spindles/DacSpindle.cpp @@ -94,10 +94,6 @@ uint32_t DacSpindle::set_rpm(uint32_t rpm) { pwm_value = map_uint32_t(rpm, _min_rpm, _max_rpm, _pwm_min_value, _pwm_max_value); } - - if (_off_with_zero_speed) { - set_enable_pin(rpm != 0); - } set_output(pwm_value); diff --git a/Grbl_Esp32/Spindles/PWMSpindle.cpp b/Grbl_Esp32/Spindles/PWMSpindle.cpp index c741c10a..e4e053b7 100644 --- a/Grbl_Esp32/Spindles/PWMSpindle.cpp +++ b/Grbl_Esp32/Spindles/PWMSpindle.cpp @@ -145,9 +145,6 @@ uint32_t PWMSpindle::set_rpm(uint32_t rpm) { pwm_value = map_uint32_t(rpm, _min_rpm, _max_rpm, _pwm_min_value, _pwm_max_value); } - if (_off_with_zero_speed) - set_enable_pin(rpm != 0); - set_output(pwm_value); return 0; @@ -165,7 +162,7 @@ void PWMSpindle::set_state(uint8_t state, uint32_t rpm) { set_rpm(rpm); } - set_enable_pin(state == SPINDLE_DISABLE); + set_enable_pin(state != SPINDLE_DISABLE); sys.report_ovr_counter = 0; // Set to report change immediately } @@ -227,6 +224,10 @@ void PWMSpindle::set_output(uint32_t duty) { void PWMSpindle::set_enable_pin(bool enable) { if (_enable_pin == UNDEFINED_PIN) return; + + if (_off_with_zero_speed && sys.spindle_speed == 0) + enable = false; + #ifndef INVERT_SPINDLE_ENABLE_PIN digitalWrite(_enable_pin, enable); #else diff --git a/Grbl_Esp32/Spindles/RelaySpindle.cpp b/Grbl_Esp32/Spindles/RelaySpindle.cpp index e0c09ba5..76f1444e 100644 --- a/Grbl_Esp32/Spindles/RelaySpindle.cpp +++ b/Grbl_Esp32/Spindles/RelaySpindle.cpp @@ -66,9 +66,6 @@ uint32_t RelaySpindle::set_rpm(uint32_t rpm) { set_output(1); } - if (_off_with_zero_speed) - set_enable_pin(rpm != 0); - return rpm; }