diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index 1969658d..1b558389 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -124,7 +124,7 @@ void Config_PrintSettings(uint8_t level) ); #ifdef PIDTEMP printf_P(PSTR("%SPID settings:\n%S M301 P%.2f I%.2f D%.2f\n"), - echomagic, echomagic, Kp, unscalePID_i(Ki), unscalePID_d(Kd)); + echomagic, echomagic, cs.Kp, unscalePID_i(cs.Ki), unscalePID_d(cs.Kd)); #endif #ifdef PIDTEMPBED printf_P(PSTR("%SPID heatbed settings:\n%S M304 P%.2f I%.2f D%.2f\n"), diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 63633da4..cc55f0c4 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -6212,9 +6212,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) #ifdef PIDTEMP case 301: // M301 { - if(code_seen('P')) Kp = code_value(); - if(code_seen('I')) Ki = scalePID_i(code_value()); - if(code_seen('D')) Kd = scalePID_d(code_value()); + if(code_seen('P')) cs.Kp = code_value(); + if(code_seen('I')) cs.Ki = scalePID_i(code_value()); + if(code_seen('D')) cs.Kd = scalePID_d(code_value()); #ifdef PID_ADD_EXTRUSION_RATE if(code_seen('C')) Kc = code_value(); @@ -6223,11 +6223,11 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) updatePID(); SERIAL_PROTOCOLRPGM(_T(MSG_OK)); SERIAL_PROTOCOL(" p:"); - SERIAL_PROTOCOL(Kp); + SERIAL_PROTOCOL(cs.Kp); SERIAL_PROTOCOL(" i:"); - SERIAL_PROTOCOL(unscalePID_i(Ki)); + SERIAL_PROTOCOL(unscalePID_i(cs.Ki)); SERIAL_PROTOCOL(" d:"); - SERIAL_PROTOCOL(unscalePID_d(Kd)); + SERIAL_PROTOCOL(unscalePID_d(cs.Kd)); #ifdef PID_ADD_EXTRUSION_RATE SERIAL_PROTOCOL(" c:"); //Kc does not have scaling applied above, or in resetting defaults diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 6a21b825..7054703b 100644 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -39,6 +39,7 @@ #include <avr/wdt.h> #include "adc.h" +#include "ConfigurationStore.h" //=========================================================================== @@ -79,9 +80,6 @@ float current_temperature_bed = 0.0; float _Kp, _Ki, _Kd; int pid_cycle, pid_number_of_cycles; bool pid_tuning_finished = false; - float Kp=DEFAULT_Kp; - float Ki=(DEFAULT_Ki*PID_dT); - float Kd=(DEFAULT_Kd/PID_dT); #ifdef PID_ADD_EXTRUSION_RATE float Kc=DEFAULT_Kc; #endif @@ -422,7 +420,7 @@ void updatePID() { #ifdef PIDTEMP for(int e = 0; e < EXTRUDERS; e++) { - temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki; + temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / cs.Ki; } #endif #ifdef PIDTEMPBED @@ -638,14 +636,14 @@ void manage_heater() temp_iState[e] = 0.0; pid_reset[e] = false; } - pTerm[e] = Kp * pid_error[e]; + pTerm[e] = cs.Kp * pid_error[e]; temp_iState[e] += pid_error[e]; temp_iState[e] = constrain(temp_iState[e], temp_iState_min[e], temp_iState_max[e]); - iTerm[e] = Ki * temp_iState[e]; + iTerm[e] = cs.Ki * temp_iState[e]; //K1 defined in Configuration.h in the PID settings #define K2 (1.0-K1) - dTerm[e] = (Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]); + dTerm[e] = (cs.Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]); pid_output = pTerm[e] + iTerm[e] - dTerm[e]; if (pid_output > PID_MAX) { if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration @@ -1040,7 +1038,7 @@ void tp_init() maxttemp[e] = maxttemp[0]; #ifdef PIDTEMP temp_iState_min[e] = 0.0; - temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki; + temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / cs.Ki; #endif //PIDTEMP #ifdef PIDTEMPBED temp_iState_min_bed = 0.0; diff --git a/Firmware/temperature.h b/Firmware/temperature.h index 0633158c..f2929564 100644 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -73,7 +73,7 @@ extern int current_voltage_raw_bed; #ifdef PIDTEMP extern int pid_cycle, pid_number_of_cycles; - extern float Kp,Ki,Kd,Kc,_Kp,_Ki,_Kd; + extern float Kc,_Kp,_Ki,_Kd; extern bool pid_tuning_finished; float scalePID_i(float i); float scalePID_d(float d);