Add Endstop Noise Filter
Co-Authored-By: ejtagle <ejtagle@hotmail.com>
This commit is contained in:
parent
e63113e6ad
commit
a971cacb06
@ -527,6 +527,23 @@
|
|||||||
// This will remove the need to poll the interrupt pins, saving many CPU cycles.
|
// This will remove the need to poll the interrupt pins, saving many CPU cycles.
|
||||||
//#define ENDSTOP_INTERRUPTS_FEATURE
|
//#define ENDSTOP_INTERRUPTS_FEATURE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endstop Noise Filter
|
||||||
|
*
|
||||||
|
* Enable this option if endstops falsely trigger due to noise.
|
||||||
|
* NOTE: Enabling this feature means adds an error of +/-0.2mm, so homing
|
||||||
|
* will end up at a slightly different position on each G28. This will also
|
||||||
|
* reduce accuracy of some bed probes.
|
||||||
|
* For mechanical switches, the better approach to reduce noise is to install
|
||||||
|
* a 100 nanofarads ceramic capacitor in parallel with the switch, making it
|
||||||
|
* essentially noise-proof without sacrificing accuracy.
|
||||||
|
* This option also increases MCU load when endstops or the probe are enabled.
|
||||||
|
* So this is not recommended. USE AT YOUR OWN RISK.
|
||||||
|
* (This feature is not required for common micro-switches mounted on PCBs
|
||||||
|
* based on the Makerbot design, since they already include the 100nF capacitor.)
|
||||||
|
*/
|
||||||
|
//#define ENDSTOP_NOISE_FILTER
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
//============================== Movement Settings ============================
|
//============================== Movement Settings ============================
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
|
@ -2224,7 +2224,7 @@ void clean_up_after_endstop_or_probe_move() {
|
|||||||
do_blocking_move_to_z(z, fr_mm_s);
|
do_blocking_move_to_z(z, fr_mm_s);
|
||||||
|
|
||||||
// Check to see if the probe was triggered
|
// Check to see if the probe was triggered
|
||||||
const bool probe_triggered = TEST(Endstops::endstop_hit_bits,
|
const bool probe_triggered = TEST(endstops.trigger_state(),
|
||||||
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
||||||
Z_MIN
|
Z_MIN
|
||||||
#else
|
#else
|
||||||
@ -3893,7 +3893,7 @@ inline void gcode_G4() {
|
|||||||
|
|
||||||
// If an endstop was not hit, then damage can occur if homing is continued.
|
// If an endstop was not hit, then damage can occur if homing is continued.
|
||||||
// This can occur if the delta height not set correctly.
|
// This can occur if the delta height not set correctly.
|
||||||
if (!(Endstops::endstop_hit_bits & (_BV(X_MAX) | _BV(Y_MAX) | _BV(Z_MAX)))) {
|
if (!(endstops.trigger_state() & (_BV(X_MAX) | _BV(Y_MAX) | _BV(Z_MAX)))) {
|
||||||
LCD_MESSAGEPGM(MSG_ERR_HOMING_FAILED);
|
LCD_MESSAGEPGM(MSG_ERR_HOMING_FAILED);
|
||||||
SERIAL_ERROR_START();
|
SERIAL_ERROR_START();
|
||||||
SERIAL_ERRORLNPGM(MSG_ERR_HOMING_FAILED);
|
SERIAL_ERRORLNPGM(MSG_ERR_HOMING_FAILED);
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TEST_ENDSTOP: test the current status of an endstop
|
// TEST_ENDSTOP: test the current status of an endstop
|
||||||
#define TEST_ENDSTOP(ENDSTOP) (TEST(current_endstop_bits, ENDSTOP))
|
#define TEST_ENDSTOP(ENDSTOP) (TEST(live_state, ENDSTOP))
|
||||||
|
|
||||||
#if HAS_BED_PROBE
|
#if HAS_BED_PROBE
|
||||||
#define ENDSTOPS_ENABLED (endstops.enabled || endstops.z_probe_enabled)
|
#define ENDSTOPS_ENABLED (endstops.enabled || endstops.z_probe_enabled)
|
||||||
@ -49,9 +49,14 @@ Endstops endstops;
|
|||||||
// public:
|
// public:
|
||||||
|
|
||||||
bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.load()
|
bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.load()
|
||||||
volatile uint8_t Endstops::endstop_hit_bits; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value
|
volatile uint8_t Endstops::hit_state;
|
||||||
|
|
||||||
Endstops::esbits_t Endstops::current_endstop_bits = 0;
|
Endstops::esbits_t Endstops::live_state = 0;
|
||||||
|
#if ENABLED(ENDSTOP_NOISE_FILTER)
|
||||||
|
Endstops::esbits_t Endstops::old_live_state,
|
||||||
|
Endstops::validated_live_state;
|
||||||
|
uint8_t Endstops::endstop_poll_count;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAS_BED_PROBE
|
#if HAS_BED_PROBE
|
||||||
volatile bool Endstops::z_probe_enabled = false;
|
volatile bool Endstops::z_probe_enabled = false;
|
||||||
@ -203,7 +208,7 @@ void Endstops::poll() {
|
|||||||
endstops.run_monitor(); // report changes in endstop status
|
endstops.run_monitor(); // report changes in endstop status
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DISABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
#if DISABLED(ENDSTOP_INTERRUPTS_FEATURE) || ENABLED(ENDSTOP_NOISE_FILTER)
|
||||||
if (ENDSTOPS_ENABLED) endstops.update();
|
if (ENDSTOPS_ENABLED) endstops.update();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -237,7 +242,7 @@ void Endstops::not_homing() {
|
|||||||
|
|
||||||
// Clear endstops (i.e., they were hit intentionally) to suppress the report
|
// Clear endstops (i.e., they were hit intentionally) to suppress the report
|
||||||
void Endstops::hit_on_purpose() {
|
void Endstops::hit_on_purpose() {
|
||||||
endstop_hit_bits = 0;
|
hit_state = 0;
|
||||||
|
|
||||||
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
||||||
if (enabled) endstops.update(); // If enabling, update state now
|
if (enabled) endstops.update(); // If enabling, update state now
|
||||||
@ -266,7 +271,7 @@ void Endstops::hit_on_purpose() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Endstops::report_state() {
|
void Endstops::report_state() {
|
||||||
if (endstop_hit_bits) {
|
if (hit_state) {
|
||||||
#if ENABLED(ULTRA_LCD)
|
#if ENABLED(ULTRA_LCD)
|
||||||
char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' ';
|
char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' ';
|
||||||
#define _SET_STOP_CHAR(A,C) (chr## A = C)
|
#define _SET_STOP_CHAR(A,C) (chr## A = C)
|
||||||
@ -279,7 +284,7 @@ void Endstops::report_state() {
|
|||||||
_SET_STOP_CHAR(A,C); }while(0)
|
_SET_STOP_CHAR(A,C); }while(0)
|
||||||
|
|
||||||
#define _ENDSTOP_HIT_TEST(A,C) \
|
#define _ENDSTOP_HIT_TEST(A,C) \
|
||||||
if (TEST(endstop_hit_bits, A ##_MIN) || TEST(endstop_hit_bits, A ##_MAX)) \
|
if (TEST(hit_state, A ##_MIN) || TEST(hit_state, A ##_MAX)) \
|
||||||
_ENDSTOP_HIT_ECHO(A,C)
|
_ENDSTOP_HIT_ECHO(A,C)
|
||||||
|
|
||||||
#define ENDSTOP_HIT_TEST_X() _ENDSTOP_HIT_TEST(X,'X')
|
#define ENDSTOP_HIT_TEST_X() _ENDSTOP_HIT_TEST(X,'X')
|
||||||
@ -294,7 +299,7 @@ void Endstops::report_state() {
|
|||||||
|
|
||||||
#if ENABLED(Z_MIN_PROBE_ENDSTOP)
|
#if ENABLED(Z_MIN_PROBE_ENDSTOP)
|
||||||
#define P_AXIS Z_AXIS
|
#define P_AXIS Z_AXIS
|
||||||
if (TEST(endstop_hit_bits, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P');
|
if (TEST(hit_state, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P');
|
||||||
#endif
|
#endif
|
||||||
SERIAL_EOL();
|
SERIAL_EOL();
|
||||||
|
|
||||||
@ -370,69 +375,23 @@ void Endstops::M119() {
|
|||||||
// The following routines are called from an ISR context. It could be the temperature ISR, the
|
// The following routines are called from an ISR context. It could be the temperature ISR, the
|
||||||
// endstop ISR or the Stepper ISR.
|
// endstop ISR or the Stepper ISR.
|
||||||
|
|
||||||
#if ENABLED(X_DUAL_ENDSTOPS)
|
#define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
|
||||||
void Endstops::test_dual_x_endstops(const EndstopEnum es1, const EndstopEnum es2) {
|
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
|
||||||
const byte x_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for X, bit 1 for X2
|
#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
|
||||||
if (x_test && stepper.movement_non_null(X_AXIS)) {
|
|
||||||
SBI(endstop_hit_bits, X_MIN);
|
|
||||||
if (!stepper.performing_homing || (x_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
|
|
||||||
stepper.quick_stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if ENABLED(Y_DUAL_ENDSTOPS)
|
|
||||||
void Endstops::test_dual_y_endstops(const EndstopEnum es1, const EndstopEnum es2) {
|
|
||||||
const byte y_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for Y, bit 1 for Y2
|
|
||||||
if (y_test && stepper.movement_non_null(Y_AXIS)) {
|
|
||||||
SBI(endstop_hit_bits, Y_MIN);
|
|
||||||
if (!stepper.performing_homing || (y_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
|
|
||||||
stepper.quick_stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if ENABLED(Z_DUAL_ENDSTOPS)
|
|
||||||
void Endstops::test_dual_z_endstops(const EndstopEnum es1, const EndstopEnum es2) {
|
|
||||||
const byte z_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for Z, bit 1 for Z2
|
|
||||||
if (z_test && stepper.movement_non_null(Z_AXIS)) {
|
|
||||||
SBI(endstop_hit_bits, Z_MIN);
|
|
||||||
if (!stepper.performing_homing || (z_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
|
|
||||||
stepper.quick_stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Check endstops - Could be called from ISR!
|
// Check endstops - Could be called from ISR!
|
||||||
void Endstops::update() {
|
void Endstops::update() {
|
||||||
|
|
||||||
#define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
|
|
||||||
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
|
|
||||||
#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
|
|
||||||
#define _ENDSTOP_HIT(AXIS, MINMAX) SBI(endstop_hit_bits, _ENDSTOP(AXIS, MINMAX))
|
|
||||||
|
|
||||||
#define SET_BIT(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
|
#define SET_BIT(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
|
||||||
// UPDATE_ENDSTOP_BIT: set the current endstop bits for an endstop to its status
|
// UPDATE_ENDSTOP_BIT: set the current endstop bits for an endstop to its status
|
||||||
#define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT(current_endstop_bits, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
|
#define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
|
||||||
// COPY_BIT: copy the value of SRC_BIT to DST_BIT in DST
|
// COPY_BIT: copy the value of SRC_BIT to DST_BIT in DST
|
||||||
#define COPY_BIT(DST, SRC_BIT, DST_BIT) SET_BIT(DST, DST_BIT, TEST(DST, SRC_BIT))
|
#define COPY_BIT(DST, SRC_BIT, DST_BIT) SET_BIT(DST, DST_BIT, TEST(DST, SRC_BIT))
|
||||||
|
|
||||||
#define UPDATE_ENDSTOP(AXIS,MINMAX) do { \
|
|
||||||
UPDATE_ENDSTOP_BIT(AXIS, MINMAX); \
|
|
||||||
if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX))) { \
|
|
||||||
_ENDSTOP_HIT(AXIS, MINMAX); \
|
|
||||||
planner.endstop_triggered(_AXIS(AXIS)); \
|
|
||||||
} \
|
|
||||||
}while(0)
|
|
||||||
|
|
||||||
#if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ)
|
#if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ)
|
||||||
// If G38 command is active check Z_MIN_PROBE for ALL movement
|
// If G38 command is active check Z_MIN_PROBE for ALL movement
|
||||||
if (G38_move) {
|
if (G38_move) {
|
||||||
UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
|
UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
|
||||||
if (TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE))) {
|
|
||||||
if (stepper.movement_non_null(_AXIS(X))) { _ENDSTOP_HIT(X, MIN); planner.endstop_triggered(_AXIS(X)); }
|
|
||||||
else if (stepper.movement_non_null(_AXIS(Y))) { _ENDSTOP_HIT(Y, MIN); planner.endstop_triggered(_AXIS(Y)); }
|
|
||||||
else if (stepper.movement_non_null(_AXIS(Z))) { _ENDSTOP_HIT(Z, MIN); planner.endstop_triggered(_AXIS(Z)); }
|
|
||||||
G38_endstop_hit = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -526,11 +485,10 @@ void Endstops::update() {
|
|||||||
#if HAS_X2_MIN
|
#if HAS_X2_MIN
|
||||||
UPDATE_ENDSTOP_BIT(X2, MIN);
|
UPDATE_ENDSTOP_BIT(X2, MIN);
|
||||||
#else
|
#else
|
||||||
COPY_BIT(current_endstop_bits, X_MIN, X2_MIN);
|
COPY_BIT(live_state, X_MIN, X2_MIN);
|
||||||
#endif
|
#endif
|
||||||
test_dual_x_endstops(X_MIN, X2_MIN);
|
|
||||||
#else
|
#else
|
||||||
if (X_MIN_TEST) UPDATE_ENDSTOP(X, MIN);
|
if (X_MIN_TEST) UPDATE_ENDSTOP_BIT(X, MIN);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -541,11 +499,10 @@ void Endstops::update() {
|
|||||||
#if HAS_X2_MAX
|
#if HAS_X2_MAX
|
||||||
UPDATE_ENDSTOP_BIT(X2, MAX);
|
UPDATE_ENDSTOP_BIT(X2, MAX);
|
||||||
#else
|
#else
|
||||||
COPY_BIT(current_endstop_bits, X_MAX, X2_MAX);
|
COPY_BIT(live_state, X_MAX, X2_MAX);
|
||||||
#endif
|
#endif
|
||||||
test_dual_x_endstops(X_MAX, X2_MAX);
|
|
||||||
#else
|
#else
|
||||||
if (X_MAX_TEST) UPDATE_ENDSTOP(X, MAX);
|
if (X_MAX_TEST) UPDATE_ENDSTOP_BIT(X, MAX);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -559,11 +516,10 @@ void Endstops::update() {
|
|||||||
#if HAS_Y2_MIN
|
#if HAS_Y2_MIN
|
||||||
UPDATE_ENDSTOP_BIT(Y2, MIN);
|
UPDATE_ENDSTOP_BIT(Y2, MIN);
|
||||||
#else
|
#else
|
||||||
COPY_BIT(current_endstop_bits, Y_MIN, Y2_MIN);
|
COPY_BIT(live_state, Y_MIN, Y2_MIN);
|
||||||
#endif
|
#endif
|
||||||
test_dual_y_endstops(Y_MIN, Y2_MIN);
|
|
||||||
#else
|
#else
|
||||||
UPDATE_ENDSTOP(Y, MIN);
|
UPDATE_ENDSTOP_BIT(Y, MIN);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -574,11 +530,10 @@ void Endstops::update() {
|
|||||||
#if HAS_Y2_MAX
|
#if HAS_Y2_MAX
|
||||||
UPDATE_ENDSTOP_BIT(Y2, MAX);
|
UPDATE_ENDSTOP_BIT(Y2, MAX);
|
||||||
#else
|
#else
|
||||||
COPY_BIT(current_endstop_bits, Y_MAX, Y2_MAX);
|
COPY_BIT(live_state, Y_MAX, Y2_MAX);
|
||||||
#endif
|
#endif
|
||||||
test_dual_y_endstops(Y_MAX, Y2_MAX);
|
|
||||||
#else
|
#else
|
||||||
UPDATE_ENDSTOP(Y, MAX);
|
UPDATE_ENDSTOP_BIT(Y, MAX);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -592,14 +547,13 @@ void Endstops::update() {
|
|||||||
#if HAS_Z2_MIN
|
#if HAS_Z2_MIN
|
||||||
UPDATE_ENDSTOP_BIT(Z2, MIN);
|
UPDATE_ENDSTOP_BIT(Z2, MIN);
|
||||||
#else
|
#else
|
||||||
COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN);
|
COPY_BIT(live_state, Z_MIN, Z2_MIN);
|
||||||
#endif
|
#endif
|
||||||
test_dual_z_endstops(Z_MIN, Z2_MIN);
|
|
||||||
#else
|
#else
|
||||||
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
||||||
if (z_probe_enabled) UPDATE_ENDSTOP(Z, MIN);
|
if (z_probe_enabled) UPDATE_ENDSTOP_BIT(Z, MIN);
|
||||||
#else
|
#else
|
||||||
UPDATE_ENDSTOP(Z, MIN);
|
UPDATE_ENDSTOP_BIT(Z, MIN);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -607,8 +561,7 @@ void Endstops::update() {
|
|||||||
// When closing the gap check the enabled probe
|
// When closing the gap check the enabled probe
|
||||||
#if ENABLED(Z_MIN_PROBE_ENDSTOP)
|
#if ENABLED(Z_MIN_PROBE_ENDSTOP)
|
||||||
if (z_probe_enabled) {
|
if (z_probe_enabled) {
|
||||||
UPDATE_ENDSTOP(Z, MIN_PROBE);
|
UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
|
||||||
if (TEST_ENDSTOP(Z_MIN_PROBE)) SBI(endstop_hit_bits, Z_MIN_PROBE);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -620,13 +573,149 @@ void Endstops::update() {
|
|||||||
#if HAS_Z2_MAX
|
#if HAS_Z2_MAX
|
||||||
UPDATE_ENDSTOP_BIT(Z2, MAX);
|
UPDATE_ENDSTOP_BIT(Z2, MAX);
|
||||||
#else
|
#else
|
||||||
COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX);
|
COPY_BIT(live_state, Z_MAX, Z2_MAX);
|
||||||
#endif
|
#endif
|
||||||
test_dual_z_endstops(Z_MAX, Z2_MAX);
|
|
||||||
// If this pin is not hijacked for the bed probe
|
// If this pin is not hijacked for the bed probe
|
||||||
// then it belongs to the Z endstop
|
// then it belongs to the Z endstop
|
||||||
#elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
|
#elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
|
||||||
UPDATE_ENDSTOP(Z, MAX);
|
UPDATE_ENDSTOP_BIT(Z, MAX);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// All endstops were updated.
|
||||||
|
#if ENABLED(ENDSTOP_NOISE_FILTER)
|
||||||
|
if (old_live_state != live_state) { // We detected a change. Reinit the timeout
|
||||||
|
/**
|
||||||
|
* Filtering out noise on endstops requires a delayed decision. Let's assume, due to noise,
|
||||||
|
* that 50% of endstop signal samples are good and 50% are bad (assuming normal distribution
|
||||||
|
* of random noise). Then the first sample has a 50% chance to be good or bad. The 2nd sample
|
||||||
|
* also has a 50% chance to be good or bad. The chances of 2 samples both being bad becomes
|
||||||
|
* 50% of 50%, or 25%. That was the previous implementation of Marlin endstop handling. It
|
||||||
|
* reduces chances of bad readings in half, at the cost of 1 extra sample period, but chances
|
||||||
|
* still exist. The only way to reduce them further is to increase the number of samples.
|
||||||
|
* To reduce the chance to 1% (1/128th) requires 7 samples (adding 7ms of delay).
|
||||||
|
*/
|
||||||
|
endstop_poll_count = 7;
|
||||||
|
old_live_state = live_state;
|
||||||
|
}
|
||||||
|
else if (endstop_poll_count && !--endstop_poll_count)
|
||||||
|
validated_live_state = live_state;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
// Lets accept the new endstop values as valid - We assume hardware filtering of lines
|
||||||
|
esbits_t validated_live_state = live_state;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Endstop readings are validated in validated_live_state
|
||||||
|
|
||||||
|
// Test the current status of an endstop
|
||||||
|
#define TEST_ENDSTOP(ENDSTOP) (TEST(validated_live_state, ENDSTOP))
|
||||||
|
|
||||||
|
// Record endstop was hit
|
||||||
|
#define _ENDSTOP_HIT(AXIS, MINMAX) SBI(hit_state, _ENDSTOP(AXIS, MINMAX))
|
||||||
|
|
||||||
|
// Call the endstop triggered routine for single endstops
|
||||||
|
#define PROCESS_ENDSTOP(AXIS,MINMAX) do { \
|
||||||
|
if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX))) { \
|
||||||
|
_ENDSTOP_HIT(AXIS, MINMAX); \
|
||||||
|
planner.endstop_triggered(_AXIS(AXIS)); \
|
||||||
|
} \
|
||||||
|
}while(0)
|
||||||
|
|
||||||
|
// Call the endstop triggered routine for single endstops
|
||||||
|
#define PROCESS_DUAL_ENDSTOP(AXIS1, AXIS2, MINMAX) do { \
|
||||||
|
if (TEST_ENDSTOP(_ENDSTOP(AXIS1, MINMAX)) || TEST_ENDSTOP(_ENDSTOP(AXIS2, MINMAX))) { \
|
||||||
|
_ENDSTOP_HIT(AXIS1, MINMAX); \
|
||||||
|
planner.endstop_triggered(_AXIS(AXIS1)); \
|
||||||
|
} \
|
||||||
|
}while(0)
|
||||||
|
|
||||||
|
#if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ)
|
||||||
|
// If G38 command is active check Z_MIN_PROBE for ALL movement
|
||||||
|
if (G38_move) {
|
||||||
|
if (TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE))) {
|
||||||
|
if (stepper.movement_non_null(_AXIS(X))) { _ENDSTOP_HIT(X, MIN); planner.endstop_triggered(_AXIS(X)); }
|
||||||
|
else if (stepper.movement_non_null(_AXIS(Y))) { _ENDSTOP_HIT(Y, MIN); planner.endstop_triggered(_AXIS(Y)); }
|
||||||
|
else if (stepper.movement_non_null(_AXIS(Z))) { _ENDSTOP_HIT(Z, MIN); planner.endstop_triggered(_AXIS(Z)); }
|
||||||
|
G38_endstop_hit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Now, we must signal, after validation, if an endstop limit is pressed or not
|
||||||
|
if (X_MOVE_TEST) {
|
||||||
|
if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
|
||||||
|
#if HAS_X_MIN
|
||||||
|
#if ENABLED(X_DUAL_ENDSTOPS)
|
||||||
|
PROCESS_DUAL_ENDSTOP(X, X2, MIN);
|
||||||
|
#else
|
||||||
|
if (X_MIN_TEST) PROCESS_ENDSTOP(X, MIN);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else { // +direction
|
||||||
|
#if HAS_X_MAX
|
||||||
|
#if ENABLED(X_DUAL_ENDSTOPS)
|
||||||
|
PROCESS_DUAL_ENDSTOP(X, X2, MAX);
|
||||||
|
#else
|
||||||
|
if (X_MAX_TEST) PROCESS_ENDSTOP(X, MAX);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Y_MOVE_TEST) {
|
||||||
|
if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
|
||||||
|
#if HAS_Y_MIN
|
||||||
|
#if ENABLED(Y_DUAL_ENDSTOPS)
|
||||||
|
PROCESS_DUAL_ENDSTOP(Y, Y2, MIN);
|
||||||
|
#else
|
||||||
|
PROCESS_ENDSTOP(Y, MIN);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else { // +direction
|
||||||
|
#if HAS_Y_MAX
|
||||||
|
#if ENABLED(Y_DUAL_ENDSTOPS)
|
||||||
|
PROCESS_DUAL_ENDSTOP(Y, Y2, MAX);
|
||||||
|
#else
|
||||||
|
PROCESS_ENDSTOP(Y, MAX);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Z_MOVE_TEST) {
|
||||||
|
if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
|
||||||
|
#if HAS_Z_MIN
|
||||||
|
#if ENABLED(Z_DUAL_ENDSTOPS)
|
||||||
|
PROCESS_DUAL_ENDSTOP(Z, Z2, MIN);
|
||||||
|
#else
|
||||||
|
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
||||||
|
if (z_probe_enabled) PROCESS_ENDSTOP(Z, MIN);
|
||||||
|
#else
|
||||||
|
PROCESS_ENDSTOP(Z, MIN);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// When closing the gap check the enabled probe
|
||||||
|
#if ENABLED(Z_MIN_PROBE_ENDSTOP)
|
||||||
|
if (z_probe_enabled) PROCESS_ENDSTOP(Z, MIN_PROBE);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else { // Z +direction. Gantry up, bed down.
|
||||||
|
#if HAS_Z_MAX
|
||||||
|
#if ENABLED(Z_DUAL_ENDSTOPS)
|
||||||
|
PROCESS_DUAL_ENDSTOP(Z, Z2, MAX);
|
||||||
|
#elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
|
||||||
|
// If this pin is not hijacked for the bed probe
|
||||||
|
// then it belongs to the Z endstop
|
||||||
|
PROCESS_ENDSTOP(Z, MAX);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,6 @@ class Endstops {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
static bool enabled, enabled_globally;
|
static bool enabled, enabled_globally;
|
||||||
static volatile uint8_t endstop_hit_bits; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value
|
|
||||||
|
|
||||||
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
|
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
|
||||||
typedef uint16_t esbits_t;
|
typedef uint16_t esbits_t;
|
||||||
@ -64,11 +63,19 @@ class Endstops {
|
|||||||
static float z_endstop_adj;
|
static float z_endstop_adj;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
typedef byte esbits_t;
|
typedef uint8_t esbits_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static esbits_t current_endstop_bits;
|
private:
|
||||||
|
static esbits_t live_state;
|
||||||
|
static volatile uint8_t hit_state; // Use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT index
|
||||||
|
#if ENABLED(ENDSTOP_NOISE_FILTER)
|
||||||
|
static esbits_t old_live_state, // Old endstop value for debouncing and denoising
|
||||||
|
validated_live_state; // The validated (accepted as true) endstop bits
|
||||||
|
static uint8_t endstop_poll_count; // Countdown from threshold for polling
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public:
|
||||||
Endstops() {};
|
Endstops() {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,6 +99,16 @@ class Endstops {
|
|||||||
*/
|
*/
|
||||||
static void update();
|
static void update();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Endstop hit state.
|
||||||
|
*/
|
||||||
|
FORCE_INLINE static uint8_t trigger_state() { return hit_state; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current endstops state
|
||||||
|
*/
|
||||||
|
FORCE_INLINE static esbits_t state() { return live_state; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print an error message reporting the position when the endstops were last hit.
|
* Print an error message reporting the position when the endstops were last hit.
|
||||||
*/
|
*/
|
||||||
@ -126,18 +143,6 @@ class Endstops {
|
|||||||
static void monitor();
|
static void monitor();
|
||||||
static void run_monitor();
|
static void run_monitor();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
#if ENABLED(X_DUAL_ENDSTOPS)
|
|
||||||
static void test_dual_x_endstops(const EndstopEnum es1, const EndstopEnum es2);
|
|
||||||
#endif
|
|
||||||
#if ENABLED(Y_DUAL_ENDSTOPS)
|
|
||||||
static void test_dual_y_endstops(const EndstopEnum es1, const EndstopEnum es2);
|
|
||||||
#endif
|
|
||||||
#if ENABLED(Z_DUAL_ENDSTOPS)
|
|
||||||
static void test_dual_z_endstops(const EndstopEnum es1, const EndstopEnum es2);
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Endstops endstops;
|
extern Endstops endstops;
|
||||||
|
@ -171,12 +171,12 @@ volatile int32_t Stepper::endstops_trigsteps[XYZ];
|
|||||||
#define DUAL_ENDSTOP_APPLY_STEP(A,V) \
|
#define DUAL_ENDSTOP_APPLY_STEP(A,V) \
|
||||||
if (performing_homing) { \
|
if (performing_homing) { \
|
||||||
if (A##_HOME_DIR < 0) { \
|
if (A##_HOME_DIR < 0) { \
|
||||||
if (!(TEST(endstops.current_endstop_bits, A##_MIN) && count_direction[_AXIS(A)] < 0) && !LOCKED_##A##_MOTOR) A##_STEP_WRITE(V); \
|
if (!(TEST(endstops.state(), A##_MIN) && count_direction[_AXIS(A)] < 0) && !LOCKED_##A##_MOTOR) A##_STEP_WRITE(V); \
|
||||||
if (!(TEST(endstops.current_endstop_bits, A##2_MIN) && count_direction[_AXIS(A)] < 0) && !LOCKED_##A##2_MOTOR) A##2_STEP_WRITE(V); \
|
if (!(TEST(endstops.state(), A##2_MIN) && count_direction[_AXIS(A)] < 0) && !LOCKED_##A##2_MOTOR) A##2_STEP_WRITE(V); \
|
||||||
} \
|
} \
|
||||||
else { \
|
else { \
|
||||||
if (!(TEST(endstops.current_endstop_bits, A##_MAX) && count_direction[_AXIS(A)] > 0) && !LOCKED_##A##_MOTOR) A##_STEP_WRITE(V); \
|
if (!(TEST(endstops.state(), A##_MAX) && count_direction[_AXIS(A)] > 0) && !LOCKED_##A##_MOTOR) A##_STEP_WRITE(V); \
|
||||||
if (!(TEST(endstops.current_endstop_bits, A##2_MAX) && count_direction[_AXIS(A)] > 0) && !LOCKED_##A##2_MOTOR) A##2_STEP_WRITE(V); \
|
if (!(TEST(endstops.state(), A##2_MAX) && count_direction[_AXIS(A)] > 0) && !LOCKED_##A##2_MOTOR) A##2_STEP_WRITE(V); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
else { \
|
else { \
|
||||||
|
@ -1695,71 +1695,71 @@ void Temperature::set_current_temp_raw() {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void endstop_monitor() {
|
void endstop_monitor() {
|
||||||
static uint16_t old_endstop_bits_local = 0;
|
static uint16_t old_live_state_local = 0;
|
||||||
static uint8_t local_LED_status = 0;
|
static uint8_t local_LED_status = 0;
|
||||||
uint16_t current_endstop_bits_local = 0;
|
uint16_t live_state_local = 0;
|
||||||
#if HAS_X_MIN
|
#if HAS_X_MIN
|
||||||
if (READ(X_MIN_PIN)) SBI(current_endstop_bits_local, X_MIN);
|
if (READ(X_MIN_PIN)) SBI(live_state_local, X_MIN);
|
||||||
#endif
|
#endif
|
||||||
#if HAS_X_MAX
|
#if HAS_X_MAX
|
||||||
if (READ(X_MAX_PIN)) SBI(current_endstop_bits_local, X_MAX);
|
if (READ(X_MAX_PIN)) SBI(live_state_local, X_MAX);
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Y_MIN
|
#if HAS_Y_MIN
|
||||||
if (READ(Y_MIN_PIN)) SBI(current_endstop_bits_local, Y_MIN);
|
if (READ(Y_MIN_PIN)) SBI(live_state_local, Y_MIN);
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Y_MAX
|
#if HAS_Y_MAX
|
||||||
if (READ(Y_MAX_PIN)) SBI(current_endstop_bits_local, Y_MAX);
|
if (READ(Y_MAX_PIN)) SBI(live_state_local, Y_MAX);
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Z_MIN
|
#if HAS_Z_MIN
|
||||||
if (READ(Z_MIN_PIN)) SBI(current_endstop_bits_local, Z_MIN);
|
if (READ(Z_MIN_PIN)) SBI(live_state_local, Z_MIN);
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Z_MAX
|
#if HAS_Z_MAX
|
||||||
if (READ(Z_MAX_PIN)) SBI(current_endstop_bits_local, Z_MAX);
|
if (READ(Z_MAX_PIN)) SBI(live_state_local, Z_MAX);
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Z_MIN_PROBE_PIN
|
#if HAS_Z_MIN_PROBE_PIN
|
||||||
if (READ(Z_MIN_PROBE_PIN)) SBI(current_endstop_bits_local, Z_MIN_PROBE);
|
if (READ(Z_MIN_PROBE_PIN)) SBI(live_state_local, Z_MIN_PROBE);
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Z2_MIN
|
#if HAS_Z2_MIN
|
||||||
if (READ(Z2_MIN_PIN)) SBI(current_endstop_bits_local, Z2_MIN);
|
if (READ(Z2_MIN_PIN)) SBI(live_state_local, Z2_MIN);
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Z2_MAX
|
#if HAS_Z2_MAX
|
||||||
if (READ(Z2_MAX_PIN)) SBI(current_endstop_bits_local, Z2_MAX);
|
if (READ(Z2_MAX_PIN)) SBI(live_state_local, Z2_MAX);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint16_t endstop_change = current_endstop_bits_local ^ old_endstop_bits_local;
|
uint16_t endstop_change = live_state_local ^ old_live_state_local;
|
||||||
|
|
||||||
if (endstop_change) {
|
if (endstop_change) {
|
||||||
#if HAS_X_MIN
|
#if HAS_X_MIN
|
||||||
if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR(" X_MIN:", !!TEST(current_endstop_bits_local, X_MIN));
|
if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR(" X_MIN:", !!TEST(live_state_local, X_MIN));
|
||||||
#endif
|
#endif
|
||||||
#if HAS_X_MAX
|
#if HAS_X_MAX
|
||||||
if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR(" X_MAX:", !!TEST(current_endstop_bits_local, X_MAX));
|
if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR(" X_MAX:", !!TEST(live_state_local, X_MAX));
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Y_MIN
|
#if HAS_Y_MIN
|
||||||
if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR(" Y_MIN:", !!TEST(current_endstop_bits_local, Y_MIN));
|
if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR(" Y_MIN:", !!TEST(live_state_local, Y_MIN));
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Y_MAX
|
#if HAS_Y_MAX
|
||||||
if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR(" Y_MAX:", !!TEST(current_endstop_bits_local, Y_MAX));
|
if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR(" Y_MAX:", !!TEST(live_state_local, Y_MAX));
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Z_MIN
|
#if HAS_Z_MIN
|
||||||
if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR(" Z_MIN:", !!TEST(current_endstop_bits_local, Z_MIN));
|
if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR(" Z_MIN:", !!TEST(live_state_local, Z_MIN));
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Z_MAX
|
#if HAS_Z_MAX
|
||||||
if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR(" Z_MAX:", !!TEST(current_endstop_bits_local, Z_MAX));
|
if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR(" Z_MAX:", !!TEST(live_state_local, Z_MAX));
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Z_MIN_PROBE_PIN
|
#if HAS_Z_MIN_PROBE_PIN
|
||||||
if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR(" PROBE:", !!TEST(current_endstop_bits_local, Z_MIN_PROBE));
|
if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR(" PROBE:", !!TEST(live_state_local, Z_MIN_PROBE));
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Z2_MIN
|
#if HAS_Z2_MIN
|
||||||
if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR(" Z2_MIN:", !!TEST(current_endstop_bits_local, Z2_MIN));
|
if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR(" Z2_MIN:", !!TEST(live_state_local, Z2_MIN));
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Z2_MAX
|
#if HAS_Z2_MAX
|
||||||
if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR(" Z2_MAX:", !!TEST(current_endstop_bits_local, Z2_MAX));
|
if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR(" Z2_MAX:", !!TEST(live_state_local, Z2_MAX));
|
||||||
#endif
|
#endif
|
||||||
SERIAL_PROTOCOLPGM("\n\n");
|
SERIAL_PROTOCOLPGM("\n\n");
|
||||||
analogWrite(LED_PIN, local_LED_status);
|
analogWrite(LED_PIN, local_LED_status);
|
||||||
local_LED_status ^= 255;
|
local_LED_status ^= 255;
|
||||||
old_endstop_bits_local = current_endstop_bits_local;
|
old_live_state_local = live_state_local;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // PINS_DEBUGGING
|
#endif // PINS_DEBUGGING
|
||||||
|
Loading…
Reference in New Issue
Block a user