Enable internal pullups for endstops on demand, only.

The binary size impact is moderate, like 18 bytes plus
4 bytes per endstop defined.

The story is a follows:

The endstop logic can be used to use a touch probe with PCB
milling. Connect the (conductive) PCB surface to GND, the
spindle/mill bit to the signal line, turn the internal pullups
on and there you go.

However, doing so with pullups always enabled and while milling
under (conductive) water showed polished mill and drill bits to
become matte after a few hours of usage. Obviously, this small
0.5 mA current from the pullup resistors going through the
rotating mill bit is sufficient to get some spark erosion going.
That's bad, as spark erosion happening also means tools become
dull faster than neccessary.

With this patch, pullups are turned on while being used, only,
so this sparc erosion should go away.
This commit is contained in:
Markus Hitter 2012-10-06 22:02:37 +02:00
parent 53049ac56e
commit 5d6de1761b
4 changed files with 64 additions and 30 deletions

3
dda.c
View File

@ -354,6 +354,8 @@ void dda_start(DDA *dda) {
psu_timeout = 0;
if (dda->z_delta)
z_enable();
if (dda->endstop_check)
endstops_on();
// set direction outputs
x_direction(dda->x_direction);
@ -636,6 +638,7 @@ void dda_step(DDA *dda) {
// TODO: If we stop axes individually, could we home two or more axes at the same time?
if (dda->endstop_check != 0x0 && endstop_not_done == 0x0) {
move_state.x_steps = move_state.y_steps = move_state.z_steps = move_state.e_steps = 0;
endstops_off();
// as we stop without ramping down, we have to re-init our ramping here
dda_init();
}

View File

@ -724,6 +724,8 @@ void process_gcode_command() {
//? --- M200: report endstop status ---
//? Report the current status of the endstops configured in the firmware to the host.
power_on();
endstops_on();
delay_ms(10); // allow the signal to stabilize
#if defined(X_MIN_PIN)
sersendf_P(PSTR("x_min:%d "), x_min());
#endif
@ -745,6 +747,7 @@ void process_gcode_command() {
#if !(defined(X_MIN_PIN) || defined(X_MAX_PIN) || defined(Y_MIN_PIN) || defined(Y_MAX_PIN) || defined(Z_MIN_PIN) || defined(Z_MAX_PIN))
sersendf_P(PSTR("no endstops defined"));
#endif
endstops_off();
break;
#ifdef DEBUG

View File

@ -72,19 +72,11 @@ void io_init(void) {
WRITE(X_DIR_PIN, 0); SET_OUTPUT(X_DIR_PIN);
#ifdef X_MIN_PIN
SET_INPUT(X_MIN_PIN);
#ifdef USE_INTERNAL_PULLUPS
WRITE(X_MIN_PIN, 1);
#else
WRITE(X_MIN_PIN, 0);
#endif
WRITE(X_MIN_PIN, 0); // pullup resistors off
#endif
#ifdef X_MAX_PIN
SET_INPUT(X_MAX_PIN);
#ifdef USE_INTERNAL_PULLUPS
WRITE(X_MAX_PIN, 1);
#else
WRITE(X_MAX_PIN, 0);
#endif
WRITE(X_MAX_PIN, 0); // pullup resistors off
#endif
// Y Stepper
@ -92,19 +84,11 @@ void io_init(void) {
WRITE(Y_DIR_PIN, 0); SET_OUTPUT(Y_DIR_PIN);
#ifdef Y_MIN_PIN
SET_INPUT(Y_MIN_PIN);
#ifdef USE_INTERNAL_PULLUPS
WRITE(Y_MIN_PIN, 1);
#else
WRITE(Y_MIN_PIN, 0);
#endif
WRITE(Y_MIN_PIN, 0); // pullup resistors off
#endif
#ifdef Y_MAX_PIN
SET_INPUT(Y_MAX_PIN);
#ifdef USE_INTERNAL_PULLUPS
WRITE(Y_MAX_PIN, 1);
#else
WRITE(Y_MAX_PIN, 0);
#endif
WRITE(Y_MAX_PIN, 0); // pullup resistors off
#endif
// Z Stepper
@ -114,19 +98,11 @@ void io_init(void) {
#endif
#ifdef Z_MIN_PIN
SET_INPUT(Z_MIN_PIN);
#ifdef USE_INTERNAL_PULLUPS
WRITE(Z_MIN_PIN, 1);
#else
WRITE(Z_MIN_PIN, 0);
#endif
WRITE(Z_MIN_PIN, 0); // pullup resistors off
#endif
#ifdef Z_MAX_PIN
SET_INPUT(Z_MAX_PIN);
#ifdef USE_INTERNAL_PULLUPS
WRITE(Z_MAX_PIN, 1);
#else
WRITE(Z_MAX_PIN, 0);
#endif
WRITE(Z_MAX_PIN, 0); // pullup resistors off
#endif
#if defined E_STEP_PIN && defined E_DIR_PIN

52
pinio.h
View File

@ -211,4 +211,56 @@ Stepper Enable Pins
#define e_disable() do { } while (0)
#endif
/*
Internal pullup resistors for endstops
*/
static void endstops_on(void) __attribute__ ((always_inline));
inline void endstops_on(void) {
#ifdef USE_INTERNAL_PULLUPS
#ifdef X_MIN_PIN
WRITE(X_MIN_PIN, 1);
#endif
#ifdef X_MAX_PIN
WRITE(X_MAX_PIN, 1);
#endif
#ifdef Y_MIN_PIN
WRITE(Y_MIN_PIN, 1);
#endif
#ifdef Y_MAX_PIN
WRITE(Y_MAX_PIN, 1);
#endif
#ifdef Z_MIN_PIN
WRITE(Z_MIN_PIN, 1);
#endif
#ifdef Z_MAX_PIN
WRITE(Z_MAX_PIN, 1);
#endif
#endif
}
static void endstops_off(void) __attribute__ ((always_inline));
inline void endstops_off(void) {
#ifdef USE_INTERNAL_PULLUPS
#ifdef X_MIN_PIN
WRITE(X_MIN_PIN, 0);
#endif
#ifdef X_MAX_PIN
WRITE(X_MAX_PIN, 0);
#endif
#ifdef Y_MIN_PIN
WRITE(Y_MIN_PIN, 0);
#endif
#ifdef Y_MAX_PIN
WRITE(Y_MAX_PIN, 0);
#endif
#ifdef Z_MIN_PIN
WRITE(Z_MIN_PIN, 0);
#endif
#ifdef Z_MAX_PIN
WRITE(Z_MAX_PIN, 0);
#endif
#endif
}
#endif /* _PINIO_H */