1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-29 17:19:50 +02:00

Fixed Spindle Issues during homing

Using the raw setting values (percentage) instead of calculated PWM (duty) off value
This commit is contained in:
bdring
2020-01-10 21:53:40 -06:00
parent faad68cb71
commit 46319a3616
9 changed files with 296 additions and 38 deletions

View File

@@ -0,0 +1 @@
8a670918e9dc8280d88406fcbf3c7f8004d39238

214
.vscode/c_cpp_properties.json vendored Normal file
View File

@@ -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
}

7
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

32
.vscode/launch.json vendored Normal file
View File

@@ -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"
}
]
}

View File

@@ -178,6 +178,8 @@
#define CPU_MAP_NAME "CPU_MAP_ESP32_ESC_SPINDLE"
#define SHOW_EXTENDED_SETTINGS
#define USE_RMT_STEPS
#define X_STEP_PIN GPIO_NUM_12
@@ -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 ===========================

View File

@@ -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;
// determine how many PWM counts are in eqach PWM cycle
spindle_pwm_period = ((1<<SPINDLE_PWM_BIT_PRECISION) -1);
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);
if (settings.spindle_pwm_min_value > 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);
@@ -119,6 +113,7 @@ 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);
@@ -212,8 +207,6 @@ 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);
}
}

View File

@@ -31,7 +31,7 @@
#define SPINDLE_STATE_CW bit(0)
#define SPINDLE_STATE_CCW bit(1)
#define SPINDLE_PULSE_RES_COUNT ((1<<SPINDLE_PWM_BIT_PRECISION) -1) //(don't change)
extern uint32_t spindle_pwm_off_value;
void spindle_init();
void spindle_stop();

View File

@@ -294,7 +294,7 @@ void IRAM_ATTR onStepperDriverTimer(void *para) // ISR It is time to take a ste
if (!(sys.state & STATE_JOG)) { // added to prevent ... jog after probing crash
// Ensure pwm is set properly upon completion of rate-controlled motion.
if (st.exec_block->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
}

View File

@@ -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."
1 $-Code Setting Units Setting Description
21 30 Maximum spindle speed RPM Maximum spindle speed. Sets PWM to 100% duty cycle.
22 31 Minimum spindle speed RPM Minimum spindle speed. Sets PWM to 0.4% or lowest duty cycle.
23 32 Laser-mode enable boolean Enables laser mode. Consecutive G1/2/3 commands will not halt when spindle speed is changed.
24 33 Spindle PWM Freq 16-bit Spindle PWM Freq Spindle PWM Freq (reboot to take effect)
25 34 Spindle PWM Off Value 16-bit Spindle PWM Off Value Spindle PWM Off Value (reboot to take effect)
26 35 Spindle PWM Min Value 16-bit Spindle PWM Min Value Spindle PWM Min Value (reboot to take effect)
27 36 Spindle PWM Max Value 16-bit Spindle PWM Max Value Spindle PWM Max Value (reboot to take effect)
28 80-84 User integer Values unsigned 16-bit Reserved for custom machine use
29 90-94 User Floating point value float Reserved for custom machine use
30 100 X-axis travel resolution step/mm X-axis travel resolution in steps per millimeter.