Store unscaled PID values in EEPROM (#15884)

This commit is contained in:
Scott Lahteine 2019-11-13 01:47:46 -06:00 committed by GitHub
parent 7e9c846ec3
commit a4709ba765
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,7 +37,7 @@
*/ */
// Change EEPROM version if the structure changes // Change EEPROM version if the structure changes
#define EEPROM_VERSION "V70" #define EEPROM_VERSION "V71"
#define EEPROM_OFFSET 100 #define EEPROM_OFFSET 100
// Check the integrity of data offsets. // Check the integrity of data offsets.
@ -788,7 +788,10 @@ void MarlinSettings::postprocess() {
_FIELD_TEST(hotendPID); _FIELD_TEST(hotendPID);
HOTEND_LOOP() { HOTEND_LOOP() {
PIDC_t pidc = { PIDC_t pidc = {
PID_PARAM(Kp, e), PID_PARAM(Ki, e), PID_PARAM(Kd, e), PID_PARAM(Kc, e) PID_PARAM(Kp, e),
unscalePID_i(PID_PARAM(Ki, e)),
unscalePID_d(PID_PARAM(Kd, e)),
PID_PARAM(Kc, e)
}; };
EEPROM_WRITE(pidc); EEPROM_WRITE(pidc);
} }
@ -808,12 +811,17 @@ void MarlinSettings::postprocess() {
{ {
_FIELD_TEST(bedPID); _FIELD_TEST(bedPID);
const PID_t bed_pid = {
#if DISABLED(PIDTEMPBED) #if DISABLED(PIDTEMPBED)
const PID_t bed_pid = { DUMMY_PID_VALUE, DUMMY_PID_VALUE, DUMMY_PID_VALUE }; DUMMY_PID_VALUE, DUMMY_PID_VALUE, DUMMY_PID_VALUE
EEPROM_WRITE(bed_pid);
#else #else
EEPROM_WRITE(thermalManager.temp_bed.pid); // Store the unscaled PID values
thermalManager.temp_bed.pid.Kp,
unscalePID_i(thermalManager.temp_bed.pid.Ki),
unscalePID_d(thermalManager.temp_bed.pid.Kd)
#endif #endif
};
EEPROM_WRITE(bed_pid);
} }
// //
@ -1585,10 +1593,10 @@ void MarlinSettings::postprocess() {
EEPROM_READ(pidc); EEPROM_READ(pidc);
#if ENABLED(PIDTEMP) #if ENABLED(PIDTEMP)
if (!validating && pidc.Kp != DUMMY_PID_VALUE) { if (!validating && pidc.Kp != DUMMY_PID_VALUE) {
// No need to scale PID values since EEPROM values are scaled // Scale PID values since EEPROM values are unscaled
PID_PARAM(Kp, e) = pidc.Kp; PID_PARAM(Kp, e) = pidc.Kp;
PID_PARAM(Ki, e) = pidc.Ki; PID_PARAM(Ki, e) = scalePID_i(pidc.Ki);
PID_PARAM(Kd, e) = pidc.Kd; PID_PARAM(Kd, e) = scalePID_d(pidc.Kd);
#if ENABLED(PID_EXTRUSION_SCALING) #if ENABLED(PID_EXTRUSION_SCALING)
PID_PARAM(Kc, e) = pidc.Kc; PID_PARAM(Kc, e) = pidc.Kc;
#endif #endif
@ -1617,8 +1625,12 @@ void MarlinSettings::postprocess() {
PID_t pid; PID_t pid;
EEPROM_READ(pid); EEPROM_READ(pid);
#if ENABLED(PIDTEMPBED) #if ENABLED(PIDTEMPBED)
if (!validating && pid.Kp != DUMMY_PID_VALUE) if (!validating && pid.Kp != DUMMY_PID_VALUE) {
memcpy(&thermalManager.temp_bed.pid, &pid, sizeof(pid)); // Scale PID values since EEPROM values are unscaled
thermalManager.temp_bed.pid.Kp = pid.Kp;
thermalManager.temp_bed.pid.Ki = scalePID_i(pid.Ki);
thermalManager.temp_bed.pid.Kd = scalePID_d(pid.Kd);
}
#endif #endif
} }