diff --git a/.pio/build/project.checksum b/.pio/build/project.checksum new file mode 100644 index 00000000..e8ec9722 --- /dev/null +++ b/.pio/build/project.checksum @@ -0,0 +1 @@ +8a670918e9dc8280d88406fcbf3c7f8004d39238 \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..a1013d5b --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,214 @@ +{ + "configurations": [ + { + "name": "!!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags" + }, + { + "name": "Win32", + "includePath": [ + "c:/Users/barto/Dropbox/Arduino/ESP32/Grbl_Esp32/Grbl_Esp32", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/ArduinoOTA/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/Update/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/ESPmDNS/src", + "c:/Users/barto/Dropbox/Arduino/ESP32/Grbl_Esp32/libraries/ESP32SSDP", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/DNSServer/src", + "c:/Users/barto/Dropbox/Arduino/ESP32/Grbl_Esp32/libraries/arduinoWebSockets/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/SD/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/SPI/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/SPIFFS/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/FS/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/Preferences/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/BluetoothSerial/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/config", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/app_trace", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/app_update", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/asio", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/bootloader_support", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/bt", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/coap", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/console", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/driver", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp-tls", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp32", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_adc_cal", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_event", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_http_client", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_http_server", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_https_ota", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_ringbuf", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/ethernet", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/expat", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/fatfs", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/freemodbus", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/freertos", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/heap", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/idf_test", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/jsmn", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/json", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/libsodium", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/log", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/lwip", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/mbedtls", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/mdns", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/micro-ecc", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/mqtt", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/newlib", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/nghttp", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/nvs_flash", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/openssl", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/protobuf-c", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/protocomm", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/pthread", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/sdmmc", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/smartconfig_ack", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/soc", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/spi_flash", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/spiffs", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/tcp_transport", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/tcpip_adapter", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/ulp", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/vfs", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/wear_levelling", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/wifi_provisioning", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/wpa_supplicant", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/xtensa-debug-module", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp-face", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp32-camera", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/fb_gfx", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/cores/esp32", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/variants/nodemcu-32s", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/AsyncUDP/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/AzureIoT/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/BLE/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/ESP32/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/FFat/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/HTTPClient/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/HTTPUpdate/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/NetBIOS/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/SD_MMC/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/SimpleBLE/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/Ticker/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/Wire/src", + "C:/Users/barto/.platformio/packages/tool-unity", + "" + ], + "browse": { + "limitSymbolsToIncludedHeaders": true, + "path": [ + "c:/Users/barto/Dropbox/Arduino/ESP32/Grbl_Esp32/Grbl_Esp32", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/ArduinoOTA/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/Update/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/ESPmDNS/src", + "c:/Users/barto/Dropbox/Arduino/ESP32/Grbl_Esp32/libraries/ESP32SSDP", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/DNSServer/src", + "c:/Users/barto/Dropbox/Arduino/ESP32/Grbl_Esp32/libraries/arduinoWebSockets/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/SD/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/SPI/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/SPIFFS/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/FS/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/Preferences/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/BluetoothSerial/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/config", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/app_trace", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/app_update", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/asio", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/bootloader_support", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/bt", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/coap", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/console", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/driver", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp-tls", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp32", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_adc_cal", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_event", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_http_client", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_http_server", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_https_ota", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_ringbuf", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/ethernet", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/expat", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/fatfs", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/freemodbus", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/freertos", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/heap", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/idf_test", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/jsmn", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/json", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/libsodium", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/log", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/lwip", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/mbedtls", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/mdns", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/micro-ecc", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/mqtt", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/newlib", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/nghttp", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/nvs_flash", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/openssl", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/protobuf-c", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/protocomm", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/pthread", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/sdmmc", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/smartconfig_ack", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/soc", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/spi_flash", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/spiffs", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/tcp_transport", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/tcpip_adapter", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/ulp", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/vfs", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/wear_levelling", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/wifi_provisioning", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/wpa_supplicant", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/xtensa-debug-module", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp-face", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp32-camera", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/fb_gfx", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/cores/esp32", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/variants/nodemcu-32s", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/AsyncUDP/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/AzureIoT/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/BLE/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/ESP32/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/FFat/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/HTTPClient/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/HTTPUpdate/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/NetBIOS/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/SD_MMC/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/SimpleBLE/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/Ticker/src", + "C:/Users/barto/.platformio/packages/framework-arduinoespressif32/libraries/Wire/src", + "C:/Users/barto/.platformio/packages/tool-unity", + "" + ] + }, + "defines": [ + "PLATFORMIO=40100", + "ARDUINO_NodeMCU_32S", + "ESP32", + "ESP_PLATFORM", + "F_CPU=240000000L", + "HAVE_CONFIG_H", + "MBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\"", + "ARDUINO=10805", + "ARDUINO_ARCH_ESP32", + "ARDUINO_VARIANT=\"nodemcu-32s\"", + "ARDUINO_BOARD=\"NodeMCU-32S\"", + "" + ], + "intelliSenseMode": "clang-x64", + "cStandard": "c99", + "cppStandard": "c++11", + "compilerPath": "\"C:/Users/barto/.platformio/packages/toolchain-xtensa32/bin/xtensa-esp32-elf-gcc.exe\" -mlongcalls" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..272828b5 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..14b929dd --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,32 @@ +// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY + +// PIO Unified Debugger +// +// Documentation: https://docs.platformio.org/page/plus/debugging.html +// Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html + +{ + "version": "0.2.0", + "configurations": [ + { + "type": "platformio-debug", + "request": "launch", + "name": "PIO Debug", + "executable": "c:/Users/barto/Dropbox/Arduino/ESP32/Grbl_Esp32/.pio/build/nodemcu-32s/firmware.elf", + "toolchainBinDir": "C:/Users/barto/.platformio/packages/toolchain-xtensa32/bin", + "preLaunchTask": { + "type": "PlatformIO", + "task": "Pre-Debug" + }, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "type": "platformio-debug", + "request": "launch", + "name": "PIO Debug (skip Pre-Debug)", + "executable": "c:/Users/barto/Dropbox/Arduino/ESP32/Grbl_Esp32/.pio/build/nodemcu-32s/firmware.elf", + "toolchainBinDir": "C:/Users/barto/.platformio/packages/toolchain-xtensa32/bin", + "internalConsoleOptions": "openOnSessionStart" + } + ] +} \ No newline at end of file diff --git a/Grbl_Esp32/cpu_map.h b/Grbl_Esp32/cpu_map.h index 1fee4513..fa3a3f51 100644 --- a/Grbl_Esp32/cpu_map.h +++ b/Grbl_Esp32/cpu_map.h @@ -177,6 +177,8 @@ // https://github.com/bdring/Grbl_Esp32/wiki/BESC-Spindle-Feature #define CPU_MAP_NAME "CPU_MAP_ESP32_ESC_SPINDLE" + + #define SHOW_EXTENDED_SETTINGS #define USE_RMT_STEPS @@ -198,9 +200,12 @@ // Begin RC ESC Based Spindle Information ====================== #define SPINDLE_PWM_BIT_PRECISION 16 // 16 bit recommended for ESC (don't change) + + /* Important ESC Settings $33=50 // Hz this is the typical good frequency for an ESC + #define DEFAULT_SPINDLE_FREQ 5000.0 // $33 Hz (extended set) Determine the typical min and max pulse length of your ESC min_pulse is typically 1ms (0.001 sec) or less @@ -212,10 +217,16 @@ (pulse / PWM_period) - min_pulse = (0.001 / 0.02) = 0.035 = 3.5% so ... $33 and $34 = 3.5 + min_pulse = (0.001 / 0.02) = 0.05 = 5% so ... $34 and $35 = 5.0 max_pulse = (0.002 / .02) = 0.1 = 10% so ... $36=10 */ + #define DEFAULT_SPINDLE_FREQ 50.0 + #define DEFAULT_SPINDLE_OFF_VALUE 5.0 + #define DEFAULT_SPINDLE_MIN_VALUE 5.0 + #define DEFAULT_SPINDLE_MAX_VALUE 10.0 + + // End RC ESC Based Spindle #defines =========================== diff --git a/Grbl_Esp32/spindle_control.cpp b/Grbl_Esp32/spindle_control.cpp index 8877bf37..8b600f59 100644 --- a/Grbl_Esp32/spindle_control.cpp +++ b/Grbl_Esp32/spindle_control.cpp @@ -22,10 +22,10 @@ #ifdef SPINDLE_PWM_PIN static float pwm_gradient; // Precalulated value to speed up rpm to PWM conversions. -float spindle_pwm_period; -float spindle_pwm_off_value; -float spindle_pwm_min_value; -float spindle_pwm_max_value; +uint32_t spindle_pwm_period; // how many counts in 1 period +uint32_t spindle_pwm_off_value; +uint32_t spindle_pwm_min_value; +uint32_t spindle_pwm_max_value; #endif void spindle_init() @@ -41,27 +41,21 @@ void spindle_init() grbl_send(CLIENT_SERIAL, "[MSG: INVERT_SPINDLE_ENABLE_PIN]\r\n"); #endif - spindle_pwm_period = SPINDLE_PULSE_RES_COUNT; - - - spindle_pwm_off_value = (spindle_pwm_period * settings.spindle_pwm_off_value / 100); - spindle_pwm_min_value = (spindle_pwm_period * settings.spindle_pwm_min_value / 100); - spindle_pwm_max_value = (spindle_pwm_period * settings.spindle_pwm_max_value / 100); - - //pwm_gradient = (settings.spindle_pwm_max_value - settings.spindle_pwm_min_value)/(settings.rpm_max-settings.rpm_min); - pwm_gradient = (spindle_pwm_max_value-spindle_pwm_min_value)/(settings.rpm_max-settings.rpm_min); - - - if ( (F_TIMERS / (uint32_t)settings.spindle_pwm_freq) < spindle_pwm_max_value) { - /* - PWM Generator is based on 80,000,000 Hz counter - Therefor the freq determines the resolution 80,000,000 / freq = max resolution - For 5000 that is 80,000,000 / 5000 = 16000 - Round down to nearest bit count for SPINDLE_PWM_MAX_VALUE = 13bits (8192) - */ - grbl_sendf(CLIENT_SERIAL, "[MSG: Warning! Spindle freq %5.0f too high for requested PWM max %5.2f%% (%5.0f)]\r\n", settings.spindle_pwm_freq, settings.spindle_pwm_max_value, spindle_pwm_max_value); + // determine how many PWM counts are in eqach PWM cycle + spindle_pwm_period = ((1< settings.spindle_pwm_min_value) { + grbl_sendf(CLIENT_SERIAL, "[MSG: Warning spindle min pwm is greater than max. Check $35 and $36]\r\n", pwm_gradient); } + // pre-caculate some PWM count values + spindle_pwm_off_value = (spindle_pwm_period * settings.spindle_pwm_off_value / 100.0); + spindle_pwm_min_value = (spindle_pwm_period * settings.spindle_pwm_min_value / 100.0); + spindle_pwm_max_value = (spindle_pwm_period * settings.spindle_pwm_max_value / 100.0); + + // The pwm_gradient is the pwm duty cycle units per rpm + pwm_gradient = (spindle_pwm_max_value-spindle_pwm_min_value)/(settings.rpm_max-settings.rpm_min); + // Use DIR and Enable if pins are defined #ifdef SPINDLE_ENABLE_PIN pinMode(SPINDLE_ENABLE_PIN, OUTPUT); @@ -73,7 +67,7 @@ void spindle_init() // use the LED control feature to setup PWM https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/ledc.html ledcSetup(SPINDLE_PWM_CHANNEL, (double)settings.spindle_pwm_freq, SPINDLE_PWM_BIT_PRECISION); // setup the channel - ledcAttachPin(SPINDLE_PWM_PIN, SPINDLE_PWM_CHANNEL); // attach the PWM to the pin + ledcAttachPin(SPINDLE_PWM_PIN, SPINDLE_PWM_CHANNEL); // attach the PWM to the pin // Start with spindle off off spindle_stop(); @@ -81,7 +75,7 @@ void spindle_init() } void spindle_stop() -{ +{ spindle_set_enable(false); #ifdef SPINDLE_PWM_PIN @@ -117,8 +111,9 @@ uint8_t spindle_get_state() // returns SPINDLE_STATE_DISABLE, SPINDLE_STATE_CW } void spindle_set_speed(uint32_t pwm_value) -{ +{ #ifndef SPINDLE_PWM_PIN + grbl_sendf(CLIENT_SERIAL, "[MSG: set speed...no pin defined]\r\n"); return; #else #ifndef SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED @@ -160,7 +155,7 @@ uint32_t spindle_compute_pwm_value(float rpm){ #ifdef ENABLE_PIECEWISE_LINEAR_SPINDLE pwm_value = piecewise_linear_fit(rpm); #else - pwm_value = floor((rpm - settings.rpm_min)*pwm_gradient) + settings.spindle_pwm_min_value; + pwm_value = floor((rpm - settings.rpm_min)*pwm_gradient) + spindle_pwm_min_value; #endif } return(pwm_value); @@ -211,9 +206,7 @@ void spindle_sync(uint8_t state, float rpm) void grbl_analogWrite(uint8_t chan, uint32_t duty) { if (ledcRead(chan) != duty) // reduce unnecessary calls to ledcWrite() - { - // Useful for debug, but too many messages in laser mode - // grbl_sendf(CLIENT_SERIAL, "[MSG: grbl_analogWrite %d]\r\n", duty); + { ledcWrite(chan, duty); } } diff --git a/Grbl_Esp32/spindle_control.h b/Grbl_Esp32/spindle_control.h index fd4147d4..068661ef 100644 --- a/Grbl_Esp32/spindle_control.h +++ b/Grbl_Esp32/spindle_control.h @@ -31,7 +31,7 @@ #define SPINDLE_STATE_CW bit(0) #define SPINDLE_STATE_CCW bit(1) -#define SPINDLE_PULSE_RES_COUNT ((1<is_pwm_rate_adjusted) { - spindle_set_speed(settings.spindle_pwm_off_value); + spindle_set_speed(spindle_pwm_off_value); } } @@ -1325,7 +1325,7 @@ void st_prep_buffer() } else { sys.spindle_speed = 0.0; #if ( (defined VARIABLE_SPINDLE) && (defined SPINDLE_PWM_PIN) ) - prep.current_spindle_pwm = settings.spindle_pwm_off_value; + prep.current_spindle_pwm = spindle_pwm_off_value ; #endif } diff --git a/doc/csv/setting_codes_en_US.csv b/doc/csv/setting_codes_en_US.csv index 55362625..71571e40 100644 --- a/doc/csv/setting_codes_en_US.csv +++ b/doc/csv/setting_codes_en_US.csv @@ -21,10 +21,10 @@ "30","Maximum spindle speed","RPM","Maximum spindle speed. Sets PWM to 100% duty cycle." "31","Minimum spindle speed","RPM","Minimum spindle speed. Sets PWM to 0.4% or lowest duty cycle." "32","Laser-mode enable","boolean","Enables laser mode. Consecutive G1/2/3 commands will not halt when spindle speed is changed." -"33","Spindle PWM Freq","16-bit","Spindle PWM Freq" -"34","Spindle PWM Off Value","16-bit","Spindle PWM Off Value" -"35","Spindle PWM Min Value","16-bit","Spindle PWM Min Value" -"36","Spindle PWM Max Value","16-bit","Spindle PWM Max Value" +"33","Spindle PWM Freq","16-bit","Spindle PWM Freq (reboot to take effect)" +"34","Spindle PWM Off Value","16-bit","Spindle PWM Off Value (reboot to take effect)" +"35","Spindle PWM Min Value","16-bit","Spindle PWM Min Value (reboot to take effect)" +"36","Spindle PWM Max Value","16-bit","Spindle PWM Max Value (reboot to take effect)" "80-84","User integer Values","unsigned 16-bit","Reserved for custom machine use" "90-94","User Floating point value","float","Reserved for custom machine use" "100","X-axis travel resolution","step/mm","X-axis travel resolution in steps per millimeter."