diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index f705c008..48551ecc 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -85,7 +85,17 @@ float current_temperature_bed = 0.0; #ifdef PIDTEMP float _Kp, _Ki, _Kd; int pid_cycle, pid_number_of_cycles; - bool pid_tuning_finished = true; + static bool pid_tuning_finished = true; + + bool pidTuningRunning() { + return !pid_tuning_finished; + } + + void preparePidTuning() { + // ensure heaters are disabled before we switch off PID management! + disable_heater(); + pid_tuning_finished = false; + } #endif //PIDTEMP unsigned char soft_pwm_bed; @@ -207,8 +217,9 @@ bool checkAllHotends(void) // codegen bug causing a stack overwrite issue in process_commands() void __attribute__((noinline)) PID_autotune(float temp, int extruder, int ncycles) { + preparePidTuning(); + pid_number_of_cycles = ncycles; - pid_tuning_finished = false; float input = 0.0; pid_cycle=0; bool heating = true; @@ -242,8 +253,6 @@ void __attribute__((noinline)) PID_autotune(float temp, int extruder, int ncycle } SERIAL_ECHOLNPGM("PID Autotune start"); - - disable_heater(); // switch off all heaters. if (extruder<0) { diff --git a/Firmware/temperature.h b/Firmware/temperature.h index 08de851f..c62d388a 100755 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -84,11 +84,13 @@ extern bool bedPWMDisabled; #ifdef PIDTEMP extern int pid_cycle, pid_number_of_cycles; extern float _Kp,_Ki,_Kd; - extern bool pid_tuning_finished; float scalePID_i(float i); float scalePID_d(float d); float unscalePID_i(float i); float unscalePID_d(float d); + + bool pidTuningRunning(); // returns true if PID tuning is still running + void preparePidTuning(); // non-blocking call to set "pidTuningRunning" to true immediately #endif diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index c233299a..a7fe85fa 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1018,14 +1018,14 @@ void lcd_commands() lcd_commands_step = 3; } if (lcd_commands_step == 3 && !blocks_queued()) { //PID calibration - pid_tuning_finished = false; // ensure we don't move to the next step early + preparePidTuning(); // ensure we don't move to the next step early sprintf_P(cmd1, PSTR("M303 E0 S%3u"), pid_temp); // setting the correct target temperature (for visualization) is done in PID_autotune enquecommand(cmd1); lcd_setstatuspgm(_i("PID cal."));////MSG_PID_RUNNING c=20 lcd_commands_step = 2; } - if (lcd_commands_step == 2 && pid_tuning_finished) { //saving to eeprom + if (lcd_commands_step == 2 && !pidTuningRunning()) { //saving to eeprom custom_message_state = 0; lcd_setstatuspgm(_i("PID cal. finished"));////MSG_PID_FINISHED c=20 setAllTargetHotends(0); // reset all hotends temperature including the number displayed on the main screen