Browse Source

Store unscaled PID values in EEPROM (#15884)

Scott Lahteine 5 years ago
parent
commit
a4709ba765
No account linked to committer's email address
1 changed files with 25 additions and 13 deletions
  1. 25
    13
      Marlin/src/module/configuration_store.cpp

+ 25
- 13
Marlin/src/module/configuration_store.cpp View File

37
  */
37
  */
38
 
38
 
39
 // Change EEPROM version if the structure changes
39
 // Change EEPROM version if the structure changes
40
-#define EEPROM_VERSION "V70"
40
+#define EEPROM_VERSION "V71"
41
 #define EEPROM_OFFSET 100
41
 #define EEPROM_OFFSET 100
42
 
42
 
43
 // Check the integrity of data offsets.
43
 // Check the integrity of data offsets.
788
       _FIELD_TEST(hotendPID);
788
       _FIELD_TEST(hotendPID);
789
       HOTEND_LOOP() {
789
       HOTEND_LOOP() {
790
         PIDC_t pidc = {
790
         PIDC_t pidc = {
791
-          PID_PARAM(Kp, e), PID_PARAM(Ki, e), PID_PARAM(Kd, e), PID_PARAM(Kc, e)
791
+                       PID_PARAM(Kp, e),
792
+          unscalePID_i(PID_PARAM(Ki, e)),
793
+          unscalePID_d(PID_PARAM(Kd, e)),
794
+                       PID_PARAM(Kc, e)
792
         };
795
         };
793
         EEPROM_WRITE(pidc);
796
         EEPROM_WRITE(pidc);
794
       }
797
       }
808
     {
811
     {
809
       _FIELD_TEST(bedPID);
812
       _FIELD_TEST(bedPID);
810
 
813
 
811
-      #if DISABLED(PIDTEMPBED)
812
-        const PID_t bed_pid = { DUMMY_PID_VALUE, DUMMY_PID_VALUE, DUMMY_PID_VALUE };
813
-        EEPROM_WRITE(bed_pid);
814
-      #else
815
-        EEPROM_WRITE(thermalManager.temp_bed.pid);
816
-      #endif
814
+      const PID_t bed_pid = {
815
+        #if DISABLED(PIDTEMPBED)
816
+          DUMMY_PID_VALUE, DUMMY_PID_VALUE, DUMMY_PID_VALUE
817
+        #else
818
+          // Store the unscaled PID values
819
+          thermalManager.temp_bed.pid.Kp,
820
+          unscalePID_i(thermalManager.temp_bed.pid.Ki),
821
+          unscalePID_d(thermalManager.temp_bed.pid.Kd)
822
+        #endif
823
+      };
824
+      EEPROM_WRITE(bed_pid);
817
     }
825
     }
818
 
826
 
819
     //
827
     //
1585
           EEPROM_READ(pidc);
1593
           EEPROM_READ(pidc);
1586
           #if ENABLED(PIDTEMP)
1594
           #if ENABLED(PIDTEMP)
1587
             if (!validating && pidc.Kp != DUMMY_PID_VALUE) {
1595
             if (!validating && pidc.Kp != DUMMY_PID_VALUE) {
1588
-              // No need to scale PID values since EEPROM values are scaled
1596
+              // Scale PID values since EEPROM values are unscaled
1589
               PID_PARAM(Kp, e) = pidc.Kp;
1597
               PID_PARAM(Kp, e) = pidc.Kp;
1590
-              PID_PARAM(Ki, e) = pidc.Ki;
1591
-              PID_PARAM(Kd, e) = pidc.Kd;
1598
+              PID_PARAM(Ki, e) = scalePID_i(pidc.Ki);
1599
+              PID_PARAM(Kd, e) = scalePID_d(pidc.Kd);
1592
               #if ENABLED(PID_EXTRUSION_SCALING)
1600
               #if ENABLED(PID_EXTRUSION_SCALING)
1593
                 PID_PARAM(Kc, e) = pidc.Kc;
1601
                 PID_PARAM(Kc, e) = pidc.Kc;
1594
               #endif
1602
               #endif
1617
         PID_t pid;
1625
         PID_t pid;
1618
         EEPROM_READ(pid);
1626
         EEPROM_READ(pid);
1619
         #if ENABLED(PIDTEMPBED)
1627
         #if ENABLED(PIDTEMPBED)
1620
-          if (!validating && pid.Kp != DUMMY_PID_VALUE)
1621
-            memcpy(&thermalManager.temp_bed.pid, &pid, sizeof(pid));
1628
+          if (!validating && pid.Kp != DUMMY_PID_VALUE) {
1629
+            // Scale PID values since EEPROM values are unscaled
1630
+            thermalManager.temp_bed.pid.Kp = pid.Kp;
1631
+            thermalManager.temp_bed.pid.Ki = scalePID_i(pid.Ki);
1632
+            thermalManager.temp_bed.pid.Kd = scalePID_d(pid.Kd);
1633
+          }
1622
         #endif
1634
         #endif
1623
       }
1635
       }
1624
 
1636
 

Loading…
Cancel
Save