diff --git a/Grbl_Esp32/src/Defaults.h b/Grbl_Esp32/src/Defaults.h index b31197de..91c9e396 100644 --- a/Grbl_Esp32/src/Defaults.h +++ b/Grbl_Esp32/src/Defaults.h @@ -42,6 +42,10 @@ # define DEFAULT_STEP_PULSE_MICROSECONDS 3 // $0 #endif +#ifndef DEFAULT_STEP_ENABLE_DELAY +# define DEFAULT_STEP_ENABLE_DELAY 0 +#endif + #ifndef DEFAULT_STEPPER_IDLE_LOCK_TIME # define DEFAULT_STEPPER_IDLE_LOCK_TIME 250 // $1 msec (0-254, 255 keeps steppers enabled) #endif diff --git a/Grbl_Esp32/src/MotionControl.cpp b/Grbl_Esp32/src/MotionControl.cpp index aa02fec1..5ea64cb2 100644 --- a/Grbl_Esp32/src/MotionControl.cpp +++ b/Grbl_Esp32/src/MotionControl.cpp @@ -184,8 +184,9 @@ void mc_arc(float* target, float cos_Ti; float r_axisi; uint16_t i; - uint8_t count = 0; - for (i = 1; i < segments; i++) { // Increment (segments-1). + uint8_t count = 0; + float original_feedrate = pl_data->feed_rate; // Kinematics may alter the feedrate, so save an original copy + for (i = 1; i < segments; i++) { // Increment (segments-1). if (count < N_ARC_CORRECTION) { // Apply vector rotation matrix. ~40 usec r_axisi = r_axis0 * sin_T + r_axis1 * cos_T; @@ -206,6 +207,7 @@ void mc_arc(float* target, position[axis_1] = center_axis1 + r_axis1; position[axis_linear] += linear_per_segment; #ifdef USE_KINEMATICS + pl_data->feed_rate = original_feedrate; // This restores the feedrate kinematics may have altered mc_line_kins(position, pl_data, previous_position); previous_position[axis_0] = position[axis_0]; previous_position[axis_1] = position[axis_1]; diff --git a/Grbl_Esp32/src/Motors/Motors.cpp b/Grbl_Esp32/src/Motors/Motors.cpp index fe7a9584..bedfcd0a 100644 --- a/Grbl_Esp32/src/Motors/Motors.cpp +++ b/Grbl_Esp32/src/Motors/Motors.cpp @@ -413,7 +413,19 @@ void init_motors() { } void motors_set_disable(bool disable, uint8_t mask) { - static bool previous_state = true; + static bool prev_disable = true; + static uint8_t prev_mask = 0; + + if ((disable == prev_disable) && (mask == prev_mask)) { + return; + } + + prev_disable = disable; + prev_mask = mask; + + if (step_enable_invert->get()) { + disable = !disable; // Apply pin invert. + } // now loop through all the motors to see if they can individually disable auto n_axis = number_axis->get(); @@ -425,11 +437,19 @@ void motors_set_disable(bool disable, uint8_t mask) { } } - // invert only inverts the global stepper disable pin. - if (step_enable_invert->get()) { - disable = !disable; // Apply pin invert. - } + // global disable. digitalWrite(STEPPERS_DISABLE_PIN, disable); + + // Add an optional delay for stepper drivers. that need time + // Some need time after the enable before they can step. + auto wait_disable_change = enable_delay_microseconds->get(); + if (wait_disable_change != 0) { + auto disable_start_time = esp_timer_get_time() + wait_disable_change; + + while ((esp_timer_get_time() - disable_start_time) < 0) { + NOP(); + } + } } void motors_read_settings() { diff --git a/Grbl_Esp32/src/SettingsDefinitions.cpp b/Grbl_Esp32/src/SettingsDefinitions.cpp index 1808e94f..8d0aecc2 100644 --- a/Grbl_Esp32/src/SettingsDefinitions.cpp +++ b/Grbl_Esp32/src/SettingsDefinitions.cpp @@ -10,6 +10,7 @@ StringSetting* build_info; IntSetting* pulse_microseconds; IntSetting* stepper_idle_lock_time; +IntSetting* enable_delay_microseconds; AxisMaskSetting* step_invert_mask; AxisMaskSetting* dir_invert_mask; @@ -399,6 +400,7 @@ void make_settings() { step_invert_mask = new AxisMaskSetting(GRBL, WG, "2", "Stepper/StepInvert", DEFAULT_STEPPING_INVERT_MASK, postMotorSetting); stepper_idle_lock_time = new IntSetting(GRBL, WG, "1", "Stepper/IdleTime", DEFAULT_STEPPER_IDLE_LOCK_TIME, 0, 255); pulse_microseconds = new IntSetting(GRBL, WG, "0", "Stepper/Pulse", DEFAULT_STEP_PULSE_MICROSECONDS, 3, 1000); + enable_delay_microseconds = new IntSetting(EXTENDED, WG, NULL, "Stepper/Enable/Delay", DEFAULT_STEP_ENABLE_DELAY, 0, 1000); // microseconds stallguard_debug_mask = new AxisMaskSetting(EXTENDED, WG, NULL, "Report/StallGuard", 0, postMotorSetting); diff --git a/Grbl_Esp32/src/SettingsDefinitions.h b/Grbl_Esp32/src/SettingsDefinitions.h index 0fe91de1..84c62367 100644 --- a/Grbl_Esp32/src/SettingsDefinitions.h +++ b/Grbl_Esp32/src/SettingsDefinitions.h @@ -18,6 +18,7 @@ extern StringSetting* build_info; extern IntSetting* pulse_microseconds; extern IntSetting* stepper_idle_lock_time; +extern IntSetting* enable_delay_microseconds; extern AxisMaskSetting* step_invert_mask; extern AxisMaskSetting* dir_invert_mask;