1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-27 08:14:31 +02:00

Fix VFD speed change from ISR (#811)

* Motion control calls set_rpm frequently from an ISR. Unfortunately the last change added some debug information in there, which can cause the ESP32 to crash in boundary cases.

* Update Grbl.h

Co-authored-by: Stefan de Bruijn <stefan@nubilosoft.com>
Co-authored-by: bdring <barton.dring@gmail.com>
This commit is contained in:
Stefan de Bruijn
2021-03-11 22:41:40 +01:00
committed by GitHub
parent d76a5fe2f2
commit ef3dc59b8a
2 changed files with 14 additions and 5 deletions

View File

@@ -22,7 +22,7 @@
// Grbl versioning system // Grbl versioning system
const char* const GRBL_VERSION = "1.3a"; const char* const GRBL_VERSION = "1.3a";
const char* const GRBL_VERSION_BUILD = "20210308"; const char* const GRBL_VERSION_BUILD = "20210311";
//#include <sdkconfig.h> //#include <sdkconfig.h>
#include <Arduino.h> #include <Arduino.h>

View File

@@ -406,6 +406,11 @@ namespace Spindles {
if (_current_state != state) { // already at the desired state. This function gets called a lot. if (_current_state != state) { // already at the desired state. This function gets called a lot.
set_mode(state, critical); // critical if we are in a job set_mode(state, critical); // critical if we are in a job
if (rpm != 0 && (rpm < _min_rpm || rpm > _max_rpm)) {
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "VFD: Requested speed %d outside range:(%d,%d)", rpm, _min_rpm, _max_rpm);
}
set_rpm(rpm); set_rpm(rpm);
if (state == SpindleState::Disable) { if (state == SpindleState::Disable) {
@@ -422,6 +427,10 @@ namespace Spindles {
} }
} else { } else {
if (_current_rpm != rpm) { if (_current_rpm != rpm) {
if (rpm != 0 && (rpm < _min_rpm || rpm > _max_rpm)) {
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "VFD: Requested speed %d outside range:(%d,%d)", rpm, _min_rpm, _max_rpm);
}
set_rpm(rpm); set_rpm(rpm);
if (rpm > _current_rpm) { if (rpm > _current_rpm) {
@@ -524,10 +533,11 @@ namespace Spindles {
// apply override // apply override
rpm = rpm * sys.spindle_speed_ovr / 100; // Scale by spindle speed override value (uint8_t percent) rpm = rpm * sys.spindle_speed_ovr / 100; // Scale by spindle speed override value (uint8_t percent)
if (rpm < _min_rpm || rpm > _max_rpm) { if (rpm != 0 && (rpm < _min_rpm || rpm > _max_rpm)) {
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "VFD: Requested speed %d outside range:(%d,%d)", rpm, _min_rpm, _max_rpm); // NOTE: Don't add a info message here; this method is called from the stepper_pulse_func ISR method, so
// emitting debug information could crash the ESP32.
rpm = constrain(rpm, _min_rpm, _max_rpm); rpm = constrain(rpm, _min_rpm, _max_rpm);
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "VFD: Requested speed changed to %d", rpm);
} }
// apply limits // apply limits
@@ -554,7 +564,6 @@ namespace Spindles {
ModbusCommand rpm_cmd; ModbusCommand rpm_cmd;
rpm_cmd.msg[0] = VFD_RS485_ADDR; rpm_cmd.msg[0] = VFD_RS485_ADDR;
set_speed_command(rpm, rpm_cmd); set_speed_command(rpm, rpm_cmd);
rpm_cmd.critical = (rpm == 0); rpm_cmd.critical = (rpm == 0);