1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-02 10:53:01 +02:00

Laser mode fix (#543)

* Fixed Laser Mode

Enablin pin was turning off, but not back on in laser mode

* Added Settings

- $Spindle/Enable/Invert=Off
- $Spindle/Enable/OffWithSpeed=Off
- $Spindle/PWM/Invert=Off

* Update build date
This commit is contained in:
bdring
2020-08-13 06:41:35 -06:00
committed by GitHub
parent 61663ff938
commit bb6ca867b2
9 changed files with 52 additions and 55 deletions

View File

@@ -316,13 +316,6 @@ Some features should not be changed. See notes below.
// NOTE: PLEASE DO NOT USE THIS, unless you have a situation that needs it.
// #define INVERT_LIMIT_PIN_MASK (bit(X_AXIS)|bit(Y_AXIS)) // Default disabled. Uncomment to enable.
// Inverts the spindle enable pin from low-disabled/high-enabled to low-enabled/high-disabled. Useful
// for some pre-built electronic boards.
// #define INVERT_SPINDLE_ENABLE_PIN // Default disabled. Uncomment to enable.
// Inverts the spindle PWM output pin from low-disabled/high-enabled to low-enabled/high-disabled.
// #define INVERT_SPINDLE_OUTPUT_PIN // Default disabled. Uncomment to enable.
// Inverts the selected coolant pin from low-disabled/high-enabled to low-enabled/high-disabled. Useful
// for some pre-built electronic boards.
// #define INVERT_COOLANT_FLOOD_PIN // Default disabled. Uncomment to enable.
@@ -445,13 +438,6 @@ Some features should not be changed. See notes below.
// tool length offset value is subtracted from the current location.
#define TOOL_LENGTH_OFFSET_AXIS Z_AXIS // Default z-axis. Valid values are X_AXIS, Y_AXIS, or Z_AXIS.
// Alters the behavior of the spindle enable pin. By default Grbl will not disable the enable pin if
// spindle speed is zero and M3/4 is active, but still sets the PWM output to zero. This allows the users
// to know if the spindle is active and use it as an additional control input.
// However, in some use cases, user may want the enable pin to disable with a zero spindle speed and
// re-enable when spindle speed is greater than zero. This option does that.
#define SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED // Default enabled. Comment to disable.
// With this enabled, Grbl sends back an echo of the line it has received, which has been pre-parsed (spaces
// removed, capitalized letters, no comments) and is to be immediately executed by Grbl. Echoes will not be
// sent upon a line buffer overflow, but should for all normal lines sent to Grbl. For example, if a user

View File

@@ -155,6 +155,18 @@
# define DEFAULT_SPINDLE_DELAY_SPINDOWN 0
#endif
#ifndef DEFAULT_INVERT_SPINDLE_OUTPUT_PIN
# define DEFAULT_INVERT_SPINDLE_OUTPUT_PIN 0
#endif
#ifndef DEFAULT_INVERT_SPINDLE_ENABLE_PIN
# define DEFAULT_INVERT_SPINDLE_ENABLE_PIN 0
#endif
#ifndef DEFAULT_SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED
# define DEFAULT_SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED 0
#endif
// ================ user settings =====================
#ifndef DEFAULT_USER_INT_80
# define DEFAULT_USER_INT_80 0 // $80 User integer setting

View File

@@ -23,7 +23,7 @@
// Grbl versioning system
#define GRBL_VERSION "1.3a"
#define GRBL_VERSION_BUILD "20200811"
#define GRBL_VERSION_BUILD "20200812"
//#include <sdkconfig.h>
#include <Arduino.h>

View File

@@ -30,7 +30,7 @@
#define Y_STEP_PIN GPIO_NUM_14 // use Y labeled connector
#define Y2_STEP_PIN GPIO_NUM_21 // ganged motor
#define Y_DIRECTION_PIN GPIO_NUM_25 // use Y labeled connector
#define Y2_DIRECTION_PIN X_DIRECTION_PIN
#define Y2_DIRECTION_PIN Y_DIRECTION_PIN
#define Y_AXIS_SQUARING
#define Z_STEP_PIN GPIO_NUM_12 // use X labeled connector

View File

@@ -73,21 +73,11 @@
#define SPINDLE_OUTPUT_PIN GPIO_NUM_25
#define SPINDLE_ENABLE_PIN GPIO_NUM_4
// Relay operation
// Install Jumper near relay
// For PWM remove jumper to prevent relay damage
// Interlock jumper along top edge needs to be installed for both versions
#define USE_RELAY // comment out to use PWM
#ifdef USE_RELAY
#define SPINDLE_TYPE SPINDLE_TYPE_RELAY
#else
#define SPINDLE_TYPE SPINDLE_TYPE_PWM
#endif
#define SPINDLE_TYPE SPINDLE_TYPE_RELAY // default use $Spindle/Type=PWM or $Spindle/Type=Laser
#define PROBE_PIN GPIO_NUM_22
#define X_LIMIT_PIN GPIO_NUM_36
#define Y_LIMIT_PIN GPIO_NUM_39
#define Z_LIMIT_PIN GPIO_NUM_34
#define A_LIMIT_PIN GPIO_NUM_35
#define A_LIMIT_PIN GPIO_NUM_35

View File

@@ -41,6 +41,9 @@ FloatSetting* rpm_max;
FloatSetting* rpm_min;
FloatSetting* spindle_delay_spinup;
FloatSetting* spindle_delay_spindown;
FlagSetting* spindle_enbl_off_with_zero_speed;
FlagSetting* spindle_enable_invert;
FlagSetting* spindle_output_invert;
FloatSetting* spindle_pwm_off_value;
FloatSetting* spindle_pwm_min_value;
@@ -267,10 +270,17 @@ void make_settings() {
spindle_pwm_off_value =
new FloatSetting(EXTENDED, WG, "34", "Spindle/PWM/Off", DEFAULT_SPINDLE_OFF_VALUE, 0.0, 100.0); // these are percentages
// IntSetting spindle_pwm_bit_precision(EXTENDED, WG, "Spindle/PWM/Precision", DEFAULT_SPINDLE_BIT_PRECISION, 1, 16);
spindle_pwm_freq = new FloatSetting(EXTENDED, WG, "33", "Spindle/PWM/Frequency", DEFAULT_SPINDLE_FREQ, 0, 100000);
spindle_pwm_freq = new FloatSetting(EXTENDED, WG, "33", "Spindle/PWM/Frequency", DEFAULT_SPINDLE_FREQ, 0, 100000);
spindle_output_invert = new FlagSetting(GRBL, WG, NULL, "Spindle/PWM/Invert", DEFAULT_INVERT_SPINDLE_OUTPUT_PIN);
spindle_delay_spinup = new FloatSetting(EXTENDED, WG, NULL, "Spindle/Delay/SpinUp", DEFAULT_SPINDLE_DELAY_SPINUP, 0, 30);
spindle_delay_spindown = new FloatSetting(EXTENDED, WG, NULL, "Spindle/Delay/SpinDown", DEFAULT_SPINDLE_DELAY_SPINUP, 0, 30);
spindle_enbl_off_with_zero_speed =
new FlagSetting(GRBL, WG, NULL, "Spindle/Enable/OffWithSpeed", DEFAULT_SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED);
spindle_enable_invert = new FlagSetting(GRBL, WG, NULL, "Spindle/Enable/Invert", DEFAULT_INVERT_SPINDLE_ENABLE_PIN);
// GRBL Non-numbered settings
startup_line_0 = new StringSetting(GRBL, WG, "N0", "GCode/Line0", "", checkStartupLine);
startup_line_1 = new StringSetting(GRBL, WG, "N1", "GCode/Line1", "", checkStartupLine);

View File

@@ -43,6 +43,9 @@ extern FloatSetting* rpm_max;
extern FloatSetting* rpm_min;
extern FloatSetting* spindle_delay_spinup;
extern FloatSetting* spindle_delay_spindown;
extern FlagSetting* spindle_enbl_off_with_zero_speed;
extern FlagSetting* spindle_enable_invert;
extern FlagSetting* spindle_output_invert;
extern FloatSetting* spindle_pwm_off_value;
extern FloatSetting* spindle_pwm_min_value;

View File

@@ -142,9 +142,10 @@ namespace Spindles {
if (_off_with_zero_speed && sys.spindle_speed == 0)
enable = false;
#ifdef INVERT_SPINDLE_ENABLE_PIN
enable = !enable;
#endif
if (spindle_enable_invert->get())
enable = !enable;
digitalWrite(_enable_pin, enable);
// turn off anything that acts like an enable

View File

@@ -61,29 +61,23 @@ namespace Spindles {
#ifdef SPINDLE_OUTPUT_PIN
_output_pin = SPINDLE_OUTPUT_PIN;
#else
_output_pin = UNDEFINED_PIN;
_output_pin = UNDEFINED_PIN;
#endif
#ifdef INVERT_SPINDLE_OUTPUT_PIN
_invert_pwm = true;
#else
_invert_pwm = false;
#endif
_invert_pwm = spindle_output_invert->get();
#ifdef SPINDLE_ENABLE_PIN
_enable_pin = SPINDLE_ENABLE_PIN;
# ifdef SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED
_off_with_zero_speed = true;
# endif
#else
_enable_pin = UNDEFINED_PIN;
_off_with_zero_speed = false;
_enable_pin = UNDEFINED_PIN;
#endif
_off_with_zero_speed = spindle_enbl_off_with_zero_speed->get();
#ifdef SPINDLE_DIR_PIN
_direction_pin = SPINDLE_DIR_PIN;
#else
_direction_pin = UNDEFINED_PIN;
_direction_pin = UNDEFINED_PIN;
#endif
is_reversable = (_direction_pin != UNDEFINED_PIN);
@@ -105,9 +99,9 @@ namespace Spindles {
_max_rpm = RPM_MAX;
_piecewide_linear = true;
#else
_min_rpm = rpm_min->get();
_max_rpm = rpm_max->get();
_piecewide_linear = false;
_min_rpm = rpm_min->get();
_max_rpm = rpm_max->get();
_piecewide_linear = false;
#endif
// The pwm_gradient is the pwm duty cycle units per rpm
// _pwm_gradient = (_pwm_max_value - _pwm_min_value) / (_max_rpm - _min_rpm);
@@ -146,6 +140,7 @@ namespace Spindles {
pwm_value = map_uint32_t(rpm, _min_rpm, _max_rpm, _pwm_min_value, _pwm_max_value);
}
set_enable_pin(_current_state != SPINDLE_DISABLE);
set_output(pwm_value);
return 0;
@@ -155,7 +150,9 @@ namespace Spindles {
if (sys.abort)
return; // Block during abort.
if (state == SPINDLE_DISABLE) { // Halt or set spindle direction and rpm.
_current_state = state;
if (_current_state == SPINDLE_DISABLE) { // Halt or set spindle direction and rpm.
sys.spindle_speed = 0;
stop();
if (use_delays && (_current_state != state)) {
@@ -164,9 +161,9 @@ namespace Spindles {
//grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "SpinDown Done");
}
} else {
set_dir_pin(state == SPINDLE_ENABLE_CW);
set_dir_pin(_current_state == SPINDLE_ENABLE_CW);
set_rpm(rpm);
set_enable_pin(state != SPINDLE_DISABLE); // must be done after setting rpm for enable features to work
set_enable_pin(_current_state != SPINDLE_DISABLE); // must be done after setting rpm for enable features to work
if (use_delays && (_current_state != state)) {
//grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "SpinUp Start %d", rpm);
mc_dwell(spindle_delay_spinup->get());
@@ -230,11 +227,9 @@ namespace Spindles {
if (_off_with_zero_speed && sys.spindle_speed == 0)
enable = false;
#ifndef INVERT_SPINDLE_ENABLE_PIN
digitalWrite(_enable_pin, enable);
#else
digitalWrite(_enable_pin, !enable);
#endif
if (spindle_enable_invert->get())
enable = !enable;
digitalWrite(_enable_pin, enable);
}