Skip to content

Commit 864d130

Browse files
committed
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.
1 parent d5ed3bd commit 864d130

File tree

11 files changed

+66
-28
lines changed

11 files changed

+66
-28
lines changed

doc/log/commit_log_v1.1.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
----------------
2+
Date: 2016-12-18
3+
Author: Sonny Jeon
4+
Subject: Addressed optional PWM min value issue. Updated docs.
5+
6+
- [fix] Spindle PWM minimum value had some typos. Fixed the macros to
7+
compile correctly. Only effects users that enable SPINDLE_MINIMUM_PWM.
8+
The name changed to SPINDLE_PWM_MIN_VALUE for consistency sake.
9+
10+
- Updated the laser documentation.
11+
12+
113
----------------
214
Date: 2016-12-12
315
Author: Sonny Jeon

grbl/config.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,15 @@
454454
// #define RX_BUFFER_SIZE 128 // (1-254) Uncomment to override defaults in serial.h
455455
// #define TX_BUFFER_SIZE 100 // (1-254)
456456

457+
// A simple software debouncing feature for hard limit switches. When enabled, the interrupt
458+
// monitoring the hard limit switch pins will enable the Arduino's watchdog timer to re-check
459+
// the limit pin state after a delay of about 32msec. This can help with CNC machines with
460+
// problematic false triggering of their hard limit switches, but it WILL NOT fix issues with
461+
// electrical interference on the signal cables from external sources. It's recommended to first
462+
// use shielded signal cables with their shielding connected to ground (old USB/computer cables
463+
// work well and are cheap to find) and wire in a low-pass circuit into each limit pin.
464+
// #define ENABLE_SOFTWARE_DEBOUNCE // Default disabled. Uncomment to enable.
465+
457466
// Configures the position after a probing cycle during Grbl's check mode. Disabled sets
458467
// the position to the probe target, when enabled sets the position to the start position.
459468
// #define SET_CHECK_MODE_PROBE_TO_START // Default disabled. Uncomment to enable.

grbl/grbl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
// Grbl versioning system
2525
#define GRBL_VERSION "1.1e"
26-
#define GRBL_VERSION_BUILD "20161218"
26+
#define GRBL_VERSION_BUILD "20161219"
2727

2828
// Define standard libraries used by Grbl.
2929
#include <avr/io.h>

grbl/limits.c

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,46 @@ uint8_t limits_get_state()
9595
// homing cycles and will not respond correctly. Upon user request or need, there may be a
9696
// special pinout for an e-stop, but it is generally recommended to just directly connect
9797
// your e-stop switch to the Arduino reset pin, since it is the most correct way to do this.
98-
ISR(LIMIT_INT_vect) // DEFAULT: Limit pin change interrupt process.
99-
{
100-
// Ignore limit switches if already in an alarm state or in-process of executing an alarm.
101-
// When in the alarm state, Grbl should have been reset or will force a reset, so any pending
102-
// moves in the planner and serial buffers are all cleared and newly sent blocks will be
103-
// locked out until a homing cycle or a kill lock command. Allows the user to disable the hard
104-
// limit setting if their limits are constantly triggering after a reset and move their axes.
105-
if (sys.state != STATE_ALARM) {
106-
if (!(sys_rt_exec_alarm)) {
107-
#ifdef HARD_LIMIT_FORCE_STATE_CHECK
108-
// Check limit pin state.
98+
#ifndef ENABLE_SOFTWARE_DEBOUNCE
99+
ISR(LIMIT_INT_vect) // DEFAULT: Limit pin change interrupt process.
100+
{
101+
// Ignore limit switches if already in an alarm state or in-process of executing an alarm.
102+
// When in the alarm state, Grbl should have been reset or will force a reset, so any pending
103+
// moves in the planner and serial buffers are all cleared and newly sent blocks will be
104+
// locked out until a homing cycle or a kill lock command. Allows the user to disable the hard
105+
// limit setting if their limits are constantly triggering after a reset and move their axes.
106+
if (sys.state != STATE_ALARM) {
107+
if (!(sys_rt_exec_alarm)) {
108+
#ifdef HARD_LIMIT_FORCE_STATE_CHECK
109+
// Check limit pin state.
110+
if (limits_get_state()) {
111+
mc_reset(); // Initiate system kill.
112+
system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT); // Indicate hard limit critical event
113+
}
114+
#else
115+
mc_reset(); // Initiate system kill.
116+
system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT); // Indicate hard limit critical event
117+
#endif
118+
}
119+
}
120+
}
121+
#else // OPTIONAL: Software debounce limit pin routine.
122+
// Upon limit pin change, enable watchdog timer to create a short delay.
123+
ISR(LIMIT_INT_vect) { if (!(WDTCSR & (1<<WDIE))) { WDTCSR |= (1<<WDIE); } }
124+
ISR(WDT_vect) // Watchdog timer ISR
125+
{
126+
WDTCSR &= ~(1<<WDIE); // Disable watchdog timer.
127+
if (sys.state != STATE_ALARM) { // Ignore if already in alarm state.
128+
if (!(sys_rt_exec_alarm)) {
129+
// Check limit pin state.
109130
if (limits_get_state()) {
110131
mc_reset(); // Initiate system kill.
111132
system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT); // Indicate hard limit critical event
112133
}
113-
#else
114-
mc_reset(); // Initiate system kill.
115-
system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT); // Indicate hard limit critical event
116-
#endif
134+
}
117135
}
118136
}
119-
}
120-
137+
#endif
121138

