Skip to content

Commit

Permalink
Fixed homing fail alarm handling. Re-integrated software debouncing.
Browse files Browse the repository at this point in the history
- [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.
  • Loading branch information
chamnit committed Dec 20, 2016
1 parent d5ed3bd commit 864d130
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 28 deletions.
12 changes: 12 additions & 0 deletions doc/log/commit_log_v1.1.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions grbl/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion grbl/grbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <avr/io.h>
Expand Down
51 changes: 34 additions & 17 deletions grbl/limits.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<<WDIE))) { WDTCSR |= (1<<WDIE); } }
ISR(WDT_vect) // Watchdog timer ISR
{
WDTCSR &= ~(1<<WDIE); // Disable watchdog timer.
if (sys.state != STATE_ALARM) { // Ignore if already in alarm state.
if (!(sys_rt_exec_alarm)) {
// 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
}
}
}
}

#endif

// Homes the specified cycle axes, sets the machine position, and performs a pull-off motion after
// completing. Homing is a special motion case, which involves rapid uncontrolled stops to locate
Expand Down
5 changes: 3 additions & 2 deletions grbl/motion_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,9 @@ void mc_reset()
// violated, by which, all bets are off.
if ((sys.state & (STATE_CYCLE | STATE_HOMING | STATE_JOG)) ||
(sys.step_control & (STEP_CONTROL_EXECUTE_HOLD | STEP_CONTROL_EXECUTE_SYS_MOTION))) {
if (sys.state == STATE_HOMING) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_RESET); }
else { system_set_exec_alarm(EXEC_ALARM_ABORT_CYCLE); }
if (sys.state == STATE_HOMING) {
if (!sys_rt_exec_alarm) {system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_RESET); }
} else { system_set_exec_alarm(EXEC_ALARM_ABORT_CYCLE); }
st_go_idle(); // Force kill steppers. Position has likely been lost.
}
}
Expand Down
2 changes: 1 addition & 1 deletion grbl/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data)
uint8_t idx;

// Copy position data based on type of motion being planned.
if (block->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);
Expand Down
2 changes: 1 addition & 1 deletion grbl/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions grbl/report.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion grbl/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions grbl/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion grbl/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 864d130

Please sign in to comment.