From 947237fa46862f79e7b4c2893756cf68df085657 Mon Sep 17 00:00:00 2001 From: John Gilmore Date: Sat, 30 Oct 2010 11:35:34 -0600 Subject: [PATCH 1/2] Added bang-bang control definition. This completely removes the PID logic, leaving only bang-bang control. This saves quite a bit of code space. Enough that I can add debugging even on a atmega168. Quite handy! And some people (nophead) don't need PID control. --- config.h.dist | 8 ++++++++ gcode_process.c | 2 ++ heater.c | 12 ++++++++++-- mendel.c | 4 ++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/config.h.dist b/config.h.dist index 6b434f9..ce79327 100644 --- a/config.h.dist +++ b/config.h.dist @@ -226,6 +226,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..098de92 100644 --- a/mendel.c +++ b/mendel.c @@ -95,7 +95,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; From 98009a2780d572c8c3162fb144f6eade58784e25 Mon Sep 17 00:00:00 2001 From: John Gilmore Date: Sat, 30 Oct 2010 11:51:40 -0600 Subject: [PATCH 2/2] ifdef'd code for MIN endstops, compiles without This code will now compile correctly wether or not the MIN pins are defined. --- config.h.dist | 5 +++++ mendel.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/config.h.dist b/config.h.dist index ce79327..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 diff --git a/mendel.c b/mendel.c index 098de92..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);