From 4d73db3b640c9cf4760ad945697dc72026b309e7 Mon Sep 17 00:00:00 2001 From: jmgiacalone Date: Sun, 15 May 2011 20:05:11 +0100 Subject: Heat interval check coded only once inside manage_heater() --- Tonokip_Firmware/Tonokip_Firmware.pde | 189 ++++++++++++++++------------------ 1 file changed, 86 insertions(+), 103 deletions(-) (limited to 'Tonokip_Firmware') diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index 5faf413..ed8027a 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -297,12 +297,8 @@ void loop() bufindr = (bufindr + 1)%BUFSIZE; } //check heater every n milliseconds - if((millis() - previous_millis_heater) >= HEATER_CHECK_INTERVAL ) { manage_heater(); - previous_millis_heater = millis(); - manage_inactivity(1); - } } @@ -466,10 +462,7 @@ inline void process_commands() if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait codenum += millis(); // keep track of when we started waiting while(millis() < codenum ){ - if((millis() - previous_millis_heater) >= HEATER_CHECK_INTERVAL ) { - manage_heater(); - previous_millis_heater = millis(); - } + manage_heater(); } break; case 28: //G28 Home all Axis one at a time @@ -706,10 +699,7 @@ inline void process_commands() Serial.println( analog2temp(current_raw) ); codenum = millis(); } - if((millis() - previous_millis_heater) >= HEATER_CHECK_INTERVAL ) { - manage_heater(); - previous_millis_heater = millis(); - } + manage_heater(); } break; case 190: // M190 - Wait bed for heater to reach target. @@ -728,10 +718,7 @@ inline void process_commands() Serial.println( analog2temp(current_bed_raw) ); codenum = millis(); } - if((millis() - previous_millis_heater) >= HEATER_CHECK_INTERVAL ) { manage_heater(); - previous_millis_heater = millis(); - } } #endif break; @@ -976,10 +963,7 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin if(z_steps_remaining) { enable_z(); do_z_step(); z_steps_remaining--; } if(e_steps_remaining) { enable_e(); do_e_step(); e_steps_remaining--; } - - previous_millis_heater = millis(); - - //Define variables that are needed for the Bresenham algorithm. Please note that Z is not currently included in the Bresenham algorithm. + //Define variables that are needed for the Bresenham algorithm. Please note that Z is not currently included in the Bresenham algorithm. unsigned int delta_x = x_steps_remaining; unsigned long x_interval_nanos; unsigned int delta_y = y_steps_remaining; @@ -1079,12 +1063,8 @@ void linear_move(unsigned long x_steps_remaining, unsigned long y_steps_remainin //move until no more steps remain while(x_steps_remaining + y_steps_remaining + z_steps_remaining + e_steps_remaining > 0) { //If more that HEATER_CHECK_INTERVAL ms have passed since previous heating check, adjust temp - if((millis() - previous_millis_heater) >= HEATER_CHECK_INTERVAL ) { - manage_heater(); - previous_millis_heater = millis(); - - manage_inactivity(2); - } + manage_heater(); + manage_inactivity(2); #ifdef RAMP_ACCELERATION //If acceleration is enabled on this move and we are in the acceleration segment, calculate the current interval if (acceleration_enabled && steps_done == 0) { @@ -1359,91 +1339,94 @@ inline int read_max6675() inline void manage_heater() { - #ifdef HEATER_USES_THERMISTOR - current_raw = analogRead(TEMP_0_PIN); - // When using thermistor, when the heater is colder than targer temp, we get a higher analog reading than target, - // this switches it up so that the reading appears lower than target for the control logic. - current_raw = 1023 - current_raw; - #elif defined HEATER_USES_AD595 - current_raw = analogRead(TEMP_0_PIN); - #elif defined HEATER_USES_MAX6675 - current_raw = read_max6675(); - #endif - #ifdef SMOOTHING - nma = (nma + current_raw) - (nma / SMOOTHFACTOR); - current_raw = nma / SMOOTHFACTOR; - #endif - #ifdef WATCHPERIOD - if(watchmillis && millis() - watchmillis > WATCHPERIOD){ - if(watch_raw + 1 >= current_raw){ - target_raw = 0; - digitalWrite(HEATER_0_PIN,LOW); - digitalWrite(LED_PIN,LOW); - }else{ - watchmillis = 0; + if((millis() - previous_millis_heater) >= HEATER_CHECK_INTERVAL ) { + previous_millis_heater = millis(); + #ifdef HEATER_USES_THERMISTOR + current_raw = analogRead(TEMP_0_PIN); + // When using thermistor, when the heater is colder than targer temp, we get a higher analog reading than target, + // this switches it up so that the reading appears lower than target for the control logic. + current_raw = 1023 - current_raw; + #elif defined HEATER_USES_AD595 + current_raw = analogRead(TEMP_0_PIN); + #elif defined HEATER_USES_MAX6675 + current_raw = read_max6675(); + #endif + #ifdef SMOOTHING + nma = (nma + current_raw) - (nma / SMOOTHFACTOR); + current_raw = nma / SMOOTHFACTOR; + #endif + #ifdef WATCHPERIOD + if(watchmillis && millis() - watchmillis > WATCHPERIOD){ + if(watch_raw + 1 >= current_raw){ + target_raw = 0; + digitalWrite(HEATER_0_PIN,LOW); + digitalWrite(LED_PIN,LOW); + }else{ + watchmillis = 0; + } + } + #endif + #ifdef MINTEMP + if(current_raw <= minttemp) + target_raw = 0; + #endif + #ifdef MAXTEMP + if(current_raw >= maxttemp) { + target_raw = 0; + } + #endif + #if (TEMP_0_PIN > -1) || defined (HEATER_USES_MAX66675) + #ifdef PIDTEMP + error = target_raw - current_raw; + pTerm = (PID_PGAIN * error) / 100; + 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, PID_MAX)); + #else + if(current_raw >= target_raw) + { + digitalWrite(HEATER_0_PIN,LOW); + digitalWrite(LED_PIN,LOW); } - } - #endif - #ifdef MINTEMP - if(current_raw <= minttemp) - target_raw = 0; - #endif - #ifdef MAXTEMP - if(current_raw >= maxttemp) { - target_raw = 0; - } - #endif - #if (TEMP_0_PIN > -1) || defined (HEATER_USES_MAX66675) - #ifdef PIDTEMP - error = target_raw - current_raw; - pTerm = (PID_PGAIN * error) / 100; - 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, PID_MAX)); - #else - if(current_raw >= target_raw) + else + { + digitalWrite(HEATER_0_PIN,HIGH); + digitalWrite(LED_PIN,HIGH); + } + #endif + #endif + + if(millis() - previous_millis_bed_heater < 5000) + return; + previous_millis_bed_heater = millis(); + + #ifdef BED_USES_THERMISTOR + + current_bed_raw = analogRead(TEMP_1_PIN); + + // If using thermistor, when the heater is colder than targer temp, we get a higher analog reading than target, + // this switches it up so that the reading appears lower than target for the control logic. + current_bed_raw = 1023 - current_bed_raw; + #elif defined BED_USES_AD595 + current_bed_raw = analogRead(TEMP_1_PIN); + + #endif + + + #if TEMP_1_PIN > -1 + if(current_bed_raw >= target_bed_raw) { - digitalWrite(HEATER_0_PIN,LOW); - digitalWrite(LED_PIN,LOW); + digitalWrite(HEATER_1_PIN,LOW); } else { - digitalWrite(HEATER_0_PIN,HIGH); - digitalWrite(LED_PIN,HIGH); + digitalWrite(HEATER_1_PIN,HIGH); } #endif - #endif - - if(millis() - previous_millis_bed_heater < 5000) - return; - previous_millis_bed_heater = millis(); - - #ifdef BED_USES_THERMISTOR - - current_bed_raw = analogRead(TEMP_1_PIN); - - // If using thermistor, when the heater is colder than targer temp, we get a higher analog reading than target, - // this switches it up so that the reading appears lower than target for the control logic. - current_bed_raw = 1023 - current_bed_raw; - #elif defined BED_USES_AD595 - current_bed_raw = analogRead(TEMP_1_PIN); - - #endif - - - #if TEMP_1_PIN > -1 - if(current_bed_raw >= target_bed_raw) - { - digitalWrite(HEATER_1_PIN,LOW); - } - else - { - digitalWrite(HEATER_1_PIN,HIGH); - } - #endif + } } // Takes hot end temperature value as input and returns corresponding raw value. -- cgit v1.2.1 From 2ec7c37669c7042358fc29d09076f9884e63837b Mon Sep 17 00:00:00 2001 From: jmgiacalone Date: Sun, 15 May 2011 20:21:02 +0100 Subject: Heat interval checked inside manage_heater --- Tonokip_Firmware/Tonokip_Firmware.pde | 158 +++++++++++++++++----------------- 1 file changed, 79 insertions(+), 79 deletions(-) (limited to 'Tonokip_Firmware') diff --git a/Tonokip_Firmware/Tonokip_Firmware.pde b/Tonokip_Firmware/Tonokip_Firmware.pde index ed8027a..9121093 100644 --- a/Tonokip_Firmware/Tonokip_Firmware.pde +++ b/Tonokip_Firmware/Tonokip_Firmware.pde @@ -1339,94 +1339,94 @@ inline int read_max6675() inline void manage_heater() { - if((millis() - previous_millis_heater) >= HEATER_CHECK_INTERVAL ) { - previous_millis_heater = millis(); - #ifdef HEATER_USES_THERMISTOR - current_raw = analogRead(TEMP_0_PIN); - // When using thermistor, when the heater is colder than targer temp, we get a higher analog reading than target, - // this switches it up so that the reading appears lower than target for the control logic. - current_raw = 1023 - current_raw; - #elif defined HEATER_USES_AD595 - current_raw = analogRead(TEMP_0_PIN); - #elif defined HEATER_USES_MAX6675 - current_raw = read_max6675(); - #endif - #ifdef SMOOTHING - nma = (nma + current_raw) - (nma / SMOOTHFACTOR); - current_raw = nma / SMOOTHFACTOR; - #endif - #ifdef WATCHPERIOD - if(watchmillis && millis() - watchmillis > WATCHPERIOD){ - if(watch_raw + 1 >= current_raw){ - target_raw = 0; - digitalWrite(HEATER_0_PIN,LOW); - digitalWrite(LED_PIN,LOW); - }else{ - watchmillis = 0; - } + if((millis() - previous_millis_heater) < HEATER_CHECK_INTERVAL ) + return; + previous_millis_heater = millis(); + #ifdef HEATER_USES_THERMISTOR + current_raw = analogRead(TEMP_0_PIN); + // When using thermistor, when the heater is colder than targer temp, we get a higher analog reading than target, + // this switches it up so that the reading appears lower than target for the control logic. + current_raw = 1023 - current_raw; + #elif defined HEATER_USES_AD595 + current_raw = analogRead(TEMP_0_PIN); + #elif defined HEATER_USES_MAX6675 + current_raw = read_max6675(); + #endif + #ifdef SMOOTHING + nma = (nma + current_raw) - (nma / SMOOTHFACTOR); + current_raw = nma / SMOOTHFACTOR; + #endif + #ifdef WATCHPERIOD + if(watchmillis && millis() - watchmillis > WATCHPERIOD){ + if(watch_raw + 1 >= current_raw){ + target_raw = 0; + digitalWrite(HEATER_0_PIN,LOW); + digitalWrite(LED_PIN,LOW); + }else{ + watchmillis = 0; + } + } + #endif + #ifdef MINTEMP + if(current_raw <= minttemp) + target_raw = 0; + #endif + #ifdef MAXTEMP + if(current_raw >= maxttemp) { + target_raw = 0; + } + #endif + #if (TEMP_0_PIN > -1) || defined (HEATER_USES_MAX66675) + #ifdef PIDTEMP + error = target_raw - current_raw; + pTerm = (PID_PGAIN * error) / 100; + 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, PID_MAX)); + #else + if(current_raw >= target_raw) + { + digitalWrite(HEATER_0_PIN,LOW); + digitalWrite(LED_PIN,LOW); } - #endif - #ifdef MINTEMP - if(current_raw <= minttemp) - target_raw = 0; - #endif - #ifdef MAXTEMP - if(current_raw >= maxttemp) { - target_raw = 0; + else + { + digitalWrite(HEATER_0_PIN,HIGH); + digitalWrite(LED_PIN,HIGH); } #endif - #if (TEMP_0_PIN > -1) || defined (HEATER_USES_MAX66675) - #ifdef PIDTEMP - error = target_raw - current_raw; - pTerm = (PID_PGAIN * error) / 100; - 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, PID_MAX)); - #else - if(current_raw >= target_raw) - { - digitalWrite(HEATER_0_PIN,LOW); - digitalWrite(LED_PIN,LOW); - } - else - { - digitalWrite(HEATER_0_PIN,HIGH); - digitalWrite(LED_PIN,HIGH); - } - #endif - #endif + #endif - if(millis() - previous_millis_bed_heater < 5000) - return; - previous_millis_bed_heater = millis(); + if(millis() - previous_millis_bed_heater < 5000) + return; + previous_millis_bed_heater = millis(); - #ifdef BED_USES_THERMISTOR + #ifdef BED_USES_THERMISTOR - current_bed_raw = analogRead(TEMP_1_PIN); + current_bed_raw = analogRead(TEMP_1_PIN); - // If using thermistor, when the heater is colder than targer temp, we get a higher analog reading than target, - // this switches it up so that the reading appears lower than target for the control logic. - current_bed_raw = 1023 - current_bed_raw; - #elif defined BED_USES_AD595 - current_bed_raw = analogRead(TEMP_1_PIN); + // If using thermistor, when the heater is colder than targer temp, we get a higher analog reading than target, + // this switches it up so that the reading appears lower than target for the control logic. + current_bed_raw = 1023 - current_bed_raw; + #elif defined BED_USES_AD595 + current_bed_raw = analogRead(TEMP_1_PIN); + + #endif - #endif - - #if TEMP_1_PIN > -1 - if(current_bed_raw >= target_bed_raw) - { - digitalWrite(HEATER_1_PIN,LOW); - } - else - { - digitalWrite(HEATER_1_PIN,HIGH); - } - #endif - } + #if TEMP_1_PIN > -1 + if(current_bed_raw >= target_bed_raw) + { + digitalWrite(HEATER_1_PIN,LOW); + } + else + { + digitalWrite(HEATER_1_PIN,HIGH); + } + #endif } // Takes hot end temperature value as input and returns corresponding raw value. -- cgit v1.2.1