diff --git a/config.h.dist b/config.h.dist index 6b434f9..98f9fc0 100644 --- a/config.h.dist +++ b/config.h.dist @@ -183,6 +183,11 @@ #define STEPPER_ENABLE_PIN DIO9 +/* + If your endstops are inverted, change this to a zero +*/ +#define ENDSTOP_OK_VALUE 1 + /* * list of PWM-able pins and corresponding timers * timer1 is used for step timing so don't use OC1A/OC1B @@ -226,6 +231,14 @@ #define FAN_PIN DIO5 #define FAN_PWM OCR0B +/* + Define this to disable PID and use bang-bang instead. + If you do this, you must also comment out "HEATER_PWM" above. + Otherwise it won't work correctly. Using bang-bang takes MUCH less + space. +*/ +//#define BANG_BANG + // -------------------------------------------------------------------------- // you shouldn't need to edit anything below this line diff --git a/gcode_process.c b/gcode_process.c index add0d34..74e54d1 100644 --- a/gcode_process.c +++ b/gcode_process.c @@ -264,6 +264,7 @@ void process_gcode_command() { break; #ifdef HEATER_PIN + #ifndef BANG_BANG // M130- heater P factor case 130: if (next_target.seen_S) @@ -288,6 +289,7 @@ void process_gcode_command() { case 134: heater_save_settings(); break; + #endif /* BANG_BANG */ #endif /* HEATER_PIN */ // M190- power on diff --git a/heater.c b/heater.c index 819896a..c4bd7ce 100644 --- a/heater.c +++ b/heater.c @@ -1,6 +1,7 @@ #include "heater.h" #ifdef HEATER_PIN +#ifndef BANG_BANG #ifndef SIMULATION #include @@ -105,5 +106,12 @@ void heater_tick(int16_t current_temp, int16_t target_temp) { disable_heater(); #endif } - -#endif /* HEATER_PIN */ \ No newline at end of file +#else /* BANG_BANG */ +void heater_tick(int16_t current_temp, int16_t target_temp) { + if ( current_temp < target_temp ) + enable_heater(); + else + disable_heater(); +} +#endif /* BANG_BANG */ +#endif /* HEATER_PIN */ diff --git a/mendel.c b/mendel.c index cd54e8b..0520f58 100644 --- a/mendel.c +++ b/mendel.c @@ -36,15 +36,54 @@ void io_init(void) { // setup I/O pins WRITE(X_STEP_PIN, 0); SET_OUTPUT(X_STEP_PIN); WRITE(X_DIR_PIN, 0); SET_OUTPUT(X_DIR_PIN); - WRITE(X_MIN_PIN, 1); SET_INPUT(X_MIN_PIN); + #ifdef X_MIN_PIN + #if ENDSTOP_OK_VALUE == 0 + WRITE(X_MIN_PIN, 0); SET_INPUT(X_MIN_PIN); + #else + WRITE(X_MIN_PIN, 1); SET_INPUT(X_MIN_PIN); + #endif + #endif + #ifdef X_MAX_PIN + #if ENDSTOP_OK_VALUE == 0 + WRITE(X_MAX_PIN, 0); SET_INPUT(X_MAX_PIN); + #else + WRITE(X_MAX_PIN, 1); SET_INPUT(X_MAX_PIN); + #endif + #endif WRITE(Y_STEP_PIN, 0); SET_OUTPUT(Y_STEP_PIN); WRITE(Y_DIR_PIN, 0); SET_OUTPUT(Y_DIR_PIN); - WRITE(Y_MIN_PIN, 1); SET_INPUT(Y_MIN_PIN); + #ifdef Y_MIN_PIN + #if ENDSTOP_OK_VALUE == 0 + WRITE(Y_MIN_PIN, 0); SET_INPUT(Y_MIN_PIN); + #else + WRITE(Y_MIN_PIN, 1); SET_INPUT(Y_MIN_PIN); + #endif + #endif + #ifdef Y_MAX_PIN + #if ENDSTOP_OK_VALUE == 0 + WRITE(Y_MAX_PIN, 0); SET_INPUT(Y_MAX_PIN); + #else + WRITE(Y_MAX_PIN, 1); SET_INPUT(Y_MAX_PIN); + #endif + #endif WRITE(Z_STEP_PIN, 0); SET_OUTPUT(Z_STEP_PIN); WRITE(Z_DIR_PIN, 0); SET_OUTPUT(Z_DIR_PIN); - WRITE(Z_MIN_PIN, 1); SET_INPUT(Z_MIN_PIN); + #ifdef Z_MIN_PIN + #if ENDSTOP_OK_VALUE == 0 + WRITE(Z_MIN_PIN, 0); SET_INPUT(Z_MIN_PIN); + #else + WRITE(Z_MIN_PIN, 1); SET_INPUT(Z_MIN_PIN); + #endif + #endif + #ifdef Z_MAX_PIN + #if ENDSTOP_OK_VALUE == 0 + WRITE(Z_MAX_PIN, 0); SET_INPUT(Z_MAX_PIN); + #else + WRITE(Z_MAX_PIN, 1); SET_INPUT(Z_MAX_PIN); + #endif + #endif WRITE(E_STEP_PIN, 0); SET_OUTPUT(E_STEP_PIN); WRITE(E_DIR_PIN, 0); SET_OUTPUT(E_DIR_PIN); @@ -95,7 +134,11 @@ void init(void) { clock_setup(); // read PID settings from EEPROM + #ifdef HEATER_PIN + #ifndef BANG_BANG heater_init(); + #endif + #endif // set up default feedrate current_position.F = startpoint.F = next_target.target.F = SEARCH_FEEDRATE_Z;