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(+) (limited to 'Sprinter') 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(+) (limited to 'Sprinter') 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(-) (limited to 'Sprinter') 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(+) (limited to 'Sprinter') 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(-) (limited to 'Sprinter') 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(-) (limited to 'Sprinter') 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 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(-) (limited to 'Sprinter') 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(+) (limited to 'Sprinter') 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