122139
// Homes the specified cycle axes, sets the machine position, and performs a pull-off motion after
123140
// completing. Homing is a special motion case, which involves rapid uncontrolled stops to locate

grbl/motion_control.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,9 @@ void mc_reset()
359359
// violated, by which, all bets are off.
360360
if ((sys.state & (STATE_CYCLE | STATE_HOMING | STATE_JOG)) ||
361361
(sys.step_control & (STEP_CONTROL_EXECUTE_HOLD | STEP_CONTROL_EXECUTE_SYS_MOTION))) {
362-
if (sys.state == STATE_HOMING) { system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_RESET); }
363-
else { system_set_exec_alarm(EXEC_ALARM_ABORT_CYCLE); }
362+
if (sys.state == STATE_HOMING) {
363+
if (!sys_rt_exec_alarm) {system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_RESET); }
364+
} else { system_set_exec_alarm(EXEC_ALARM_ABORT_CYCLE); }
364365
st_go_idle(); // Force kill steppers. Position has likely been lost.
365366
}
366367
}

grbl/planner.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data)
331331
uint8_t idx;
332332

333333
// Copy position data based on type of motion being planned.
334-
if (block->condition & PL_COND_FLAG_SYSTEM_MOTION) {
334+
if (block->condition & PL_COND_FLAG_SYSTEM_MOTION) {
335335
#ifdef COREXY
336336
position_steps[X_AXIS] = system_convert_corexy_to_x_axis_steps(sys_position);
337337
position_steps[Y_AXIS] = system_convert_corexy_to_y_axis_steps(sys_position);

grbl/protocol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void protocol_exec_rt_system()
234234
// lost, continued streaming could cause a serious crash if by chance it gets executed.
235235
} while (bit_isfalse(sys_rt_exec_state,EXEC_RESET));
236236
}
237-
system_clear_exec_alarm_flag(0xFF); // Clear all alarm flags
237+
system_clear_exec_alarm(); // Clear alarm
238238
}
239239

240240
rt_exec = sys_rt_exec_state; // Copy volatile sys_rt_exec_state.

grbl/report.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ static void report_util_float_setting(uint8_t n, float val, uint8_t n_decimal) {
109109
// operation. Errors events can originate from the g-code parser, settings module, or asynchronously
110110
// from a critical error, such as a triggered hard limit. Interface should always monitor for these
111111
// responses.
112-
// NOTE: In REPORT_GUI_MODE, all error codes are greater than zero.
113112
void report_status_message(uint8_t status_code)
114113
{
115114
switch(status_code) {
@@ -123,7 +122,7 @@ void report_status_message(uint8_t status_code)
123122
}
124123

125124
// Prints alarm messages.
126-
void report_alarm_message(int8_t alarm_code)
125+
void report_alarm_message(uint8_t alarm_code)
127126
{
128127
printPgmString(PSTR("ALARM:"));
129128
print_uint8_base10(alarm_code);

grbl/report.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
void report_status_message(uint8_t status_code);
8787

8888
// Prints system alarm messages.
89-
void report_alarm_message(int8_t alarm_code);
89+
void report_alarm_message(uint8_t alarm_code);
9090

9191
// Prints miscellaneous feedback messages.
9292
void report_feedback_message(uint8_t message_code);

grbl/system.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,10 @@ void system_set_exec_alarm(uint8_t code) {
371371
SREG = sreg;
372372
}
373373

374-
void system_clear_exec_alarm_flag(uint8_t mask) {
374+
void system_clear_exec_alarm() {
375375
uint8_t sreg = SREG;
376376
cli();
377-
sys_rt_exec_alarm &= ~(mask);
377+
sys_rt_exec_alarm = 0;
378378
SREG = sreg;
379379
}
380380

0 commit comments

Comments
 (0)