From 864d1306b93285645599e33063c0805e6c8ff905 Mon Sep 17 00:00:00 2001 From: Sonny Jeon Date: Mon, 19 Dec 2016 22:18:23 -0700 Subject: [PATCH] Fixed homing fail alarm handling. Re-integrated software debouncing. - [bug] Fixed a homing fail issue, where the alarm was not being set right, not cleared correctly. It would report the wrong code and enter an infinite alarm loop. This was due to how alarm codes were altered a while back. Now updated and fixed to show the right codes. - [feature] Re-installed optional software debouncing for hard limit switches. By request. --- doc/log/commit_log_v1.1.txt | 12 +++++++++ grbl/config.h | 9 +++++++ grbl/grbl.h | 2 +- grbl/limits.c | 51 ++++++++++++++++++++++++------------- grbl/motion_control.c | 5 ++-- grbl/planner.c | 2 +- grbl/protocol.c | 2 +- grbl/report.c | 3 +-- grbl/report.h | 2 +- grbl/system.c | 4 +-- grbl/system.h | 2 +- 11 files changed, 66 insertions(+), 28 deletions(-) diff --git a/doc/log/commit_log_v1.1.txt b/doc/log/commit_log_v1.1.txt index dad0699..48a1260 100644 --- a/doc/log/commit_log_v1.1.txt +++ b/doc/log/commit_log_v1.1.txt @@ -1,3 +1,15 @@ +---------------- +Date: 2016-12-18 +Author: Sonny Jeon +Subject: Addressed optional PWM min value issue. Updated docs. + +- [fix] Spindle PWM minimum value had some typos. Fixed the macros to +compile correctly. Only effects users that enable SPINDLE_MINIMUM_PWM. +The name changed to SPINDLE_PWM_MIN_VALUE for consistency sake. + +- Updated the laser documentation. + + ---------------- Date: 2016-12-12 Author: Sonny Jeon diff --git a/grbl/config.h b/grbl/config.h index c4c4c4d..6697735 100644 --- a/grbl/config.h +++ b/grbl/config.h @@ -454,6 +454,15 @@ // #define RX_BUFFER_SIZE 128 // (1-254) Uncomment to override defaults in serial.h // #define TX_BUFFER_SIZE 100 // (1-254) +// A simple software debouncing feature for hard limit switches. When enabled, the interrupt +// monitoring the hard limit switch pins will enable the Arduino's watchdog timer to re-check +// the limit pin state after a delay of about 32msec. This can help with CNC machines with +// problematic false triggering of their hard limit switches, but it WILL NOT fix issues with +// electrical interference on the signal cables from external sources. It's recommended to first +// use shielded signal cables with their shielding connected to ground (old USB/computer cables +// work well and are cheap to find) and wire in a low-pass circuit into each limit pin. +// #define ENABLE_SOFTWARE_DEBOUNCE // Default disabled. Uncomment to enable. + // Configures the position after a probing cycle during Grbl's check mode. Disabled sets // the position to the probe target, when enabled sets the position to the start position. // #define SET_CHECK_MODE_PROBE_TO_START // Default disabled. Uncomment to enable. diff --git a/grbl/grbl.h b/grbl/grbl.h index 23b8d58..d23fd80 100644 --- a/grbl/grbl.h +++ b/grbl/grbl.h @@ -23,7 +23,7 @@ // Grbl versioning system #define GRBL_VERSION "1.1e" -#define GRBL_VERSION_BUILD "20161218" +#define GRBL_VERSION_BUILD "20161219" // Define standard libraries used by Grbl. #include diff --git a/grbl/limits.c b/grbl/limits.c index 7e64294..3cc2556 100644 --- a/grbl/limits.c +++ b/grbl/limits.c @@ -95,29 +95,46 @@ uint8_t limits_get_state() // homing cycles and will not respond correctly. Upon user request or need, there may be a // special pinout for an e-stop, but it is generally recommended to just directly connect // your e-stop switch to the Arduino reset pin, since it is the most correct way to do this. -ISR(LIMIT_INT_vect) // DEFAULT: Limit pin change interrupt process. -{ - // Ignore limit switches if already in an alarm state or in-process of executing an alarm. - // When in the alarm state, Grbl should have been reset or will force a reset, so any pending - // moves in the planner and serial buffers are all cleared and newly sent blocks will be - // locked out until a homing cycle or a kill lock command. Allows the user to disable the hard - // limit setting if their limits are constantly triggering after a reset and move their axes. - if (sys.state != STATE_ALARM) { - if (!(sys_rt_exec_alarm)) { - #ifdef HARD_LIMIT_FORCE_STATE_CHECK - // Check limit pin state. +#ifndef ENABLE_SOFTWARE_DEBOUNCE + ISR(LIMIT_INT_vect) // DEFAULT: Limit pin change interrupt process. + { + // Ignore limit switches if already in an alarm state or in-process of executing an alarm. + // When in the alarm state, Grbl should have been reset or will force a reset, so any pending + // moves in the planner and serial buffers are all cleared and newly sent blocks will be + // locked out until a homing cycle or a kill lock command. Allows the user to disable the hard + // limit setting if their limits are constantly triggering after a reset and move their axes. + if (sys.state != STATE_ALARM) { + if (!(sys_rt_exec_alarm)) { + #ifdef HARD_LIMIT_FORCE_STATE_CHECK + // Check limit pin state. + if (limits_get_state()) { + mc_reset(); // Initiate system kill. + system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT); // Indicate hard limit critical event + } + #else + mc_reset(); // Initiate system kill. + system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT); // Indicate hard limit critical event + #endif + } + } + } +#else // OPTIONAL: Software debounce limit pin routine. + // Upon limit pin change, enable watchdog timer to create a short delay. + ISR(LIMIT_INT_vect) { if (!(WDTCSR & (1<condition & PL_COND_FLAG_SYSTEM_MOTION) { + if (block->condition & PL_COND_FLAG_SYSTEM_MOTION) { #ifdef COREXY position_steps[X_AXIS] = system_convert_corexy_to_x_axis_steps(sys_position); position_steps[Y_AXIS] = system_convert_corexy_to_y_axis_steps(sys_position); diff --git a/grbl/protocol.c b/grbl/protocol.c index dda09a8..2d5b8d1 100644 --- a/grbl/protocol.c +++ b/grbl/protocol.c @@ -234,7 +234,7 @@ void protocol_exec_rt_system() // lost, continued streaming could cause a serious crash if by chance it gets executed. } while (bit_isfalse(sys_rt_exec_state,EXEC_RESET)); } - system_clear_exec_alarm_flag(0xFF); // Clear all alarm flags + system_clear_exec_alarm(); // Clear alarm } rt_exec = sys_rt_exec_state; // Copy volatile sys_rt_exec_state. diff --git a/grbl/report.c b/grbl/report.c index 54a53fd..7dd26af 100644 --- a/grbl/report.c +++ b/grbl/report.c @@ -109,7 +109,6 @@ static void report_util_float_setting(uint8_t n, float val, uint8_t n_decimal) { // operation. Errors events can originate from the g-code parser, settings module, or asynchronously // from a critical error, such as a triggered hard limit. Interface should always monitor for these // responses. -// NOTE: In REPORT_GUI_MODE, all error codes are greater than zero. void report_status_message(uint8_t status_code) { switch(status_code) { @@ -123,7 +122,7 @@ void report_status_message(uint8_t status_code) } // Prints alarm messages. -void report_alarm_message(int8_t alarm_code) +void report_alarm_message(uint8_t alarm_code) { printPgmString(PSTR("ALARM:")); print_uint8_base10(alarm_code); diff --git a/grbl/report.h b/grbl/report.h index 6488ed1..cdeacfa 100644 --- a/grbl/report.h +++ b/grbl/report.h @@ -86,7 +86,7 @@ void report_status_message(uint8_t status_code); // Prints system alarm messages. -void report_alarm_message(int8_t alarm_code); +void report_alarm_message(uint8_t alarm_code); // Prints miscellaneous feedback messages. void report_feedback_message(uint8_t message_code); diff --git a/grbl/system.c b/grbl/system.c index 14f56fd..d1665ff 100644 --- a/grbl/system.c +++ b/grbl/system.c @@ -371,10 +371,10 @@ void system_set_exec_alarm(uint8_t code) { SREG = sreg; } -void system_clear_exec_alarm_flag(uint8_t mask) { +void system_clear_exec_alarm() { uint8_t sreg = SREG; cli(); - sys_rt_exec_alarm &= ~(mask); + sys_rt_exec_alarm = 0; SREG = sreg; } diff --git a/grbl/system.h b/grbl/system.h index a4ca818..0cbea6b 100644 --- a/grbl/system.h +++ b/grbl/system.h @@ -195,7 +195,7 @@ uint8_t system_check_travel_limits(float *target); void system_set_exec_state_flag(uint8_t mask); void system_clear_exec_state_flag(uint8_t mask); void system_set_exec_alarm(uint8_t code); -void system_clear_exec_alarm_flag(uint8_t mask); +void system_clear_exec_alarm(); void system_set_exec_motion_override_flag(uint8_t mask); void system_set_exec_accessory_override_flag(uint8_t mask); void system_clear_exec_motion_overrides();