Commit b5a673fa authored by MagoKimbra's avatar MagoKimbra

Fix Temperature.cpp width arduino 1.6

parent 12485790
...@@ -210,7 +210,7 @@ static void updateTemperaturesFromRawValues(); ...@@ -210,7 +210,7 @@ static void updateTemperaturesFromRawValues();
#endif //WATCH_TEMP_PERIOD #endif //WATCH_TEMP_PERIOD
#ifndef SOFT_PWM_SCALE #ifndef SOFT_PWM_SCALE
#define SOFT_PWM_SCALE 0 #define SOFT_PWM_SCALE 0
#endif #endif
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
...@@ -242,18 +242,19 @@ void PID_autotune(float temp, int extruder, int ncycles) ...@@ -242,18 +242,19 @@ void PID_autotune(float temp, int extruder, int ncycles)
float Kp, Ki, Kd; float Kp, Ki, Kd;
float max = 0, min = 10000; float max = 0, min = 10000;
#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \ #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) || \ (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1) (defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1)
unsigned long extruder_autofan_last_check = millis(); unsigned long extruder_autofan_last_check = millis();
#endif #endif
if ((extruder >= EXTRUDERS)
#if (TEMP_BED_PIN <= -1) #if (TEMP_BED_PIN <= -1)
||(extruder < 0) if ((extruder >= EXTRUDERS) || (extruder < 0))
#else
if (extruder >= EXTRUDERS)
#endif #endif
){ {
SERIAL_ECHOLN("PID Autotune failed. Bad extruder number."); SERIAL_ECHOLN("PID Autotune failed. Bad extruder number.");
return; return;
} }
...@@ -273,9 +274,6 @@ void PID_autotune(float temp, int extruder, int ncycles) ...@@ -273,9 +274,6 @@ void PID_autotune(float temp, int extruder, int ncycles)
bias = d = (PID_MAX)/2; bias = d = (PID_MAX)/2;
} }
for(;;) { for(;;) {
if(temp_meas_ready == true) { // temp sample ready if(temp_meas_ready == true) { // temp sample ready
...@@ -517,8 +515,8 @@ void checkExtruderAutoFans() ...@@ -517,8 +515,8 @@ void checkExtruderAutoFans()
void manage_heater() void manage_heater()
{ {
float pid_input; static float pid_input;
float pid_output; static float pid_output;
if(temp_meas_ready != true) //better readability if(temp_meas_ready != true) //better readability
return; return;
...@@ -526,23 +524,24 @@ void manage_heater() ...@@ -526,23 +524,24 @@ void manage_heater()
updateTemperaturesFromRawValues(); updateTemperaturesFromRawValues();
#ifdef HEATER_0_USES_MAX6675 #ifdef HEATER_0_USES_MAX6675
if (current_temperature[0] > 1023 || current_temperature[0] > HEATER_0_MAXTEMP) { if (current_temperature[0] > 1023 || current_temperature[0] > HEATER_0_MAXTEMP)
{
max_temp_error(0); max_temp_error(0);
} }
if (current_temperature[0] == 0 || current_temperature[0] < HEATER_0_MINTEMP) { if (current_temperature[0] == 0 || current_temperature[0] < HEATER_0_MINTEMP)
{
min_temp_error(0); min_temp_error(0);
} }
#endif //HEATER_0_USES_MAX6675 #endif //HEATER_0_USES_MAX6675
#ifndef SINGLENOZZLE #ifndef SINGLENOZZLE
for(int e = 0; e < EXTRUDERS; e++) for(int e = 0; e < EXTRUDERS; e++)
{ #else
#else
for(int e = 0; e < 1; e++) for(int e = 0; e < 1; e++)
#endif // !SINLGENOZZE
{ {
#endif // !SINLGENOZZE
#if defined (THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0 #if defined (THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0
thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_RUNAWAY_PROTECTION_PERIOD, THERMAL_RUNAWAY_PROTECTION_HYSTERESIS); thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_RUNAWAY_PROTECTION_PERIOD, THERMAL_RUNAWAY_PROTECTION_HYSTERESIS);
#endif #endif
...@@ -551,16 +550,20 @@ void manage_heater() ...@@ -551,16 +550,20 @@ void manage_heater()
#ifndef PID_OPENLOOP #ifndef PID_OPENLOOP
pid_error[e] = target_temperature[e] - pid_input; pid_error[e] = target_temperature[e] - pid_input;
if(pid_error[e] > PID_FUNCTIONAL_RANGE) { if(pid_error[e] > PID_FUNCTIONAL_RANGE)
{
pid_output = BANG_MAX; pid_output = BANG_MAX;
pid_reset[e] = true; pid_reset[e] = true;
} }
else if(pid_error[e] < -PID_FUNCTIONAL_RANGE || target_temperature[e] == 0) { else if(pid_error[e] < -PID_FUNCTIONAL_RANGE || target_temperature[e] == 0)
{
pid_output = 0; pid_output = 0;
pid_reset[e] = true; pid_reset[e] = true;
} }
else { else
if(pid_reset[e] == true) { {
if(pid_reset[e] == true)
{
temp_iState[e] = 0.0; temp_iState[e] = 0.0;
pid_reset[e] = false; pid_reset[e] = false;
} }
...@@ -573,10 +576,12 @@ void manage_heater() ...@@ -573,10 +576,12 @@ void manage_heater()
#define K2 (1.0-K1) #define K2 (1.0-K1)
dTerm[e] = (Kd[e] * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]); dTerm[e] = (Kd[e] * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
pid_output = pTerm[e] + iTerm[e] - dTerm[e]; pid_output = pTerm[e] + iTerm[e] - dTerm[e];
if (pid_output > PID_MAX) { if (pid_output > PID_MAX)
{
if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration
pid_output=PID_MAX; pid_output=PID_MAX;
} else if (pid_output < 0){ } else if (pid_output < 0)
{
if (pid_error[e] < 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration if (pid_error[e] < 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration
pid_output=0; pid_output=0;
} }
...@@ -585,6 +590,7 @@ void manage_heater() ...@@ -585,6 +590,7 @@ void manage_heater()
#else #else
pid_output = constrain(target_temperature[e], 0, PID_MAX); pid_output = constrain(target_temperature[e], 0, PID_MAX);
#endif //PID_OPENLOOP #endif //PID_OPENLOOP
#ifdef PID_DEBUG #ifdef PID_DEBUG
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHO(" PID_DEBUG "); SERIAL_ECHO(" PID_DEBUG ");
...@@ -600,19 +606,21 @@ void manage_heater() ...@@ -600,19 +606,21 @@ void manage_heater()
SERIAL_ECHO(" dTerm "); SERIAL_ECHO(" dTerm ");
SERIAL_ECHOLN(dTerm[e]); SERIAL_ECHOLN(dTerm[e]);
#endif //PID_DEBUG #endif //PID_DEBUG
#else /* PID off */ #else //NO PIDTEMP
pid_output = 0; pid_output = 0;
if(current_temperature[e] < target_temperature[e]) { if(current_temperature[e] < target_temperature[e])
{
pid_output = PID_MAX; pid_output = PID_MAX;
} }
#endif #endif //PIDTEMP
// Check if temperature is within the correct range // Check if temperature is within the correct range
if((current_temperature[e] > minttemp[e]) && (current_temperature[e] < maxttemp[e])) if((current_temperature[e] > minttemp[e]) && (current_temperature[e] < maxttemp[e]))
{ {
soft_pwm[e] = (int)pid_output >> 1; soft_pwm[e] = (int)pid_output >> 1;
} }
else { else
{
soft_pwm[e] = 0; soft_pwm[e] = 0;
} }
...@@ -625,15 +633,20 @@ void manage_heater() ...@@ -625,15 +633,20 @@ void manage_heater()
LCD_MESSAGEPGM("Heating failed"); LCD_MESSAGEPGM("Heating failed");
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLN("Heating failed"); SERIAL_ECHOLN("Heating failed");
}else{ }
else
{
watchmillis[e] = 0; watchmillis[e] = 0;
} }
} }
#endif #endif //WATCH_TEMP_PERIOD
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #ifdef TEMP_SENSOR_1_AS_REDUNDANT
if(fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) { if(fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF)
{
disable_heater(); disable_heater();
if(IsStopped() == false) { if(IsStopped() == false)
{
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Extruder switched off. Temperature difference between temp sensors is too high !"); SERIAL_ERRORLNPGM("Extruder switched off. Temperature difference between temp sensors is too high !");
LCD_ALERTMESSAGEPGM("Err: REDUNDANT TEMP ERROR"); LCD_ALERTMESSAGEPGM("Err: REDUNDANT TEMP ERROR");
...@@ -642,7 +655,7 @@ void manage_heater() ...@@ -642,7 +655,7 @@ void manage_heater()
Stop(); Stop();
#endif #endif
} }
#endif #endif //TEMP_SENSOR_1_AS_REDUNDANT
} // End extruder for loop } // End extruder for loop
#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \ #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment