Commit b5a673fa authored by MagoKimbra's avatar MagoKimbra

Fix Temperature.cpp width arduino 1.6

parent 12485790
......@@ -210,7 +210,7 @@ static void updateTemperaturesFromRawValues();
#endif //WATCH_TEMP_PERIOD
#ifndef SOFT_PWM_SCALE
#define SOFT_PWM_SCALE 0
#define SOFT_PWM_SCALE 0
#endif
#ifdef FILAMENT_SENSOR
......@@ -242,18 +242,19 @@ void PID_autotune(float temp, int extruder, int ncycles)
float Kp, Ki, Kd;
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_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1)
unsigned long extruder_autofan_last_check = millis();
#endif
#endif
if ((extruder >= EXTRUDERS)
#if (TEMP_BED_PIN <= -1)
||(extruder < 0)
if ((extruder >= EXTRUDERS) || (extruder < 0))
#else
if (extruder >= EXTRUDERS)
#endif
){
{
SERIAL_ECHOLN("PID Autotune failed. Bad extruder number.");
return;
}
......@@ -273,9 +274,6 @@ void PID_autotune(float temp, int extruder, int ncycles)
bias = d = (PID_MAX)/2;
}
for(;;) {
if(temp_meas_ready == true) { // temp sample ready
......@@ -517,8 +515,8 @@ void checkExtruderAutoFans()
void manage_heater()
{
float pid_input;
float pid_output;
static float pid_input;
static float pid_output;
if(temp_meas_ready != true) //better readability
return;
......@@ -526,23 +524,24 @@ void manage_heater()
updateTemperaturesFromRawValues();
#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);
}
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);
}
#endif //HEATER_0_USES_MAX6675
#ifndef SINGLENOZZLE
#ifndef SINGLENOZZLE
for(int e = 0; e < EXTRUDERS; e++)
{
#else
#else
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);
#endif
......@@ -551,16 +550,20 @@ void manage_heater()
#ifndef PID_OPENLOOP
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_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_reset[e] = true;
}
else {
if(pid_reset[e] == true) {
else
{
if(pid_reset[e] == true)
{
temp_iState[e] = 0.0;
pid_reset[e] = false;
}
......@@ -573,10 +576,12 @@ void manage_heater()
#define K2 (1.0-K1)
dTerm[e] = (Kd[e] * (pid_input - temp_dState[e]))*K2 + (K1 * 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
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
pid_output=0;
}
......@@ -585,6 +590,7 @@ void manage_heater()
#else
pid_output = constrain(target_temperature[e], 0, PID_MAX);
#endif //PID_OPENLOOP
#ifdef PID_DEBUG
SERIAL_ECHO_START;
SERIAL_ECHO(" PID_DEBUG ");
......@@ -600,19 +606,21 @@ void manage_heater()
SERIAL_ECHO(" dTerm ");
SERIAL_ECHOLN(dTerm[e]);
#endif //PID_DEBUG
#else /* PID off */
#else //NO PIDTEMP
pid_output = 0;
if(current_temperature[e] < target_temperature[e]) {
if(current_temperature[e] < target_temperature[e])
{
pid_output = PID_MAX;
}
#endif
#endif //PIDTEMP
// Check if temperature is within the correct range
if((current_temperature[e] > minttemp[e]) && (current_temperature[e] < maxttemp[e]))
{
soft_pwm[e] = (int)pid_output >> 1;
}
else {
else
{
soft_pwm[e] = 0;
}
......@@ -625,15 +633,20 @@ void manage_heater()
LCD_MESSAGEPGM("Heating failed");
SERIAL_ECHO_START;
SERIAL_ECHOLN("Heating failed");
}else{
}
else
{
watchmillis[e] = 0;
}
}
#endif
#endif //WATCH_TEMP_PERIOD
#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();
if(IsStopped() == false) {
if(IsStopped() == false)
{
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Extruder switched off. Temperature difference between temp sensors is too high !");
LCD_ALERTMESSAGEPGM("Err: REDUNDANT TEMP ERROR");
......@@ -642,7 +655,7 @@ void manage_heater()
Stop();
#endif
}
#endif
#endif //TEMP_SENSOR_1_AS_REDUNDANT
} // End extruder for loop
#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