From 1444f5d9264aa9cf7c90d7a995b1c57f14866b33 Mon Sep 17 00:00:00 2001 From: bdring Date: Sat, 12 Jun 2021 13:00:36 -0500 Subject: [PATCH] WIP PWMSpindle --- Grbl_Esp32/data/config.yaml | 5 +++++ Grbl_Esp32/src/MachineConfig.cpp | 2 +- Grbl_Esp32/src/Machines/3axis_v4.yaml | 5 +++++ Grbl_Esp32/src/Spindles/PWMSpindle.h | 30 +++++++++++++-------------- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Grbl_Esp32/data/config.yaml b/Grbl_Esp32/data/config.yaml index c185a596..aa7b18e9 100644 --- a/Grbl_Esp32/data/config.yaml +++ b/Grbl_Esp32/data/config.yaml @@ -86,3 +86,8 @@ probe: PWM: output_pin: gpio.2 enable_pin: gpio.22 + pwm_off: 0.0 + pwm_min: 0.0 + pwm_max: 100.0 + min_rpm: 0 + max_rpm: 1000 diff --git a/Grbl_Esp32/src/MachineConfig.cpp b/Grbl_Esp32/src/MachineConfig.cpp index d5bc47ef..97f8689c 100644 --- a/Grbl_Esp32/src/MachineConfig.cpp +++ b/Grbl_Esp32/src/MachineConfig.cpp @@ -501,7 +501,7 @@ size_t MachineConfig::readFile(const char* filename, char*& buffer) { file.close(); buffer[filesize] = 0; - log_debug("Read config file:\r\n" << buffer); + log_debug("Read config file:" << buffer); if (pos != filesize) { delete[] buffer; diff --git a/Grbl_Esp32/src/Machines/3axis_v4.yaml b/Grbl_Esp32/src/Machines/3axis_v4.yaml index dce83c71..decece31 100644 --- a/Grbl_Esp32/src/Machines/3axis_v4.yaml +++ b/Grbl_Esp32/src/Machines/3axis_v4.yaml @@ -86,3 +86,8 @@ probe: pwm: output_pin: gpio.2 enable_pin: gpio.22 + pwm_off: 0.0 + pwm_min: 0.0 + pwm_max: 100.0 + min_rpm: 0 + max_rpm: 1000 diff --git a/Grbl_Esp32/src/Spindles/PWMSpindle.h b/Grbl_Esp32/src/Spindles/PWMSpindle.h index 9ea9187d..8662646c 100644 --- a/Grbl_Esp32/src/Spindles/PWMSpindle.h +++ b/Grbl_Esp32/src/Spindles/PWMSpindle.h @@ -54,9 +54,9 @@ namespace Spindles { handler.item("max_rpm", _max_rpm); handler.item("pwm_freq", _pwm_freq); - handler.item("pwm_off", _pwm_off_setting); - handler.item("pwm_min", _pwm_min_setting); - handler.item("pwm_max", _pwm_max_setting); + handler.item("pwm_off", _pwm_off_setting, 0.0, 100.0); + handler.item("pwm_min", _pwm_min_setting, 0.0, 100.0); + handler.item("pwm_max", _pwm_max_setting, 0.0, 100.0); handler.item("invert_pwm", _invert_pwm); handler.item("output_pin", _output_pin); handler.item("enable_pin", _enable_pin); @@ -72,25 +72,25 @@ namespace Spindles { virtual ~PWM() {} protected: - uint32_t _pwm_off_setting; // do we need these 3? - uint32_t _pwm_min_setting; - uint32_t _pwm_max_setting; + float _pwm_off_setting = 0; // do we need these 3? + float _pwm_min_setting = 0; + float _pwm_max_setting = 0; int32_t _current_pwm_duty; - uint32_t _min_rpm; - uint32_t _max_rpm; - uint32_t _pwm_off; - uint32_t _pwm_min; - uint32_t _pwm_max; + uint32_t _min_rpm = 0; + uint32_t _max_rpm = 1000; + uint32_t _pwm_off; // calculated at init + uint32_t _pwm_min; // calculated at init + uint32_t _pwm_max; // calculated at init Pin _output_pin; Pin _enable_pin; Pin _direction_pin; uint8_t _pwm_chan_num; uint32_t _pwm_freq = 5000; - uint32_t _pwm_period; // how many counts in 1 period - uint8_t _pwm_precision; - bool _off_with_zero_speed; - bool _invert_pwm; + uint32_t _pwm_period; // how many counts in 1 period + uint8_t _pwm_precision; // auto calculated + bool _off_with_zero_speed = false; + bool _invert_pwm = false; virtual void set_direction(bool Clockwise); virtual void set_output(uint32_t duty);