diff --git a/Makefile b/Makefile
index ea1ea61..ab8c9ec 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ CLOCK = 16000000
PROGRAMMER ?= -c avrisp2 -P usb
OBJECTS = main.o motion_control.o gcode.o spindle_control.o coolant_control.o serial.o \
protocol.o stepper.o eeprom.o settings.o planner.o nuts_bolts.o limits.o \
- print.o report.o system.o
+ print.o probe.o report.o system.o
# FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m
FUSES = -U hfuse:w:0xd2:m -U lfuse:w:0xff:m
# update that line with this when programmer is back up:
diff --git a/cpu_map.h b/cpu_map.h
index 0538bbc..060135a 100644
--- a/cpu_map.h
+++ b/cpu_map.h
@@ -107,11 +107,18 @@
#define PIN_RESET 0 // Uno Analog Pin 0
#define PIN_FEED_HOLD 1 // Uno Analog Pin 1
#define PIN_CYCLE_START 2 // Uno Analog Pin 2
- #define PIN_PROBE 5 // Uno Analog Pin 5
#define PINOUT_INT PCIE1 // Pin change interrupt enable pin
#define PINOUT_INT_vect PCINT1_vect
#define PINOUT_PCMSK PCMSK1 // Pin change interrupt register
- #define PINOUT_MASK ((1<.
+*/
+
+#include "system.h"
+#include "probe.h"
+
+
+// Probe pin initialization routine.
+void probe_init()
+{
+ PROBE_DDR &= ~(PROBE_MASK); // Configure as input pins
+ PROBE_PORT |= PROBE_MASK; // Enable internal pull-up resistors. Normal high operation.
+}
+
+
+// Monitors probe pin state and records the system position when detected. Called by the
+// stepper ISR per ISR tick.
+// NOTE: This function must be extremely efficient as to not bog down the stepper ISR.
+void probe_state_monitor()
+{
+ if (sys.probe_state == PROBE_ACTIVE) {
+ if (!(PROBE_PIN & PROBE_MASK)) {
+ sys.probe_state = PROBE_OFF;
+ memcpy(sys.probe_position, sys.position, sizeof(float)*N_AXIS);
+ sys.execute |= EXEC_FEED_HOLD;
+ }
+ }
+}
diff --git a/probe.h b/probe.h
new file mode 100644
index 0000000..e5aef86
--- /dev/null
+++ b/probe.h
@@ -0,0 +1,36 @@
+/*
+ probe.h - code pertaining to probing methods
+ Part of Grbl
+
+ Copyright (c) 2014 Sungeun K. Jeon
+
+ Grbl is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Grbl is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Grbl. If not, see .
+*/
+
+#ifndef probe_h
+#define probe_h
+
+// Values that define the probing state machine.
+#define PROBE_OFF 0 // No probing. (Must be zero.)
+#define PROBE_ACTIVE 1 // Actively watching the input pin.
+
+
+// Probe pin initialization routine.
+void probe_init();
+
+// Monitors probe pin state and records the system position when detected. Called by the
+// stepper ISR per ISR tick.
+void probe_state_monitor();
+
+#endif
diff --git a/protocol.c b/protocol.c
index c8406d0..2bf7bcd 100644
--- a/protocol.c
+++ b/protocol.c
@@ -173,9 +173,11 @@ void protocol_execute_runtime()
if (rt_exec & (EXEC_ALARM | EXEC_CRIT_EVENT)) {
sys.state = STATE_ALARM; // Set system alarm state
- // Critical event. Only hard/soft limit errors currently qualify.
+ // Critical events. Hard/soft limit events identified by both critical event and alarm exec
+ // flags. Probe fail is identified by the critical event exec flag only.
if (rt_exec & EXEC_CRIT_EVENT) {
- report_alarm_message(ALARM_LIMIT_ERROR);
+ if (rt_exec & EXEC_ALARM) { report_alarm_message(ALARM_LIMIT_ERROR); }
+ else { report_alarm_message(ALARM_PROBE_FAIL); }
report_feedback_message(MESSAGE_CRITICAL_EVENT);
bit_false(sys.execute,EXEC_RESET); // Disable any existing reset
do {
diff --git a/report.c b/report.c
index bcecfc8..e766ee5 100644
--- a/report.c
+++ b/report.c
@@ -79,8 +79,6 @@ void report_status_message(uint8_t status_code)
printPgmString(PSTR("Homing not enabled")); break;
case STATUS_OVERFLOW:
printPgmString(PSTR("Line overflow")); break;
- case STATUS_PROBE_ERROR:
- printPgmString(PSTR("Probe error")); break;
}
printPgmString(PSTR("\r\n"));
}
@@ -95,8 +93,10 @@ void report_alarm_message(int8_t alarm_code)
printPgmString(PSTR("Hard/soft limit")); break;
case ALARM_ABORT_CYCLE:
printPgmString(PSTR("Abort during cycle")); break;
+ case ALARM_PROBE_FAIL:
+ printPgmString(PSTR("Probe fail")); break;
}
- printPgmString(PSTR(". MPos?\r\n"));
+ printPgmString(PSTR("\r\n"));
delay_ms(500); // Force delay to ensure message clears serial write buffer.
}
@@ -190,8 +190,28 @@ void report_grbl_settings() {
}
-// Prints gcode coordinate offset parameters
-void report_gcode_parameters()
+// Prints current probe parameters. Upon a probe command, these parameters are updated upon a
+// successful probe or upon a failed probe with the G38.3 without errors command (if supported).
+// These values are retained until Grbl is power-cycled, whereby they will be re-zeroed.
+void report_probe_parameters()
+{
+ uint8_t i;
+ float print_position[N_AXIS];
+
+ // Report in terms of machine position.
+ printPgmString(PSTR("[Probe:"));
+ for (i=0; i< N_AXIS; i++) {
+ print_position[i] = sys.probe_position[i]/settings.steps_per_mm[i];
+ if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) { print_position[i] *= INCH_PER_MM; }
+ printFloat(print_position[i]);
+ if (i < (N_AXIS-1)) { printPgmString(PSTR(",")); }
+ }
+ printPgmString(PSTR("]\r\n"));
+}
+
+
+// Prints Grbl NGC parameters (coordinate offsets, probing)
+void report_ngc_parameters()
{
float coord_data[N_AXIS];
uint8_t coord_select, i;
@@ -226,6 +246,7 @@ void report_gcode_parameters()
if (i < (N_AXIS-1)) { printPgmString(PSTR(",")); }
else { printPgmString(PSTR("]\r\n")); }
}
+ report_probe_parameters(); // Print probe parameters. Not persistent in memory.
}
@@ -353,7 +374,7 @@ void report_realtime_status()
if (i < (N_AXIS-1)) { printPgmString(PSTR(",")); }
}
-#ifdef USE_LINE_NUMBERS
+ #ifdef USE_LINE_NUMBERS
// Report current line number
printPgmString(PSTR(",Ln:"));
int32_t ln=0;
@@ -362,56 +383,7 @@ void report_realtime_status()
ln = pb->line_number;
}
printInteger(ln);
-#endif
-
- printPgmString(PSTR(">\r\n"));
-}
-
-// Prints real-time data. This function grabs a real-time snapshot of the stepper subprogram
- // and the actual location of the CNC machine. Users may change the following function to their
- // specific needs. It is kept separate from the "normal" report_realtime_status() to allow customization.
-void report_realtime_status_probe()
-{
- // **Under construction** Bare-bones status report. Provides real-time machine position relative to
- // the system power on location (0,0,0) and work coordinate position (G54 and G92 applied).
- uint8_t i;
- int32_t current_position[N_AXIS]; // Copy current state of the system position variable
- memcpy(current_position,sys.position,sizeof(sys.position));
- float print_position[N_AXIS];
-
- printPgmString(PSTR("line_number;
- }
- printInteger(ln);
-#endif
+ #endif
printPgmString(PSTR(">\r\n"));
}
diff --git a/report.h b/report.h
index f05bc42..91d7797 100644
--- a/report.h
+++ b/report.h
@@ -36,11 +36,11 @@
#define STATUS_ALARM_LOCK 12
#define STATUS_SOFT_LIMIT_ERROR 13
#define STATUS_OVERFLOW 14
-#define STATUS_PROBE_ERROR 15
// Define Grbl alarm codes. Less than zero to distinguish alarm error from status error.
#define ALARM_LIMIT_ERROR -1
#define ALARM_ABORT_CYCLE -2
+#define ALARM_PROBE_FAIL -3
// Define Grbl feedback message codes.
#define MESSAGE_CRITICAL_EVENT 1
@@ -70,13 +70,11 @@ void report_grbl_settings();
// Prints realtime status report
void report_realtime_status();
-// Prints realtime position status report at the end of a probe cycle
-// This is in leiu of saving the probe position to internal variables like an
-// EMC machine
-void report_realtime_status_probe();
+// Prints recorded probe position
+void report_probe_parameters();
-// Prints Grbl persistent coordinate parameters
-void report_gcode_parameters();
+// Prints Grbl NGC parameters (coordinate offsets, probe)
+void report_ngc_parameters();
// Prints current g-code parser mode state
void report_gcode_modes();
diff --git a/settings.h b/settings.h
index 3551ec2..62dfcfc 100644
--- a/settings.h
+++ b/settings.h
@@ -25,8 +25,8 @@
#include "system.h"
-#define GRBL_VERSION "0.9c"
-#define GRBL_VERSION_BUILD "20140215"
+#define GRBL_VERSION "0.9d"
+#define GRBL_VERSION_BUILD "20140228"
// Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl
// when firmware is upgraded. Always stored in byte 0 of eeprom
diff --git a/stepper.c b/stepper.c
index 370d798..58ec9c1 100644
--- a/stepper.c
+++ b/stepper.c
@@ -24,6 +24,7 @@
#include "stepper.h"
#include "settings.h"
#include "planner.h"
+#include "probe.h"
// Some useful constants.
@@ -282,12 +283,6 @@ ISR(TIMER1_COMPA_vect)
{
// SPINDLE_ENABLE_PORT ^= 1<