From 067c662510309a3c1841921d2c01e408d6311da4 Mon Sep 17 00:00:00 2001 From: "Lawrence Leung larryleungcal@yahoo.com" Date: Mon, 25 Jul 2011 00:51:01 -0700 Subject: add support for TEMP_RESIDENCY_TIME for M109 --- Sprinter/Configuration.h | 3 +++ Sprinter/Sprinter.pde | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index bbc2cfe..c1c4918 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -140,6 +140,9 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; // If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109 //#define WATCHPERIOD 5000 //5 seconds +// Wait this long after achieving target temperature on M109 before continuing with print (seconds) +#define TEMP_RESIDENCY_TIME 20 + //// The minimal temperature defines the temperature below which the heater will not be enabled #define MINTEMP 5 diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index dde302c..801f103 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -778,6 +778,23 @@ inline void process_commands() } manage_heater(); } + // wait extra time before letting the print continue + #ifdef TEMP_RESIDENCY_TIME + { + long residencyStart = millis(); + codenum = millis(); + while(millis()-residencyStart<(TEMP_RESIDENCY_TIME*1000)) { + if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. + { + Serial.print("T:"); + Serial.println( analog2temp(current_raw) ); + codenum = millis(); + } + manage_heater(); + } + } + #endif + break; case 190: // M190 - Wait bed for heater to reach target. #if TEMP_1_PIN > -1 -- cgit v1.2.1 From eb1c87fa7bf2e4bcc8b074775d88a6e767de2c29 Mon Sep 17 00:00:00 2001 From: "Lawrence Leung larryleungcal@yahoo.com" Date: Mon, 25 Jul 2011 00:55:42 -0700 Subject: Disable TEMP_RESIDENCY_TIME for default --- Sprinter/Configuration.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index c1c4918..8e8724c 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -16,12 +16,14 @@ // 2 is 200k thermistor // 3 is mendel-parts thermistor // 4 is 10k thermistor -#define THERMISTORHEATER 1 -#define THERMISTORBED 1 +// 5 is Ultimachine +// 6 is honeywell +#define THERMISTORHEATER 5 +#define THERMISTORBED 6 //// Calibration variables // X, Y, Z, E steps per unit - Metric Prusa Mendel with Wade extruder: -float axis_steps_per_unit[] = {80, 80, 3200/1.25,700}; +float axis_steps_per_unit[] = {32.37655, 32.37655, 642,144.31/2}; // Metric Prusa Mendel with Makergear geared stepper extruder: //float axis_steps_per_unit[] = {80,80,3200/1.25,1380}; @@ -36,7 +38,7 @@ const bool ENDSTOPS_INVERTING = false; //set to true to invert the logic of the #define BAUDRATE 115200 // Comment out (using // at the start of the line) to disable SD support: -#define SDSUPPORT 1 +//#define SDSUPPORT 1 //// ADVANCED SETTINGS - to tweak parameters @@ -101,7 +103,7 @@ long max_travel_acceleration_units_per_sq_second[] = {500,500,50,500}; // X, Y, // Machine UUID // This may be useful if you have multiple machines and wish to identify them by using the M115 command. // By default we set it to zeros. -char uuid[] = "00000000-0000-0000-0000-000000000000"; +char uuid[] = "00000000-0000-0000-0000-000000000123"; //// AD595 THERMOCOUPLE SUPPORT UNTESTED... USE WITH CAUTION!!!! @@ -119,7 +121,7 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; // How often should the heater check for new temp readings, in milliseconds #define HEATER_CHECK_INTERVAL 500 -#define BED_CHECK_INTERVAL 5000 +#define BED_CHECK_INTERVAL 2000 // Comment the following line to enable heat management during acceleration #define DISABLE_CHECK_DURING_ACC #ifndef DISABLE_CHECK_DURING_ACC @@ -141,7 +143,7 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; //#define WATCHPERIOD 5000 //5 seconds // Wait this long after achieving target temperature on M109 before continuing with print (seconds) -#define TEMP_RESIDENCY_TIME 20 +//#define TEMP_RESIDENCY_TIME 20 //// The minimal temperature defines the temperature below which the heater will not be enabled #define MINTEMP 5 @@ -150,7 +152,7 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; // When temperature exceeds max temp, your heater will be switched off. // This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure! // You should use MINTEMP for thermistor short/failure protection. -#define MAXTEMP 275 +#define MAXTEMP 250 // Select one of these only to define how the nozzle temp is read. #define HEATER_USES_THERMISTOR -- cgit v1.2.1 From cec92aff246e711159220e2ce052a575a3a85279 Mon Sep 17 00:00:00 2001 From: Lawrence Date: Mon, 25 Jul 2011 10:56:55 -0700 Subject: Revert "Disable TEMP_RESIDENCY_TIME for default" This reverts commit eb1c87fa7bf2e4bcc8b074775d88a6e767de2c29. --- Sprinter/Configuration.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index 8e8724c..c1c4918 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -16,14 +16,12 @@ // 2 is 200k thermistor // 3 is mendel-parts thermistor // 4 is 10k thermistor -// 5 is Ultimachine -// 6 is honeywell -#define THERMISTORHEATER 5 -#define THERMISTORBED 6 +#define THERMISTORHEATER 1 +#define THERMISTORBED 1 //// Calibration variables // X, Y, Z, E steps per unit - Metric Prusa Mendel with Wade extruder: -float axis_steps_per_unit[] = {32.37655, 32.37655, 642,144.31/2}; +float axis_steps_per_unit[] = {80, 80, 3200/1.25,700}; // Metric Prusa Mendel with Makergear geared stepper extruder: //float axis_steps_per_unit[] = {80,80,3200/1.25,1380}; @@ -38,7 +36,7 @@ const bool ENDSTOPS_INVERTING = false; //set to true to invert the logic of the #define BAUDRATE 115200 // Comment out (using // at the start of the line) to disable SD support: -//#define SDSUPPORT 1 +#define SDSUPPORT 1 //// ADVANCED SETTINGS - to tweak parameters @@ -103,7 +101,7 @@ long max_travel_acceleration_units_per_sq_second[] = {500,500,50,500}; // X, Y, // Machine UUID // This may be useful if you have multiple machines and wish to identify them by using the M115 command. // By default we set it to zeros. -char uuid[] = "00000000-0000-0000-0000-000000000123"; +char uuid[] = "00000000-0000-0000-0000-000000000000"; //// AD595 THERMOCOUPLE SUPPORT UNTESTED... USE WITH CAUTION!!!! @@ -121,7 +119,7 @@ char uuid[] = "00000000-0000-0000-0000-000000000123"; // How often should the heater check for new temp readings, in milliseconds #define HEATER_CHECK_INTERVAL 500 -#define BED_CHECK_INTERVAL 2000 +#define BED_CHECK_INTERVAL 5000 // Comment the following line to enable heat management during acceleration #define DISABLE_CHECK_DURING_ACC #ifndef DISABLE_CHECK_DURING_ACC @@ -143,7 +141,7 @@ char uuid[] = "00000000-0000-0000-0000-000000000123"; //#define WATCHPERIOD 5000 //5 seconds // Wait this long after achieving target temperature on M109 before continuing with print (seconds) -//#define TEMP_RESIDENCY_TIME 20 +#define TEMP_RESIDENCY_TIME 20 //// The minimal temperature defines the temperature below which the heater will not be enabled #define MINTEMP 5 @@ -152,7 +150,7 @@ char uuid[] = "00000000-0000-0000-0000-000000000123"; // When temperature exceeds max temp, your heater will be switched off. // This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure! // You should use MINTEMP for thermistor short/failure protection. -#define MAXTEMP 250 +#define MAXTEMP 275 // Select one of these only to define how the nozzle temp is read. #define HEATER_USES_THERMISTOR -- cgit v1.2.1 From a24acc77318776409699e4ba78666ca627a998ef Mon Sep 17 00:00:00 2001 From: Lawrence Date: Mon, 25 Jul 2011 10:58:02 -0700 Subject: Comment out TEMP_RESIDENCY_TIME --- Sprinter/Configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index c1c4918..4dc72fa 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -141,7 +141,7 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; //#define WATCHPERIOD 5000 //5 seconds // Wait this long after achieving target temperature on M109 before continuing with print (seconds) -#define TEMP_RESIDENCY_TIME 20 +//#define TEMP_RESIDENCY_TIME 20 //// The minimal temperature defines the temperature below which the heater will not be enabled #define MINTEMP 5 -- cgit v1.2.1 From 53be78c9496f3fa2df191fb7dc621affdb2e1dc1 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 26 Jul 2011 18:17:52 +0200 Subject: New implementation of TEMP_RESIDENCY_TIME. We now wait for the target temp to be esablished and maintained for residency time +/- a configurable hysteresis --- Sprinter/Configuration.h | 5 +++-- Sprinter/Sprinter.pde | 33 +++++++++++++++++---------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index 3073393..1798642 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -143,8 +143,9 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; // If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109 //#define WATCHPERIOD 5000 //5 seconds -// Wait this long after achieving target temperature on M109 before continuing with print (seconds) -//#define TEMP_RESIDENCY_TIME 20 +// Actual temperature must be close to target for this long before M109 returns success +//#define TEMP_RESIDENCY_TIME 20 // (seconds) +//#define TEMP_HYSTERESIS 5 // (C°) range of +/- temperatures considered "close" to the target one //// The minimal temperature defines the temperature below which the heater will not be enabled #define MINTEMP 5 diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 801f103..4b93c0e 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -769,7 +769,16 @@ inline void process_commands() } #endif codenum = millis(); - while(current_raw < target_raw) { + #ifdef TEMP_RESIDENCY_TIME + long residencyStart; + residencyStart = -1; + /* continue to loop until we have reached the target temp + _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */ + while( current_raw < target_raw + || (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) { + #else + while(current_raw < target_raw) { + #endif if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. { Serial.print("T:"); @@ -777,23 +786,15 @@ inline void process_commands() codenum = millis(); } manage_heater(); - } - // wait extra time before letting the print continue - #ifdef TEMP_RESIDENCY_TIME - { - long residencyStart = millis(); - codenum = millis(); - while(millis()-residencyStart<(TEMP_RESIDENCY_TIME*1000)) { - if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. - { - Serial.print("T:"); - Serial.println( analog2temp(current_raw) ); - codenum = millis(); + #ifdef TEMP_RESIDENCY_TIME + /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time + or when current temp falls outside the hysteresis after target temp was reached */ + if ( (residencyStart == -1 && current_raw >= target_raw) + || (residencyStart > -1 && labs(analog2temp(current_raw) - analog2temp(target_raw)) > TEMP_HYSTERESIS) ) { + residencyStart = millis(); } - manage_heater(); - } + #endif } - #endif break; case 190: // M190 - Wait bed for heater to reach target. -- cgit v1.2.1 From 0ca62c559670c0d9878b1ede081267d7142506a5 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 26 Jul 2011 18:45:13 +0200 Subject: New config option HEATER_CURRENT to limit current to the nozzle --- Sprinter/Configuration.h | 4 +++- Sprinter/Sprinter.pde | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index 3073393..d8bc8ea 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -113,13 +113,15 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; // Uncomment the following line to enable PID support. This is untested and could be disastrous. Be careful. //#define PIDTEMP 1 #ifdef PIDTEMP -#define PID_MAX 255 // limits current to nozzle #define PID_INTEGRAL_DRIVE_MAX 220 #define PID_PGAIN 180 //100 is 1.0 #define PID_IGAIN 2 //100 is 1.0 #define PID_DGAIN 100 //100 is 1.0 #endif +// Change this value (range 1-255) to limit the current to the nozzle +#define HEATER_CURRENT 255 + // How often should the heater check for new temp readings, in milliseconds #define HEATER_CHECK_INTERVAL 500 #define BED_CHECK_INTERVAL 5000 diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 801f103..10e0648 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -126,6 +126,9 @@ int tt = 0, bt = 0; int temp_iState_min = 100 * -PID_INTEGRAL_DRIVE_MAX / PID_IGAIN; int temp_iState_max = 100 * PID_INTEGRAL_DRIVE_MAX / PID_IGAIN; #endif +#ifndef HEATER_CURRENT + #define HEATER_CURRENT 255 +#endif #ifdef SMOOTHING uint32_t nma = 0; #endif @@ -1443,7 +1446,7 @@ void manage_heater() iTerm = (PID_IGAIN * temp_iState) / 100; dTerm = (PID_DGAIN * (current_raw - temp_dState)) / 100; temp_dState = current_raw; - analogWrite(HEATER_0_PIN, constrain(pTerm + iTerm - dTerm, 0, PID_MAX)); + analogWrite(HEATER_0_PIN, constrain(pTerm + iTerm - dTerm, 0, HEATER_CURRENT)); #else if(current_raw >= target_raw) { @@ -1455,6 +1458,7 @@ void manage_heater() else { WRITE(HEATER_0_PIN,HIGH); + analogWrite(HEATER_0_PIN, HEATER_CURRENT); #if LED_PIN > -1 WRITE(LED_PIN,HIGH); #endif -- cgit v1.2.1 From 96291e27a89f2e68e00a3d90f2a8bd3b8bba8d97 Mon Sep 17 00:00:00 2001 From: Kliment Date: Tue, 2 Aug 2011 21:47:32 +0200 Subject: When you set PWM on a pin to a given value and then WRITE a 0 to it, the PWM timer does not stop. Set the PWM to 0 as well to prevent hotend meltdowns. --- Sprinter/Sprinter.pde | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index c6932cf..76c221f 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -1421,6 +1421,7 @@ void manage_heater() if(watch_raw + 1 >= current_raw){ target_raw = 0; WRITE(HEATER_0_PIN,LOW); + analogWrite(HEATER_0_PIN, 0); #if LED_PIN>-1 WRITE(LED_PIN,LOW); #endif @@ -1452,6 +1453,7 @@ void manage_heater() if(current_raw >= target_raw) { WRITE(HEATER_0_PIN,LOW); + analogWrite(HEATER_0_PIN, 0); #if LED_PIN>-1 WRITE(LED_PIN,LOW); #endif -- cgit v1.2.1 From 563c90f6ffc172ee671abe634ae87b3c250c7be8 Mon Sep 17 00:00:00 2001 From: blddk Date: Tue, 2 Aug 2011 23:47:30 +0300 Subject: Added a list of pins which will be ignored by manual change through M42 --- Sprinter/pins.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprinter/pins.h b/Sprinter/pins.h index 720f3a9..9c38bed 100644 --- a/Sprinter/pins.h +++ b/Sprinter/pins.h @@ -495,4 +495,7 @@ #endif +//List of pins which to ignore when asked to change by gcode, 0 and 1 are RX and TX, do not mess with those! +const int sensitive_pins[] = {0, 1, X_STEP_PIN, X_DIR_PIN, X_ENABLE_PIN, X_MIN_PIN, X_MAX_PIN, Y_STEP_PIN, Y_DIR_PIN, Y_ENABLE_PIN, Y_MIN_PIN, Y_MAX_PIN, Z_STEP_PIN, Z_DIR_PIN, Z_ENABLE_PIN, Z_MIN_PIN, Z_MAX_PIN, E_STEP_PIN, E_DIR_PIN, E_ENABLE_PIN, LED_PIN, PS_ON_PIN, HEATER_0_PIN, HEATER_1_PIN, FAN_PIN, TEMP_0_PIN, TEMP_1_PIN}; + #endif -- cgit v1.2.1 From ef66ecf5f1bb6c6c6819ee5c90efcb0d09419e71 Mon Sep 17 00:00:00 2001 From: blddk Date: Tue, 2 Aug 2011 23:50:10 +0300 Subject: Added M42 to control non used pins example: M42 P23 S255 --- Sprinter/Sprinter.pde | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index dde302c..5d40499 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -43,6 +43,7 @@ // M27 - Report SD print status // M28 - Start SD write (M28 filename.g) // M29 - Stop SD write +// M42 - Set output on free pins, on a non pwm pin (over pin 13 on an arduino mega) use S255 to turn it on and S0 to turn it off. Use P to decide the pin (M42 P23 S255) would turn pin 23 on // M81 - Turn off Power Supply // M82 - Set E codes absolute (default) // M83 - Set E codes relative while in Absolute Coordinates (G90) mode @@ -721,6 +722,31 @@ inline void process_commands() //savetosd = false; break; #endif + case 42: //M42 -Change pin status via gcode + if (code_seen('S')) + { + int pin_status = code_value(); + if (code_seen('P') && pin_status >= 0 && pin_status <= 255) + { + int pin_number = code_value(); + for(int i = 0; i < sizeof(sensitive_pins); i++) + { + if (sensitive_pins[i] == pin_number) + { + pin_number = -1; + break; + } + } + + if (pin_number > -1) + { + pinMode(pin_number, OUTPUT); + digitalWrite(pin_number, pin_status); + analogWrite(pin_number, pin_status); + } + } + } + break; case 104: // M104 if (code_seen('S')) target_raw = temp2analogh(code_value()); #ifdef WATCHPERIOD -- cgit v1.2.1 From f131f08bb65891ffbdfe9857f30e6b251d65b3bb Mon Sep 17 00:00:00 2001 From: blddk Date: Wed, 3 Aug 2011 01:47:56 +0300 Subject: Added MINTEMP to work on the heated bed too, so it will also turn off when thermistor fails. --- Sprinter/Sprinter.pde | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 5d40499..8639218 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -1498,7 +1498,7 @@ void manage_heater() #endif - if(current_bed_raw >= target_bed_raw) + if(current_bed_raw >= target_bed_raw || current_bed_raw < minttemp) { WRITE(HEATER_1_PIN,LOW); } -- cgit v1.2.1 From 02dfbc071d295e50f2bd752508226672850b7fe2 Mon Sep 17 00:00:00 2001 From: blddk Date: Wed, 3 Aug 2011 12:44:28 +0300 Subject: Fixed so commenting out MINTEMP won't break compile, however, commenting out MINTEMP will then again allow the bed to be turned on, but not off, when there are no thermistor, or thermistor is broken. --- Sprinter/Sprinter.pde | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 8639218..026daba 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -1498,7 +1498,11 @@ void manage_heater() #endif + #ifdef MINTEMP if(current_bed_raw >= target_bed_raw || current_bed_raw < minttemp) + #else + if(current_bed_raw >= target_bed_raw) + #endif { WRITE(HEATER_1_PIN,LOW); } -- cgit v1.2.1 From edc06d3bd3c487d0132ddc3eeed69ce8dfe7b56c Mon Sep 17 00:00:00 2001 From: Nils Date: Thu, 11 Aug 2011 15:36:48 +0200 Subject: Adding falling mode to M109 to better implement GCode definition --- Sprinter/Sprinter.pde | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 1173c79..3bb3358 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -798,16 +798,47 @@ inline void process_commands() } #endif codenum = millis(); - #ifdef TEMP_RESIDENCY_TIME - long residencyStart; - residencyStart = -1; - /* continue to loop until we have reached the target temp - _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */ - while( current_raw < target_raw + /* See if we are heating up or cooling down */ + if( current_raw < target_raw ) + /* We are heating up */ + #ifdef TEMP_RESIDENCY_TIME + long residencyStart; + residencyStart = -1; + /* continue to loop until we have reached the target temp + _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */ + while( current_raw < target_raw || (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) { - #else - while(current_raw < target_raw) { - #endif + #else + while(current_raw < target_raw) { + #endif + if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. + { + Serial.print("T:"); + Serial.println( analog2temp(current_raw) ); + codenum = millis(); + } + manage_heater(); + #ifdef TEMP_RESIDENCY_TIME + /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time + or when current temp falls outside the hysteresis after target temp was reached */ + if ( (residencyStart == -1 && current_raw >= target_raw) + || (residencyStart > -1 && labs(analog2temp(current_raw) - analog2temp(target_raw)) > TEMP_HYSTERESIS) ) { + residencyStart = millis(); + } + #endif + } + else if( current_raw > target_raw ) + /* We are cooling down */ + #ifdef TEMP_RESIDENCY_TIME + long residencyStart; + residencyStart = -1; + /* continue to loop until we have reached the target temp + _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */ + while( current_raw > target_raw + || (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) { + #else + while(current_raw > target_raw) { + #endif if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. { Serial.print("T:"); @@ -818,7 +849,7 @@ inline void process_commands() #ifdef TEMP_RESIDENCY_TIME /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time or when current temp falls outside the hysteresis after target temp was reached */ - if ( (residencyStart == -1 && current_raw >= target_raw) + if ( (residencyStart == -1 && current_raw <= target_raw) || (residencyStart > -1 && labs(analog2temp(current_raw) - analog2temp(target_raw)) > TEMP_HYSTERESIS) ) { residencyStart = millis(); } -- cgit v1.2.1 From a58e299370fa70f0bd1d15fba2d240ee5779cc86 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 25 Aug 2011 20:40:16 +0200 Subject: Refactoring in M109 to support residency time on cooling without code duplication --- Sprinter/Sprinter.pde | 70 ++++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 3bb3358..c0c4107 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -787,7 +787,7 @@ inline void process_commands() #endif return; //break; - case 109: // M109 - Wait for extruder heater to reach target. + case 109: { // M109 - Wait for extruder heater to reach target. if (code_seen('S')) target_raw = temp2analogh(code_value()); #ifdef WATCHPERIOD if(target_raw>current_raw){ @@ -798,65 +798,39 @@ inline void process_commands() } #endif codenum = millis(); + /* See if we are heating up or cooling down */ - if( current_raw < target_raw ) - /* We are heating up */ - #ifdef TEMP_RESIDENCY_TIME - long residencyStart; - residencyStart = -1; - /* continue to loop until we have reached the target temp - _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */ - while( current_raw < target_raw - || (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) { - #else - while(current_raw < target_raw) { - #endif - if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. - { - Serial.print("T:"); - Serial.println( analog2temp(current_raw) ); - codenum = millis(); - } - manage_heater(); - #ifdef TEMP_RESIDENCY_TIME - /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time - or when current temp falls outside the hysteresis after target temp was reached */ - if ( (residencyStart == -1 && current_raw >= target_raw) - || (residencyStart > -1 && labs(analog2temp(current_raw) - analog2temp(target_raw)) > TEMP_HYSTERESIS) ) { - residencyStart = millis(); - } - #endif - } - else if( current_raw > target_raw ) - /* We are cooling down */ - #ifdef TEMP_RESIDENCY_TIME - long residencyStart; - residencyStart = -1; - /* continue to loop until we have reached the target temp - _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */ - while( current_raw > target_raw - || (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) { - #else - while(current_raw > target_raw) { - #endif - if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. + bool target_direction = (current_raw < target_raw); // true if heating, false if cooling + + #ifdef TEMP_RESIDENCY_TIME + long residencyStart; + residencyStart = -1; + /* continue to loop until we have reached the target temp + _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */ + while( (target_direction ? (current_raw < target_raw) : (current_raw > target_raw)) + || (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) { + #else + while ( target_direction ? (current_raw < target_raw) : (current_raw > target_raw) ) { + #endif + if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up/cooling down { Serial.print("T:"); - Serial.println( analog2temp(current_raw) ); - codenum = millis(); + Serial.println( analog2temp(current_raw) ); + codenum = millis(); } manage_heater(); #ifdef TEMP_RESIDENCY_TIME /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time or when current temp falls outside the hysteresis after target temp was reached */ - if ( (residencyStart == -1 && current_raw <= target_raw) + if ( (residencyStart == -1 && target_direction && current_raw >= target_raw) + || (residencyStart == -1 && !target_direction && current_raw <= target_raw) || (residencyStart > -1 && labs(analog2temp(current_raw) - analog2temp(target_raw)) > TEMP_HYSTERESIS) ) { residencyStart = millis(); } #endif - } - - break; + } + } + break; case 190: // M190 - Wait bed for heater to reach target. #if TEMP_1_PIN > -1 if (code_seen('S')) target_bed_raw = temp2analogh(code_value()); -- cgit v1.2.1 From a638077ea8399f77e7314ddcb93eb985e01d5d1f Mon Sep 17 00:00:00 2001 From: lemio Date: Sat, 27 Aug 2011 03:35:42 +0300 Subject: Added support for using different endstops () --- Sprinter/Sprinter.pde | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 3bb3358..7081865 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -944,27 +944,27 @@ inline void process_commands() case 119: // M119 #if (X_MIN_PIN > -1) Serial.print("x_min:"); - Serial.print((READ(X_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L "); + Serial.print((READ(X_MIN_PIN)^X_ENDSTOP_INVERT)?"H ":"L "); #endif #if (X_MAX_PIN > -1) Serial.print("x_max:"); - Serial.print((READ(X_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L "); + Serial.print((READ(X_MAX_PIN)^X_ENDSTOP_INVERT)?"H ":"L "); #endif #if (Y_MIN_PIN > -1) Serial.print("y_min:"); - Serial.print((READ(Y_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L "); + Serial.print((READ(Y_MIN_PIN)^Y_ENDSTOP_INVERT)?"H ":"L "); #endif #if (Y_MAX_PIN > -1) Serial.print("y_max:"); - Serial.print((READ(Y_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L "); + Serial.print((READ(Y_MAX_PIN)^Y_ENDSTOP_INVERT)?"H ":"L "); #endif #if (Z_MIN_PIN > -1) Serial.print("z_min:"); - Serial.print((READ(Z_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L "); + Serial.print((READ(Z_MIN_PIN)^Z_ENDSTOP_INVERT?"H ":"L "); #endif #if (Z_MAX_PIN > -1) Serial.print("z_max:"); - Serial.print((READ(Z_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L "); + Serial.print((READ(Z_MAX_PIN)^Z_ENDSTOP_INVERT)?"H ":"L "); #endif Serial.println(""); break; @@ -1119,22 +1119,22 @@ inline void linear_move(unsigned long axis_steps_remaining[]) // make linear mov else WRITE(E_DIR_PIN,INVERT_E_DIR); movereset: #if (X_MIN_PIN > -1) - if(!move_direction[0]) if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[0]=0; + if(!move_direction[0]) if(READ(X_MIN_PIN) != X_ENDSTOP_INVERT) axis_steps_remaining[0]=0; #endif #if (Y_MIN_PIN > -1) - if(!move_direction[1]) if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[1]=0; + if(!move_direction[1]) if(READ(Y_MIN_PIN) != Y_ENDSTOP_INVERT) axis_steps_remaining[1]=0; #endif #if (Z_MIN_PIN > -1) - if(!move_direction[2]) if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[2]=0; + if(!move_direction[2]) if(READ(Z_MIN_PIN) != Z_ENDSTOP_INVERT) axis_steps_remaining[2]=0; #endif #if (X_MAX_PIN > -1) - if(move_direction[0]) if(READ(X_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[0]=0; + if(move_direction[0]) if(READ(X_MAX_PIN) != X_ENDSTOP_INVERT) axis_steps_remaining[0]=0; #endif #if (Y_MAX_PIN > -1) - if(move_direction[1]) if(READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[1]=0; + if(move_direction[1]) if(READ(Y_MAX_PIN) != Y_ENDSTOP_INVERT) axis_steps_remaining[1]=0; #endif # if(Z_MAX_PIN > -1) - if(move_direction[2]) if(READ(Z_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[2]=0; + if(move_direction[2]) if(READ(Z_MAX_PIN) != Z_ENDSTOP_INVERT) axis_steps_remaining[2]=0; #endif @@ -1310,22 +1310,22 @@ inline void linear_move(unsigned long axis_steps_remaining[]) // make linear mov //If there are x or y steps remaining, perform Bresenham algorithm if(axis_steps_remaining[primary_axis]) { #if (X_MIN_PIN > -1) - if(!move_direction[0]) if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) if(primary_axis==0) break; else if(axis_steps_remaining[0]) axis_steps_remaining[0]=0; + if(!move_direction[0]) if(READ(X_MIN_PIN) != X_ENDSTOP_INVERT) if(primary_axis==0) break; else if(axis_steps_remaining[0]) axis_steps_remaining[0]=0; #endif #if (Y_MIN_PIN > -1) - if(!move_direction[1]) if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) if(primary_axis==1) break; else if(axis_steps_remaining[1]) axis_steps_remaining[1]=0; + if(!move_direction[1]) if(READ(Y_MIN_PIN) != Y_ENDSTOP_INVERT) if(primary_axis==1) break; else if(axis_steps_remaining[1]) axis_steps_remaining[1]=0; #endif #if (X_MAX_PIN > -1) - if(move_direction[0]) if(READ(X_MAX_PIN) != ENDSTOPS_INVERTING) if(primary_axis==0) break; else if(axis_steps_remaining[0]) axis_steps_remaining[0]=0; + if(move_direction[0]) if(READ(X_MAX_PIN) != X_ENDSTOP_INVERT) if(primary_axis==0) break; else if(axis_steps_remaining[0]) axis_steps_remaining[0]=0; #endif #if (Y_MAX_PIN > -1) - if(move_direction[1]) if(READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) if(primary_axis==1) break; else if(axis_steps_remaining[1]) axis_steps_remaining[1]=0; + if(move_direction[1]) if(READ(Y_MAX_PIN) != Y_ENDSTOP_INVERT) if(primary_axis==1) break; else if(axis_steps_remaining[1]) axis_steps_remaining[1]=0; #endif #if (Z_MIN_PIN > -1) - if(!move_direction[2]) if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) if(primary_axis==2) break; else if(axis_steps_remaining[2]) axis_steps_remaining[2]=0; + if(!move_direction[2]) if(READ(Z_MIN_PIN) != Z_ENDSTOP_INVERT) if(primary_axis==2) break; else if(axis_steps_remaining[2]) axis_steps_remaining[2]=0; #endif #if (Z_MAX_PIN > -1) - if(move_direction[2]) if(READ(Z_MAX_PIN) != ENDSTOPS_INVERTING) if(primary_axis==2) break; else if(axis_steps_remaining[2]) axis_steps_remaining[2]=0; + if(move_direction[2]) if(READ(Z_MAX_PIN) != Z_ENDSTOP_INVERT) if(primary_axis==2) break; else if(axis_steps_remaining[2]) axis_steps_remaining[2]=0; #endif timediff = micros() * 100 - axis_previous_micros[primary_axis]; if(timediff<0){//check for overflow -- cgit v1.2.1 From 34b9fd054b7c45e9e3d7b6696c426d006380fd14 Mon Sep 17 00:00:00 2001 From: lemio Date: Sat, 27 Aug 2011 03:28:16 +0300 Subject: Edited Sprinter/Configuration.h via GitHub --- Sprinter/Configuration.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index 354e59d..f0001da 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -31,10 +31,11 @@ float axis_steps_per_unit[] = {80, 80, 3200/1.25,700}; //// Endstop Settings #define ENDSTOPPULLUPS 1 // Comment this out (using // at the start of the line) to disable the endstop pullup resistors // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins. -const bool ENDSTOPS_INVERTING = false; //set to true to invert the logic of the endstops //If your axes are only moving in one direction, make sure the endstops are connected properly. //If your axes move in one direction ONLY when the endstops are triggered, set ENDSTOPS_INVERTING to true here - +cost bool X_ENDSTOP_INVERT = false;//set to true to invert the logic of the endstops +cost bool Y_ENDSTOP_INVERT = false;//set to true to invert the logic of the endstops +cost bool Z_ENDSTOP_INVERT = false;//set to true to invert the logic of the endstops // This determines the communication speed of the printer #define BAUDRATE 115200 -- cgit v1.2.1 From 492682f06a7821f8e1bcd2153676e371d0186ad8 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 26 Aug 2011 19:40:37 +0200 Subject: Fixed configuration for new [XYZ]_ENDSTOP_INVERT options --- Sprinter/Configuration.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index f0001da..2594593 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -32,10 +32,11 @@ float axis_steps_per_unit[] = {80, 80, 3200/1.25,700}; #define ENDSTOPPULLUPS 1 // Comment this out (using // at the start of the line) to disable the endstop pullup resistors // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins. //If your axes are only moving in one direction, make sure the endstops are connected properly. -//If your axes move in one direction ONLY when the endstops are triggered, set ENDSTOPS_INVERTING to true here -cost bool X_ENDSTOP_INVERT = false;//set to true to invert the logic of the endstops -cost bool Y_ENDSTOP_INVERT = false;//set to true to invert the logic of the endstops -cost bool Z_ENDSTOP_INVERT = false;//set to true to invert the logic of the endstops +//If your axes move in one direction ONLY when the endstops are triggered, set [XYZ]_ENDSTOP_INVERT to true here: +const bool X_ENDSTOP_INVERT = false; +const bool Y_ENDSTOP_INVERT = false; +const bool Z_ENDSTOP_INVERT = false; + // This determines the communication speed of the printer #define BAUDRATE 115200 -- cgit v1.2.1 From b74d1b90e3d74176b1b97b481d91e73bbc0f3557 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 26 Aug 2011 19:43:38 +0200 Subject: Fixed typo in Z_ENDSTOP_INVERT patch by lemio --- Sprinter/Sprinter.pde | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 7081865..3243d78 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -960,7 +960,7 @@ inline void process_commands() #endif #if (Z_MIN_PIN > -1) Serial.print("z_min:"); - Serial.print((READ(Z_MIN_PIN)^Z_ENDSTOP_INVERT?"H ":"L "); + Serial.print((READ(Z_MIN_PIN)^Z_ENDSTOP_INVERT)?"H ":"L "); #endif #if (Z_MAX_PIN > -1) Serial.print("z_max:"); -- cgit v1.2.1 From 2acd4af635f0800fe1da38055efa5664b6b92307 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 29 Aug 2011 15:07:37 +0200 Subject: Refactoring acceleration math to a new setup_acceleration() function to make M92 fully working. --- Sprinter/Sprinter.pde | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index c0c4107..99c1dce 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -311,11 +311,7 @@ void setup() SET_OUTPUT(E_STEP_PIN); #endif #ifdef RAMP_ACCELERATION - for(int i=0; i < NUM_AXIS; i++){ - axis_max_interval[i] = 100000000.0 / (max_start_speed_units_per_second[i] * axis_steps_per_unit[i]); - axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i]; - axis_travel_steps_per_sqr_second[i] = max_travel_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i]; - } + setup_acceleration(); #endif #ifdef HEATER_USES_MAX6675 @@ -891,15 +887,10 @@ inline void process_commands() if(code_seen(axis_codes[i])) axis_steps_per_unit[i] = code_value(); } - //Update start speed intervals and axis order. TODO: refactor axis_max_interval[] calculation into a function, as it - // should also be used in setup() as well #ifdef RAMP_ACCELERATION - long temp_max_intervals[NUM_AXIS]; - for(int i=0; i < NUM_AXIS; i++) { - axis_max_interval[i] = 100000000.0 / (max_start_speed_units_per_second[i] * axis_steps_per_unit[i]);//TODO: do this for - // all steps_per_unit related variables - } + setup_acceleration(); #endif + break; case 115: // M115 Serial.print("FIRMWARE_NAME:Sprinter FIRMWARE_URL:http%%3A/github.com/kliment/Sprinter/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 UUID:"); @@ -1638,6 +1629,16 @@ if( (millis()-previous_millis_cmd) > max_inactive_time ) if(max_inactive_time) if( (millis()-previous_millis_cmd) > stepper_inactive_time ) if(stepper_inactive_time) { disable_x(); disable_y(); disable_z(); disable_e(); } } +#ifdef RAMP_ACCELERATION +void setup_acceleration() { + for (int i=0; i < NUM_AXIS; i++) { + axis_max_interval[i] = 100000000.0 / (max_start_speed_units_per_second[i] * axis_steps_per_unit[i]); + axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i]; + axis_travel_steps_per_sqr_second[i] = max_travel_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i]; + } +} +#endif + #ifdef DEBUG void log_message(char* message) { Serial.print("DEBUG"); Serial.println(message); -- cgit v1.2.1 From 736a8f3b4a79d40b6c69eda659ba53e41c7ab342 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 29 Aug 2011 16:05:37 +0200 Subject: Added setup_acceleration() to header file --- Sprinter/Sprinter.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprinter/Sprinter.h b/Sprinter/Sprinter.h index d612b5d..a7c7a8f 100644 --- a/Sprinter/Sprinter.h +++ b/Sprinter/Sprinter.h @@ -8,6 +8,7 @@ void get_command(); void process_commands(); void manage_inactivity(byte debug); +void setup_acceleration(); void manage_heater(); int temp2analogu(int celsius, const short table[][2], int numtemps, int source); -- cgit v1.2.1 From abff90d5547471d8811ea0967fedf053f8eeea66 Mon Sep 17 00:00:00 2001 From: Kliment Yanev Date: Wed, 31 Aug 2011 11:55:24 +0200 Subject: Add temp2 pin define --- Sprinter/pins.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprinter/pins.h b/Sprinter/pins.h index 720f3a9..aeb747d 100644 --- a/Sprinter/pins.h +++ b/Sprinter/pins.h @@ -261,7 +261,7 @@ #define HEATER_1_PIN 8 #define TEMP_0_PIN 13 // ANALOG NUMBERING #define TEMP_1_PIN 14 // ANALOG NUMBERING - +#define TEMP_2_PIN 15 // ANALOG NUMBERING #else // RAMPS_V_1_1 or RAMPS_V_1_2 as default -- cgit v1.2.1 From 614b60b038cf14e1a9f469cd04bfe1bda44f28fb Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 11 Sep 2011 16:36:15 +0930 Subject: Fix temp readings for multiple sensor types. Signed-off-by: Greg Frost --- Sprinter/Sprinter.h | 42 ++++++++++++++++++++--------------------- Sprinter/Sprinter.pde | 52 +++++++++++++++++++++++++++------------------------ 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/Sprinter/Sprinter.h b/Sprinter/Sprinter.h index a7c7a8f..e77da12 100644 --- a/Sprinter/Sprinter.h +++ b/Sprinter/Sprinter.h @@ -11,31 +11,29 @@ void manage_inactivity(byte debug); void setup_acceleration(); void manage_heater(); -int temp2analogu(int celsius, const short table[][2], int numtemps, int source); -int analog2tempu(int raw, const short table[][2], int numtemps, int source); -#ifdef HEATER_USES_THERMISTOR - #define HEATERSOURCE 1 -#endif -#ifdef HEATER_USES_AD595 - #define HEATERSOURCE 2 -#endif -#ifdef HEATER_USES_MAX6675 - #define HEATERSOURCE 3 -#endif -#ifdef BED_USES_THERMISTOR - #define BEDSOURCE 1 -#endif -#ifdef BED_USES_AD595 - #define BEDSOURCE 2 + +#if defined HEATER_USES_THERMISTOR +#define temp2analogh( c ) temp2analog_thermistor(c,temptable,NUMTEMPS) +#define analog2temp( c ) analog2temp_thermistor(c,temptable,NUMTEMPS) +#elif defined HEATER_USES_AD595 +#define temp2analogh( c ) temp2analog_ad595(c) +#define analog2temp( c ) analog2temp_ad595(c) +#elif defined HEATER_USES_MAX6675 +#define temp2analogh( c ) temp2analog_max6675(c) +#define analog2temp( c ) analog2temp_max6675(c) #endif -#ifdef BED_USES_MAX6675 - #define BEDSOURCE 3 + +#if defined BED_USES_THERMISTOR +#define temp2analogBed( c ) temp2analog_thermistor((c),bedtemptable,BNUMTEMPS) +#define analog2tempBed( c ) analog2temp_thermistor((c),bedtemptable,BNUMTEMPS) +#elif defined BED_USES_AD595 +#define temp2analogBed( c ) temp2analog_ad595(c) +#define analog2tempBed( c ) analog2temp_ad595(c) +#elif defined BED_USES_MAX6675 +#define temp2analogBed( c ) temp2analog_max6675(c) +#define analog2tempBed( c ) analog2temp_max6675(c) #endif -#define temp2analogh( c ) temp2analogu((c),temptable,NUMTEMPS,HEATERSOURCE) -#define temp2analogBed( c ) temp2analogu((c),bedtemptable,BNUMTEMPS,BEDSOURCE) -#define analog2temp( c ) analog2tempu((c),temptable,NUMTEMPS,HEATERSOURCE) -#define analog2tempBed( c ) analog2tempu((c),bedtemptable,BNUMTEMPS,BEDSOURCE) #if X_ENABLE_PIN > -1 #define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON) #define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 5daee2f..cc1434f 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -1539,10 +1539,8 @@ void manage_heater() #endif } - -int temp2analogu(int celsius, const short table[][2], int numtemps, int source) { - #if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR) - if(source==1){ +#if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR) +int temp2analog_thermistor(int celsius, const short table[][2], int numtemps) { int raw = 0; byte i; @@ -1563,20 +1561,23 @@ int temp2analogu(int celsius, const short table[][2], int numtemps, int source) if (i == numtemps) raw = table[i-1][0]; return 1023 - raw; - } - #elif defined (HEATER_USES_AD595) || defined (BED_USES_AD595) - if(source==2) - return celsius * 1024 / (500); - #elif defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675) - if(source==3) - return celsius * 4; - #endif - return -1; } +#endif + +#if defined (HEATER_USES_AD595) || defined (BED_USES_AD595) +int temp2analog_ad595(int celsius) { + return celsius * 1024 / (500); +} +#endif + +#if defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675) +int temp2analog_max6675(int celsius) { + return celsius * 4; +} +#endif -int analog2tempu(int raw,const short table[][2], int numtemps, int source) { - #if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR) - if(source==1){ +#if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR) +int analog2temp_thermistor(int raw,const short table[][2], int numtemps) { int celsius = 0; byte i; @@ -1599,17 +1600,20 @@ int analog2tempu(int raw,const short table[][2], int numtemps, int source) { if (i == numtemps) celsius = table[i-1][1]; return celsius; - } - #elif defined (HEATER_USES_AD595) || defined (BED_USES_AD595) - if(source==2) +} +#endif + +#if defined (HEATER_USES_AD595) || defined (BED_USES_AD595) +int analog2temp_ad595(int raw) { return raw * 500 / 1024; - #elif defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675) - if(source==3) - return raw / 4; - #endif - return -1; } +#endif +#if defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675) +int analog2temp_max6675(int raw) { + return raw / 4; +} +#endif inline void kill() { -- cgit v1.2.1 From f14bac8a91a82fdc33b5c65d8033014ec5f45a6f Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 17 Sep 2011 09:45:25 +0200 Subject: Initialize LED pin (was stuck after hard resets) --- Sprinter/Sprinter.pde | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index cc1434f..8e94db8 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -302,6 +302,12 @@ void setup() SET_OUTPUT(FAN_PIN); #endif + //Initialize LED Pin + #if (LED_PIN > -1) + SET_OUTPUT(LED_PIN); + WRITE(LED_PIN,LOW); + #endif + //Initialize Step Pins #if (X_STEP_PIN > -1) SET_OUTPUT(X_STEP_PIN); -- cgit v1.2.1 From 205d115002a18c7c9ccd8dc2aed388196772fadb Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 17 Sep 2011 14:54:39 +0200 Subject: Signal an optional ALARM_PIN when reaching MAXTEMP Alarm signal can be dismissed by hard-resetting the board or by sending a M42 P23 S0 command (where 23 is the ALARM_PIN) --- Sprinter/Sprinter.pde | 9 +++++++++ Sprinter/pins.h | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index cc1434f..f04e374 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -302,6 +302,12 @@ void setup() SET_OUTPUT(FAN_PIN); #endif + //Initialize Alarm Pin + #if (ALARM_PIN > -1) + SET_OUTPUT(ALARM_PIN); + WRITE(ALARM_PIN,LOW); + #endif + //Initialize Step Pins #if (X_STEP_PIN > -1) SET_OUTPUT(X_STEP_PIN); @@ -1465,6 +1471,9 @@ void manage_heater() #ifdef MAXTEMP if(current_raw >= maxttemp) { target_raw = 0; + #if (ALARM_PIN > -1) + WRITE(ALARM_PIN,HIGH); + #endif } #endif #if (TEMP_0_PIN > -1) || defined (HEATER_USES_MAX6675) || defined (HEATER_USES_AD595) diff --git a/Sprinter/pins.h b/Sprinter/pins.h index 8571d20..fd9995d 100644 --- a/Sprinter/pins.h +++ b/Sprinter/pins.h @@ -57,6 +57,7 @@ #define FAN_PIN -1 #define PS_ON_PIN 15 #define KILL_PIN -1 +#define ALARM_PIN -1 #define HEATER_0_PIN 6 #define TEMP_0_PIN 0 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! @@ -130,6 +131,7 @@ #define FAN_PIN -1 #define PS_ON_PIN -1 #define KILL_PIN -1 +#define ALARM_PIN -1 #define HEATER_0_PIN 14 #define TEMP_0_PIN 4 //D27 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! @@ -191,6 +193,7 @@ #define FAN_PIN -1 #define KILL_PIN -1 +#define ALARM_PIN -1 #define HEATER_0_PIN -1 #define TEMP_0_PIN -1 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! @@ -379,6 +382,7 @@ #define FAN_PIN 9 #define PS_ON_PIN 12 #define KILL_PIN -1 +#define ALARM_PIN -1 #define HEATER_0_PIN 10 #define HEATER_1_PIN 8 @@ -415,7 +419,7 @@ #define LED_PIN 13 #define PS_ON_PIN -1 #define KILL_PIN -1 - +#define ALARM_PIN -1 #ifdef RAMPS_V_1_0 // RAMPS_V_1_0 @@ -486,6 +490,7 @@ #define FAN_PIN 5 #define PS_ON_PIN -1 #define KILL_PIN -1 +#define ALARM_PIN -1 #define HEATER_0_PIN 6 #define TEMP_0_PIN 0 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! @@ -587,6 +592,7 @@ #define PS_ON_PIN -1 #define KILL_PIN -1 +#define ALARM_PIN -1 #define HEATER_0_PIN 13 // (extruder) -- cgit v1.2.1 From 80f186ebe05615fe7127914ce71186564ae29ea0 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 17 Sep 2011 16:27:10 +0200 Subject: Reset heater pins after hard resets to avoid keeping them enabled while we don't have temperature control anymore --- Sprinter/Sprinter.pde | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index e3f60b2..d385285 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -292,9 +292,11 @@ void setup() #if (HEATER_0_PIN > -1) SET_OUTPUT(HEATER_0_PIN); + WRITE(HEATER_0_PIN,LOW); #endif #if (HEATER_1_PIN > -1) SET_OUTPUT(HEATER_1_PIN); + WRITE(HEATER_1_PIN,LOW); #endif //Initialize Fan Pin -- cgit v1.2.1 From c6a228d62ed7f42eb2a019801d9fa4316b45bdb7 Mon Sep 17 00:00:00 2001 From: Keegi Date: Tue, 9 Aug 2011 10:56:34 +0300 Subject: PID fixes --- Sprinter/Configuration.h | 12 ++++++++---- Sprinter/Sprinter.pde | 45 ++++++++++++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index bc00ce1..df55c7d 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -120,10 +120,14 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; // Uncomment the following line to enable PID support. This is untested and could be disastrous. Be careful. //#define PIDTEMP #ifdef PIDTEMP -#define PID_INTEGRAL_DRIVE_MAX 220 -#define PID_PGAIN 180 //100 is 1.0 -#define PID_IGAIN 2 //100 is 1.0 -#define PID_DGAIN 100 //100 is 1.0 +#define PID_INTEGRAL_DRIVE_MAX 80 // too big, and heater will lag after changing temperature, too small and it might not compensate enough for long-term errors +#define PID_PGAIN 1280 //256 is 1.0 // value of 5.0 means that error of 20C is changing it almost halfway of the PWM range +#define PID_IGAIN 64 //256 is 1.0 // value of 0.25 means that each degree error over 1 sec (2 measurements) changes duty cycle by 0.5 units (verify?) +#define PID_DGAIN 2048 //256 is 1.0 // value of 8.0 means that each degree change over one measurement (half second) adjusts PWM by 8 units to compensate +// magic formula 1, to get approximate "zero error" PWM duty. It is most likely linear formula +#define HEATER_DUTY_FOR_SETPOINT(setpoint) (22+1*setpoint) +// magic formula 2, to make led brightness approximately linear +#define LED_PWM_FOR_BRIGTHNESS(brightness) ((64*brightness-1384)/(300-brightness)) #endif // Change this value (range 1-255) to limit the current to the nozzle diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index d385285..2f8cac9 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -1,4 +1,4 @@ -// Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware. + // Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware. // Licence: GPL #include "fastio.h" @@ -112,20 +112,22 @@ char *strchr_pointer; // just a pointer to find chars in the cmd string like X, // degree increments (i.e. 100=25 deg). int target_raw = 0; +int target_temp = 0; int current_raw = 0; int target_bed_raw = 0; int current_bed_raw = 0; int tt = 0, bt = 0; #ifdef PIDTEMP int temp_iState = 0; - int temp_dState = 0; + int prev_temp = 0; int pTerm; int iTerm; int dTerm; //int output; int error; - int temp_iState_min = 100 * -PID_INTEGRAL_DRIVE_MAX / PID_IGAIN; - int temp_iState_max = 100 * PID_INTEGRAL_DRIVE_MAX / PID_IGAIN; + int heater_duty = 0; + const int temp_iState_min = 256L * -PID_INTEGRAL_DRIVE_MAX / PID_IGAIN; + const int temp_iState_max = 256L * PID_INTEGRAL_DRIVE_MAX / PID_IGAIN; #endif #ifndef HEATER_CURRENT #define HEATER_CURRENT 255 @@ -766,7 +768,7 @@ inline void process_commands() } break; case 104: // M104 - if (code_seen('S')) target_raw = temp2analogh(code_value()); + if (code_seen('S')) target_raw = temp2analogh(target_temp = code_value()); #ifdef WATCHPERIOD if(target_raw > current_raw){ watchmillis = max(1,millis()); @@ -791,6 +793,12 @@ inline void process_commands() #if (TEMP_0_PIN > -1) || defined (HEATER_USES_MAX6675) || defined HEATER_USES_AD595 Serial.print("ok T:"); Serial.print(tt); + #ifdef PIDTEMP + Serial.print(" @:"); + Serial.print(heater_duty); + Serial.print(","); + Serial.print(iTerm); + #endif #if TEMP_1_PIN > -1 || defined BED_USES_AD595 Serial.print(" B:"); Serial.println(bt); @@ -803,7 +811,7 @@ inline void process_commands() return; //break; case 109: { // M109 - Wait for extruder heater to reach target. - if (code_seen('S')) target_raw = temp2analogh(code_value()); + if (code_seen('S')) target_raw = temp2analogh(target_temp = code_value()); #ifdef WATCHPERIOD if(target_raw>current_raw){ watchmillis = max(1,millis()); @@ -1461,7 +1469,7 @@ void manage_heater() #ifdef WATCHPERIOD if(watchmillis && millis() - watchmillis > WATCHPERIOD){ if(watch_raw + 1 >= current_raw){ - target_raw = 0; + target_temp = target_raw = 0; WRITE(HEATER_0_PIN,LOW); analogWrite(HEATER_0_PIN, 0); #if LED_PIN>-1 @@ -1474,11 +1482,11 @@ void manage_heater() #endif #ifdef MINTEMP if(current_raw <= minttemp) - target_raw = 0; + target_temp = target_raw = 0; #endif #ifdef MAXTEMP if(current_raw >= maxttemp) { - target_raw = 0; + target_temp = target_raw = 0; #if (ALARM_PIN > -1) WRITE(ALARM_PIN,HIGH); #endif @@ -1486,14 +1494,21 @@ void manage_heater() #endif #if (TEMP_0_PIN > -1) || defined (HEATER_USES_MAX6675) || defined (HEATER_USES_AD595) #ifdef PIDTEMP - error = target_raw - current_raw; - pTerm = (PID_PGAIN * error) / 100; + int current_temp = analog2temp(current_raw); + error = target_temp - current_temp; + int delta_temp = current_temp - prev_temp; + prev_temp = current_temp; + pTerm = ((long)PID_PGAIN * error) / 256; temp_iState += error; temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max); - iTerm = (PID_IGAIN * temp_iState) / 100; - dTerm = (PID_DGAIN * (current_raw - temp_dState)) / 100; - temp_dState = current_raw; - analogWrite(HEATER_0_PIN, constrain(pTerm + iTerm - dTerm, 0, HEATER_CURRENT)); + iTerm = ((long)PID_IGAIN * temp_iState) / 256; + dTerm = ((long)PID_DGAIN * delta_temp) / 256; + const int H0 = min(HEATER_DUTY_FOR_SETPOINT(target_temp),HEATER_CURRENT); + heater_duty = H0 + constrain(pTerm + iTerm - dTerm, -H0, HEATER_CURRENT-H0); + analogWrite(HEATER_0_PIN, heater_duty); + #if LED_PIN>-1 + analogWrite(LED_PIN, constrain(LED_PWM_FOR_BRIGHTNESS(heater_duty),0,255)); + #endif #else if(current_raw >= target_raw) { -- cgit v1.2.1 From 116eefa1d78339a705390eb14db9eb4f09a6ae1a Mon Sep 17 00:00:00 2001 From: Keegi Date: Wed, 10 Aug 2011 16:09:23 +0300 Subject: fixed typo, added even more PID improvements (these settings work out of box for my old hotend, but overshoot badly on MG hotend) --- Sprinter/Configuration.h | 4 ++-- Sprinter/Sprinter.pde | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index df55c7d..e246e65 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -118,7 +118,7 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; //// PID settings: // Uncomment the following line to enable PID support. This is untested and could be disastrous. Be careful. -//#define PIDTEMP +//#define PIDTEMP 1 #ifdef PIDTEMP #define PID_INTEGRAL_DRIVE_MAX 80 // too big, and heater will lag after changing temperature, too small and it might not compensate enough for long-term errors #define PID_PGAIN 1280 //256 is 1.0 // value of 5.0 means that error of 20C is changing it almost halfway of the PWM range @@ -127,7 +127,7 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; // magic formula 1, to get approximate "zero error" PWM duty. It is most likely linear formula #define HEATER_DUTY_FOR_SETPOINT(setpoint) (22+1*setpoint) // magic formula 2, to make led brightness approximately linear -#define LED_PWM_FOR_BRIGTHNESS(brightness) ((64*brightness-1384)/(300-brightness)) +#define LED_PWM_FOR_BRIGHTNESS(brightness) ((64*brightness-1384)/(300-brightness)) #endif // Change this value (range 1-255) to limit the current to the nozzle diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 2f8cac9..7e9b3ba 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -1499,12 +1499,22 @@ void manage_heater() int delta_temp = current_temp - prev_temp; prev_temp = current_temp; pTerm = ((long)PID_PGAIN * error) / 256; - temp_iState += error; - temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max); - iTerm = ((long)PID_IGAIN * temp_iState) / 256; - dTerm = ((long)PID_DGAIN * delta_temp) / 256; const int H0 = min(HEATER_DUTY_FOR_SETPOINT(target_temp),HEATER_CURRENT); - heater_duty = H0 + constrain(pTerm + iTerm - dTerm, -H0, HEATER_CURRENT-H0); + heater_duty = H0 + pTerm; + if(error < 20){ + temp_iState += error; + temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max); + iTerm = ((long)PID_IGAIN * temp_iState) / 256; + heater_duty += iTerm; + } + int prev_error = abs(target_temp - prev_temp); + int log3 = 1; // discrete logarithm base 3, plus 1 + if(prev_error > 81){ prev_error /= 81; log3 += 4; } + if(prev_error > 9){ prev_error /= 9; log3 += 2; } + if(prev_error > 3){ prev_error /= 3; log3 ++; } + dTerm = ((long)PID_DGAIN * delta_temp) / (256*log3); + heater_duty += dTerm; + heater_duty = constrain(heater_duty, 0, HEATER_CURRENT); analogWrite(HEATER_0_PIN, heater_duty); #if LED_PIN>-1 analogWrite(LED_PIN, constrain(LED_PWM_FOR_BRIGHTNESS(heater_duty),0,255)); -- cgit v1.2.1 From 66a04dd00c3ecc823255e0b661904fe4f4949585 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 17 Sep 2011 16:58:17 +0200 Subject: Commit 614b60b was missing function signatures and wouldn't compile --- Sprinter/Sprinter.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprinter/Sprinter.h b/Sprinter/Sprinter.h index e77da12..2ac9163 100644 --- a/Sprinter/Sprinter.h +++ b/Sprinter/Sprinter.h @@ -34,6 +34,21 @@ void manage_heater(); #define analog2tempBed( c ) analog2temp_max6675(c) #endif +#if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR) +int temp2analog_thermistor(int celsius, const short table[][2], int numtemps); +int analog2temp_thermistor(int raw,const short table[][2], int numtemps); +#endif + +#if defined (HEATER_USES_AD595) || defined (BED_USES_AD595) +int temp2analog_ad595(int celsius); +int analog2temp_ad595(int raw); +#endif + +#if defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675) +int temp2analog_max6675(int celsius); +int analog2temp_max6675(int raw); +#endif + #if X_ENABLE_PIN > -1 #define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON) #define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON) -- cgit v1.2.1 From 3991d6c46a8b25bae95c0d84072e2a26f2606699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20=27ax=27=20H=C5=AFla?= Date: Sat, 17 Sep 2011 19:50:06 +0200 Subject: simplified string-to-number conversions --- Sprinter/Sprinter.pde | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index a941531..fdd3920 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -392,7 +392,7 @@ inline void get_command() if(strstr(cmdbuffer[bufindw], "N") != NULL) { strchr_pointer = strchr(cmdbuffer[bufindw], 'N'); - gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10)); + gcode_N = atoi(strchr_pointer+1); if(gcode_N != gcode_LastN+1 && (strstr(cmdbuffer[bufindw], "M110") == NULL) ) { Serial.print("Serial Error: Line Number is not Last Line Number+1, Last Line:"); Serial.println(gcode_LastN); @@ -409,7 +409,7 @@ inline void get_command() while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++]; strchr_pointer = strchr(cmdbuffer[bufindw], '*'); - if( (int)(strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)) != checksum) { + if( atoi(strchr_pointer+1) != checksum) { Serial.print("Error: checksum mismatch, Last Line:"); Serial.println(gcode_LastN); FlushSerialRequestResend(); @@ -442,7 +442,7 @@ inline void get_command() } if((strstr(cmdbuffer[bufindw], "G") != NULL)){ strchr_pointer = strchr(cmdbuffer[bufindw], 'G'); - switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))){ + switch(atoi(strchr_pointer+1)){ case 0: case 1: #ifdef SDSUPPORT @@ -504,8 +504,8 @@ if(!sdmode || serial_count!=0){ } -inline float code_value() { return (strtod(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL)); } -inline long code_value_long() { return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10)); } +inline float code_value() { return strtod(strchr_pointer, NULL); } +inline long code_value_long() { return atol(strchr_pointer); } inline bool code_seen(char code_string[]) { return (strstr(cmdbuffer[bufindr], code_string) != NULL); } //Return True if the string was found inline bool code_seen(char code) -- cgit v1.2.1 From 3d4980b4f2ebf4ddf165b960dd6226758a30d696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20=27ax=27=20H=C5=AFla?= Date: Sat, 17 Sep 2011 20:14:20 +0200 Subject: line numbers ale long, not int --- Sprinter/Sprinter.pde | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index fdd3920..31ef14c 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -392,7 +392,7 @@ inline void get_command() if(strstr(cmdbuffer[bufindw], "N") != NULL) { strchr_pointer = strchr(cmdbuffer[bufindw], 'N'); - gcode_N = atoi(strchr_pointer+1); + gcode_N = atol(strchr_pointer+1); if(gcode_N != gcode_LastN+1 && (strstr(cmdbuffer[bufindw], "M110") == NULL) ) { Serial.print("Serial Error: Line Number is not Last Line Number+1, Last Line:"); Serial.println(gcode_LastN); -- cgit v1.2.1 From 28a37563de7717b16569beb1dafc51811b9d510c Mon Sep 17 00:00:00 2001 From: Kliment Yanev Date: Sun, 18 Sep 2011 22:18:30 +0200 Subject: Revert "Merge pull request #95 from AxTheB/master" This reverts commit a27649c455c4d13385b32d45bf353ab890da052a, reversing changes made to 8fa84ce04eda414886cc5b075d7257e49b6f7f0a. --- Sprinter/Sprinter.pde | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 0fa00d3..7e9b3ba 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -408,7 +408,7 @@ inline void get_command() if(strstr(cmdbuffer[bufindw], "N") != NULL) { strchr_pointer = strchr(cmdbuffer[bufindw], 'N'); - gcode_N = atol(strchr_pointer+1); + gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10)); if(gcode_N != gcode_LastN+1 && (strstr(cmdbuffer[bufindw], "M110") == NULL) ) { Serial.print("Serial Error: Line Number is not Last Line Number+1, Last Line:"); Serial.println(gcode_LastN); @@ -425,7 +425,7 @@ inline void get_command() while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++]; strchr_pointer = strchr(cmdbuffer[bufindw], '*'); - if( atoi(strchr_pointer+1) != checksum) { + if( (int)(strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)) != checksum) { Serial.print("Error: checksum mismatch, Last Line:"); Serial.println(gcode_LastN); FlushSerialRequestResend(); @@ -458,7 +458,7 @@ inline void get_command() } if((strstr(cmdbuffer[bufindw], "G") != NULL)){ strchr_pointer = strchr(cmdbuffer[bufindw], 'G'); - switch(atoi(strchr_pointer+1)){ + switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))){ case 0: case 1: #ifdef SDSUPPORT @@ -520,8 +520,8 @@ if(!sdmode || serial_count!=0){ } -inline float code_value() { return strtod(strchr_pointer, NULL); } -inline long code_value_long() { return atol(strchr_pointer); } +inline float code_value() { return (strtod(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL)); } +inline long code_value_long() { return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10)); } inline bool code_seen(char code_string[]) { return (strstr(cmdbuffer[bufindr], code_string) != NULL); } //Return True if the string was found inline bool code_seen(char code) -- cgit v1.2.1 From 253a4edc56dc9abffec46044ff11749551ccf3fa Mon Sep 17 00:00:00 2001 From: rotorit Date: Sun, 25 Sep 2011 17:36:58 +0300 Subject: Edited Sprinter/pins.h via GitHub --- Sprinter/pins.h | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/Sprinter/pins.h b/Sprinter/pins.h index fd9995d..e88f650 100644 --- a/Sprinter/pins.h +++ b/Sprinter/pins.h @@ -204,7 +204,7 @@ #endif /**************************************************************************************** -* Gen3 PLUS +* Gen3 PLUS for RepRap Motherboard V1.2 * ****************************************************************************************/ #if MOTHERBOARD == 21 @@ -246,7 +246,7 @@ #define HEATER_0_PIN 12 //Pin for heated bed heater -#define HEATER_1_PIN 5 +#define HEATER_1_PIN 16 //pin for debugging. @@ -268,7 +268,7 @@ #endif /**************************************************************************************** -* Gen3 Monolithic Electronics +* Gen3 Monolithic Electronics * ****************************************************************************************/ #if MOTHERBOARD == 22 @@ -326,6 +326,71 @@ #endif +/**************************************************************************************** +* Gen3 PLUS for TechZone Gen3 Remix Motherboard +* +****************************************************************************************/ +#if MOTHERBOARD == 23 +#define KNOWN_BOARD 1 + +#ifndef __AVR_ATmega644P__ + #error Oops! Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu. +#endif + + +//x axis pins +#define X_STEP_PIN 15 +#define X_DIR_PIN 18 +#define X_ENABLE_PIN 24 //same as E/Y_enable_pin +#define X_MIN_PIN 20 +#define X_MAX_PIN -1 + +//y axis pins +#define Y_STEP_PIN 23 +#define Y_DIR_PIN 22 +#define Y_ENABLE_PIN 24 //same as E/X_enable_pin +#define Y_MIN_PIN 25 +#define Y_MAX_PIN -1 + +//z axis pins +#define Z_STEP_PIN 27 +#define Z_DIR_PIN 28 +#define Z_ENABLE_PIN 29 +#define Z_MIN_PIN 30 +#define Z_MAX_PIN -1 + +#define E_DIR_PIN 21 +#define E_STEP_PIN 19 +#define E_ENABLE_PIN 24 //same as X/Y_enable_pin + +//heaters + +//pin for hot end heater +#define HEATER_0_PIN 16 + +//Pin for heated bed heater +#define HEATER_1_PIN 17 + + +//pin for debugging. +#define DEBUG_PIN -1 + +//SD card pin + +#define SDSS 4 + +#define SDPOWER -1 +#define FAN_PIN -1 +#define TEMP_0_PIN 0 +#define TEMP_1_PIN 5 +#define LED_PIN -1 + +//pin for controlling the PSU. +#define PS_ON_PIN 14 + +#endif + + /**************************************************************************************** * Arduino Mega pin assignment * -- cgit v1.2.1 From 0df9fa2891a084b10f84bf71133f2bbb71e5f460 Mon Sep 17 00:00:00 2001 From: rotorit Date: Sun, 25 Sep 2011 17:42:03 +0300 Subject: added Gen3 PLUS for TechZone Gen3 Remix Motherboard and renaming 21 --- Sprinter/Configuration.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index e246e65..3f2dda2 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -9,8 +9,9 @@ // Gen6 = 5, // Sanguinololu up to 1.1 = 6 // Sanguinololu 1.2 and above = 62 -// Gen 3 Plus = 21 +// Gen Gen3 PLUS for RepRap Motherboard V1.2 = 21 // gen 3 Monolithic Electronics = 22 +// Gen3 PLUS for TechZone Gen3 Remix Motherboard = 23 #define MOTHERBOARD 3 //// Thermistor settings: -- cgit v1.2.1 From 7eef2733856dac97dd46f19160cf6fb2eedd198b Mon Sep 17 00:00:00 2001 From: blddk Date: Sun, 16 Oct 2011 15:55:42 +0300 Subject: Added function for controlling controller cooling fan --- Sprinter/Sprinter.pde | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 52910ec..8124f00 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -245,6 +245,10 @@ void setup() if(!E_ENABLE_ON) WRITE(E_ENABLE_PIN,HIGH); #endif + #ifdef CONTROLLERFAN_PIN + SET_OUTPUT(CONTROLLERFAN_PIN); //Set pin used for driver cooling fan + #endif + //endstops and pullups #ifdef ENDSTOPPULLUPS #if X_MIN_PIN > -1 @@ -1441,6 +1445,32 @@ int read_max6675() } #endif +#ifdef CONTROLLERFAN_PIN +unsigned long lastMotor = 0; //Save the time for when a motor was turned on last +unsigned long lastMotorCheck = 0; + +void controllerFan() +{ + if ((millis() - lastMotorCheck) >= 2500) //Not a time critical function, so we only check every 2500ms + { + lastMotorCheck = millis(); + + if(!digitalRead(X_ENABLE_PIN) || !digitalRead(Y_ENABLE_PIN) || !digitalRead(Z_ENABLE_PIN) || !digitalRead(E_ENABLE_PIN)) //If any of the drivers are enabled... + { + lastMotor = millis(); //... set time to NOW so the fan will turn on + } + + if ((millis() - lastMotor) >= (CONTROLLERFAN_SEC*1000) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC... + { + digitalWrite(CONTROLLERFAN_PIN, LOW); //... turn the fan off + } + else + { + digitalWrite(CONTROLLERFAN_PIN, HIGH); //... turn the fan on + } + } +} +#endif void manage_heater() { @@ -1579,6 +1609,10 @@ void manage_heater() WRITE(HEATER_1_PIN,HIGH); } #endif + +#ifdef CONTROLLERFAN_PIN + controllerFan(); //Check if fan should be turned on to cool stepper drivers down +#endif } #if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR) -- cgit v1.2.1 From a584adc97f791fc3f9d71e6612db135d492df888 Mon Sep 17 00:00:00 2001 From: blddk Date: Sun, 16 Oct 2011 15:56:21 +0300 Subject: Added options for the controller cooling fan --- Sprinter/Configuration.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index 3f2dda2..8c73f57 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -179,6 +179,12 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; #define BED_USES_THERMISTOR //#define BED_USES_AD595 +//This is for controlling a fan to cool down the stepper drivers +//it will turn on when any driver is enabled +//and turn off after the set amount of seconds from last driver being disabled again +#define CONTROLLERFAN_PIN 23 //Pin used for the fan to cool controller, comment out to disable this function +#define CONTROLLERFAN_SEC 60 //How many seconds, after all motors were disabled, the fan should run + // Uncomment the following line to enable debugging. You can better control debugging below the following line //#define DEBUG #ifdef DEBUG -- cgit v1.2.1 From c62f9388144c6723541e26a9cdf4e0e7c9f234aa Mon Sep 17 00:00:00 2001 From: blddk Date: Sun, 16 Oct 2011 16:18:50 +0300 Subject: Update Sprinter/Configuration.h --- Sprinter/Configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h index 8c73f57..a3a5d59 100644 --- a/Sprinter/Configuration.h +++ b/Sprinter/Configuration.h @@ -182,7 +182,7 @@ char uuid[] = "00000000-0000-0000-0000-000000000000"; //This is for controlling a fan to cool down the stepper drivers //it will turn on when any driver is enabled //and turn off after the set amount of seconds from last driver being disabled again -#define CONTROLLERFAN_PIN 23 //Pin used for the fan to cool controller, comment out to disable this function +//#define CONTROLLERFAN_PIN 23 //Pin used for the fan to cool controller, comment out to disable this function #define CONTROLLERFAN_SEC 60 //How many seconds, after all motors were disabled, the fan should run // Uncomment the following line to enable debugging. You can better control debugging below the following line -- cgit v1.2.1 From cc1bb0fc0825ca7997b3c21ae744972a1b22a6f9 Mon Sep 17 00:00:00 2001 From: blddk Date: Sun, 16 Oct 2011 16:26:08 +0300 Subject: Update Sprinter/Sprinter.pde --- Sprinter/Sprinter.pde | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 8124f00..9b694fd 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -1455,18 +1455,18 @@ void controllerFan() { lastMotorCheck = millis(); - if(!digitalRead(X_ENABLE_PIN) || !digitalRead(Y_ENABLE_PIN) || !digitalRead(Z_ENABLE_PIN) || !digitalRead(E_ENABLE_PIN)) //If any of the drivers are enabled... + if(!READ(X_ENABLE_PIN) || !READ(Y_ENABLE_PIN) || !READ(Z_ENABLE_PIN) || !READ(E_ENABLE_PIN)) //If any of the drivers are enabled... { lastMotor = millis(); //... set time to NOW so the fan will turn on } if ((millis() - lastMotor) >= (CONTROLLERFAN_SEC*1000) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC... { - digitalWrite(CONTROLLERFAN_PIN, LOW); //... turn the fan off + WRITE(CONTROLLERFAN_PIN, LOW); //... turn the fan off } else { - digitalWrite(CONTROLLERFAN_PIN, HIGH); //... turn the fan on + WRITE(CONTROLLERFAN_PIN, HIGH); //... turn the fan on } } } -- cgit v1.2.1 From 588109f0984eeeb1f97dee956f26c9cecea1c806 Mon Sep 17 00:00:00 2001 From: blddk Date: Sun, 16 Oct 2011 16:29:59 +0300 Subject: Update Sprinter/Sprinter.pde --- Sprinter/Sprinter.pde | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index 9b694fd..ca3e0e9 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -1460,7 +1460,7 @@ void controllerFan() lastMotor = millis(); //... set time to NOW so the fan will turn on } - if ((millis() - lastMotor) >= (CONTROLLERFAN_SEC*1000) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC... + if ((millis() - lastMotor) >= (CONTROLLERFAN_SEC*1000L) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC... { WRITE(CONTROLLERFAN_PIN, LOW); //... turn the fan off } -- cgit v1.2.1 From f63468b74788d6c9efd7d7a2bf9174c99d0044ca Mon Sep 17 00:00:00 2001 From: blddk Date: Sun, 16 Oct 2011 16:31:56 +0300 Subject: Update Sprinter/Sprinter.pde --- Sprinter/Sprinter.pde | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde index ca3e0e9..7a6bf5e 100644 --- a/Sprinter/Sprinter.pde +++ b/Sprinter/Sprinter.pde @@ -1460,7 +1460,7 @@ void controllerFan() lastMotor = millis(); //... set time to NOW so the fan will turn on } - if ((millis() - lastMotor) >= (CONTROLLERFAN_SEC*1000L) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC... + if ((millis() - lastMotor) >= (CONTROLLERFAN_SEC*1000UL) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC... { WRITE(CONTROLLERFAN_PIN, LOW); //... turn the fan off } -- cgit v1.2.1