From 324c14943bdb58a26cf95574dc9b0d329bbe4027 Mon Sep 17 00:00:00 2001 From: Chris Roadfeldt Date: Sun, 29 Mar 2015 02:16:09 -0500 Subject: [PATCH] Bug fixes for Z_PROBE_AND_ENDSTOP. Code cleanup for Z_PROBE_AND_ENDSTOP. Added Z_PROBE_PIN to pins_RAMPS_13.h --- Marlin/Configuration.h | 3 +-- Marlin/Marlin_main.cpp | 9 +++++++-- Marlin/pins_RAMPS_13.h | 5 +++++ Marlin/stepper.cpp | 19 ++----------------- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 262b4e15b..b23864065 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -499,9 +499,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // As of 3-28-2015, there are NO Z Probe pins defined in any board config files. // Z_PROBE_PIN is for the signal pin only. RAMPS 1.3/1.4 boards may be able to use the 5V, Ground and the D32 pin in the Aux 4 section of the RAMPS board for the signal. // The D32 pin in Aux 4 on RAMPS maps to the Arduino D32 pin. The Z_PROBE_PIN is setting the pin to use on the Arduino. Since the D32 pin on the RAMPS maps to D32 on Arduino, this works. -// If you have RAMPS 1.3/1.4 and want to use the RAMPS D32 pin, set Z_PROBE_PIN to 32 and use ground and 5v next to it as needed. Check the RAMPS 1.3/1.4 pinout diagram for details. +// D32 is currently selected in the RAMPS 1.3/1.4 pin file. Update the pins.h file for your control board to make use of this. Not doing so nullifies Z_PROBE_AND_ENDSTOP // WARNING: Setting the wrong pin may have unexpected and disastrous outcomes. Use with caution and do your homework. - #define Z_PROBE_PIN -1 // Mechanical endstop with COM to ground and NC to Signal uses "false" here (most common setup). const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 7f8592b2c..87ec4792c 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1359,8 +1359,13 @@ static void retract_z_probe() { st_synchronize(); + #if defined(Z_PROBE_AND_ENDSTOP) + bool z_probe_endstop = (READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING); + if (z_probe_endstop) + #else bool z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); - if (!z_min_endstop) + if (z_min_endstop) + #endif { if (!Stopped) { @@ -3516,7 +3521,7 @@ inline void gcode_M119() { #endif #if defined(Z_PROBE_PIN) && Z_PROBE_PIN >-1 SERIAL_PROTOCOLPGM(MSG_Z_PROBE); - SERIALPROTOCOLLN(((READ(Z_PROBE_PIN)^72Z_PROBE_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); + SERIAL_PROTOCOLLN(((READ(Z_PROBE_PIN)^Z_PROBE_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); #endif } diff --git a/Marlin/pins_RAMPS_13.h b/Marlin/pins_RAMPS_13.h index ece70005b..4bd2bce46 100644 --- a/Marlin/pins_RAMPS_13.h +++ b/Marlin/pins_RAMPS_13.h @@ -62,6 +62,11 @@ #define FILWIDTH_PIN 5 #endif +#if defined(Z_PROBE_ANDENDSTOP) + // Define a pin to use as the signal pin on Arduino for the Z_PROBE endstop. + #define 32 +#endif + #if defined(FILAMENT_RUNOUT_SENSOR) // define digital pin 4 for the filament runout sensor. Use the RAMPS 1.4 digital input 4 on the servos connector #define FILRUNOUT_PIN 4 diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 4241111d7..c246e5e52 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -527,22 +527,15 @@ ISR(TIMER1_COMPA_vect) { #if defined(Z_PROBE_PIN) && Z_PROBE_PIN > -1 UPDATE_ENDSTOP(z, Z, probe, PROBE); - bool z_probe_endstop(READ(Z_PROBE_PIN) != Z_MIN_ENDSTOP_INVERTING); + z_probe_endstop=(READ(Z_PROBE_PIN) != Z_MIN_ENDSTOP_INVERTING); if(z_probe_endstop && old_z_probe_endstop) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstop_z_hit=true; // if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true"); - - - if (!(performing_homing)) //if not performing home - { - step_events_completed = current_block->step_event_count; - } } old_z_probe_endstop = z_probe_endstop; - old_z2_probe_endstop = z2_probe_endstop; #endif } } @@ -581,22 +574,14 @@ ISR(TIMER1_COMPA_vect) { #if defined(Z_PROBE_PIN) && Z_PROBE_PIN > -1 UPDATE_ENDSTOP(z, Z, probe, PROBE); - bool z_probe_endstop(READ(Z_PROBE_PIN) != Z_MAX_ENDSTOP_INVERTING); + z_probe_endstop=(READ(Z_PROBE_PIN) != Z_MAX_ENDSTOP_INVERTING); if(z_probe_endstop && old_z_probe_endstop) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstop_z_hit=true; - // if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true"); - - - if (!(performing_homing)) //if not performing home - { - step_events_completed = current_block->step_event_count; - } } old_z_probe_endstop = z_probe_endstop; - old_z2_probe_endstop = z2_probe_endstop; #endif } }