Fixed AUTOTEMP (M109 S215 B260 F1 starts autotemp)

Changed SLOWDOWN. IF this does not work ok OLD_SLOWDOWN is the old algo.
This commit is contained in:
Erik van der Zalm
2012-04-15 19:17:33 +02:00
parent 8aee9d51b6
commit 67cf105bc6
7 changed files with 97 additions and 115 deletions

View File

@ -95,17 +95,6 @@ static unsigned long previous_millis_bed_heater;
static int maxttemp[EXTRUDERS] = { 16383 }; // the first value used for all
static int bed_minttemp = 0;
static int bed_maxttemp = 16383;
static int heater_pin_map[EXTRUDERS] = { HEATER_0_PIN
#if EXTRUDERS > 1
, HEATER_1_PIN
#endif
#if EXTRUDERS > 2
, HEATER_2_PIN
#endif
#if EXTRUDERS > 3
#error Unsupported number of extruders
#endif
};
static void *heater_ttbl_map[EXTRUDERS] = { (void *)heater_0_temptable
#if EXTRUDERS > 1
, (void *)heater_1_temptable
@ -138,7 +127,6 @@ void PID_autotune(float temp)
float input;
int cycles=0;
bool heating = true;
soft_pwm[0] = 255>>1;
unsigned long temp_millis = millis();
unsigned long t1=temp_millis;
@ -154,8 +142,10 @@ void PID_autotune(float temp)
SERIAL_ECHOLN("PID Autotune start");
//disable_heater(); // switch off all heaters.
disable_heater(); // switch off all heaters.
soft_pwm[0] = 255>>1;
for(;;) {
if(temp_meas_ready == true) { // temp sample ready
@ -202,6 +192,7 @@ void PID_autotune(float temp)
SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
/*
Kp = 0.33*Ku;
Ki = Kp/Tu;
Kd = Kp*Tu/3;
@ -216,6 +207,7 @@ void PID_autotune(float temp)
SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
*/
}
}
soft_pwm[0] = (bias + d) >> 1;
@ -225,7 +217,7 @@ void PID_autotune(float temp)
}
}
if(input > (temp + 20)) {
SERIAL_PROTOCOLLNPGM("PID Autotune failed !, Temperature to high");
SERIAL_PROTOCOLLNPGM("PID Autotune failed! Temperature to high");
return;
}
if(millis() - temp_millis > 2000) {
@ -235,6 +227,14 @@ void PID_autotune(float temp)
SERIAL_PROTOCOLPGM(" @:");
SERIAL_PROTOCOLLN(getHeaterPower(0));
}
if(((millis() - t1) + (millis() - t2)) > (10L*60L*1000L*2L)) {
SERIAL_PROTOCOLLNPGM("PID Autotune failed! timeout");
return;
}
if(cycles > 5) {
SERIAL_PROTOCOLLNPGM("PID Autotune finished ! Place the Kp, Ki and Kd constants in the configuration.h");
return;
}
LCD_STATUS;
}
}
@ -313,11 +313,9 @@ void manage_heater()
// Check if temperature is within the correct range
if((current_raw[e] > minttemp[e]) && (current_raw[e] < maxttemp[e]))
{
//analogWrite(heater_pin_map[e], pid_output);
soft_pwm[e] = (int)pid_output >> 1;
}
else {
//analogWrite(heater_pin_map[e], 0);
soft_pwm[e] = 0;
}
} // End extruder for loop
@ -680,7 +678,7 @@ void disable_heater()
target_raw[0]=0;
soft_pwm[0]=0;
#if HEATER_0_PIN > -1
digitalWrite(HEATER_0_PIN,LOW);
WRITE(HEATER_0_PIN,LOW);
#endif
#endif
@ -688,7 +686,7 @@ void disable_heater()
target_raw[1]=0;
soft_pwm[1]=0;
#if HEATER_1_PIN > -1
digitalWrite(HEATER_1_PIN,LOW);
WRITE(HEATER_1_PIN,LOW);
#endif
#endif
@ -696,20 +694,20 @@ void disable_heater()
target_raw[2]=0;
soft_pwm[2]=0;
#if HEATER_2_PIN > -1
digitalWrite(HEATER_2_PIN,LOW);
WRITE(HEATER_2_PIN,LOW);
#endif
#endif
#if TEMP_BED_PIN > -1
target_raw_bed=0;
#if HEATER_BED_PIN > -1
digitalWrite(HEATER_BED_PIN,LOW);
WRITE(HEATER_BED_PIN,LOW);
#endif
#endif
}
void max_temp_error(uint8_t e) {
digitalWrite(heater_pin_map[e], 0);
disable_heater();
if(IsStopped() == false) {
SERIAL_ERROR_START;
SERIAL_ERRORLN(e);
@ -718,7 +716,7 @@ void max_temp_error(uint8_t e) {
}
void min_temp_error(uint8_t e) {
digitalWrite(heater_pin_map[e], 0);
disable_heater();
if(IsStopped() == false) {
SERIAL_ERROR_START;
SERIAL_ERRORLN(e);
@ -727,7 +725,7 @@ void min_temp_error(uint8_t e) {
}
void bed_max_temp_error(void) {
digitalWrite(HEATER_BED_PIN, 0);
WRITE(HEATER_BED_PIN, 0);
if(IsStopped() == false) {
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");