Browse Source

Merge pull request #1796 from thinkyhead/pidbed_temp_eeprom

Add PIDTEMPBED to EEPROM
Scott Lahteine 9 years ago
parent
commit
c747becec1
2 changed files with 76 additions and 32 deletions
  1. 75
    31
      Marlin/ConfigurationStore.cpp
  2. 1
    1
      Marlin/temperature.h

+ 75
- 31
Marlin/ConfigurationStore.cpp View File

@@ -3,7 +3,21 @@
3 3
  *
4 4
  * Configuration and EEPROM storage
5 5
  *
6
- * V16 EEPROM Layout:
6
+ * IMPORTANT:  Whenever there are changes made to the variables stored in EEPROM
7
+ * in the functions below, also increment the version number. This makes sure that
8
+ * the default values are used whenever there is a change to the data, to prevent
9
+ * wrong data being written to the variables.
10
+ *
11
+ * ALSO: Variables in the Store and Retrieve sections must be in the same order.
12
+ *       If a feature is disabled, some data must still be written that, when read,
13
+ *       either sets a Sane Default, or results in No Change to the existing value.
14
+ *
15
+ */
16
+
17
+#define EEPROM_VERSION "V19"
18
+
19
+/**
20
+ * V19 EEPROM Layout:
7 21
  *
8 22
  *  ver
9 23
  *  axis_steps_per_unit (x4)
@@ -47,6 +61,9 @@
47 61
  *  Kp[2], Ki[2], Kd[2], Kc[2]
48 62
  *  Kp[3], Ki[3], Kd[3], Kc[3]
49 63
  *
64
+ * PIDTEMPBED:
65
+ *  bedKp, bedKi, bedKd
66
+ *
50 67
  * DOGLCD:
51 68
  *  lcd_contrast
52 69
  *
@@ -111,15 +128,6 @@ void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) {
111 128
 
112 129
 #define EEPROM_OFFSET 100
113 130
 
114
-
115
-// IMPORTANT:  Whenever there are changes made to the variables stored in EEPROM
116
-// in the functions below, also increment the version number. This makes sure that
117
-// the default values are used whenever there is a change to the data, to prevent
118
-// wrong data being written to the variables.
119
-// ALSO:  always make sure the variables in the Store and retrieve sections are in the same order.
120
-
121
-#define EEPROM_VERSION "V18"
122
-
123 131
 #ifdef EEPROM_SETTINGS
124 132
 
125 133
 void Config_StoreSettings()  {
@@ -194,7 +202,6 @@ void Config_StoreSettings()  {
194 202
   EEPROM_WRITE_VAR(i, absPreheatHPBTemp);
195 203
   EEPROM_WRITE_VAR(i, absPreheatFanSpeed);
196 204
 
197
-
198 205
   for (int e = 0; e < 4; e++) {
199 206
 
200 207
     #ifdef PIDTEMP
@@ -209,12 +216,10 @@ void Config_StoreSettings()  {
209 216
           EEPROM_WRITE_VAR(i, dummy);
210 217
         #endif
211 218
       }
212
-      else {
213
-    #else // !PIDTEMP
214
-      {
219
+      else
215 220
     #endif // !PIDTEMP
216
-
217
-        dummy = DUMMY_PID_VALUE;
221
+      {
222
+        dummy = DUMMY_PID_VALUE; // When read, will not change the existing value
218 223
         EEPROM_WRITE_VAR(i, dummy);
219 224
         dummy = 0.0f;
220 225
         for (int q = 3; q--;) EEPROM_WRITE_VAR(i, dummy);
@@ -222,6 +227,14 @@ void Config_StoreSettings()  {
222 227
 
223 228
   } // Extruders Loop
224 229
 
230
+  #ifndef PIDTEMPBED
231
+    float bedKp = DUMMY_PID_VALUE, bedKi = DUMMY_PID_VALUE, bedKd = DUMMY_PID_VALUE;
232
+  #endif
233
+
234
+  EEPROM_WRITE_VAR(i, bedKp);
235
+  EEPROM_WRITE_VAR(i, bedKi);
236
+  EEPROM_WRITE_VAR(i, bedKd);
237
+
225 238
   #ifndef DOGLCD
226 239
     int lcd_contrast = 32;
227 240
   #endif
@@ -364,7 +377,7 @@ void Config_RetrieveSettings() {
364 377
 
365 378
     #ifdef PIDTEMP
366 379
       for (int e = 0; e < 4; e++) { // 4 = max extruders currently supported by Marlin
367
-        EEPROM_READ_VAR(i, dummy);
380
+        EEPROM_READ_VAR(i, dummy); // Kp
368 381
         if (e < EXTRUDERS && dummy != DUMMY_PID_VALUE) {
369 382
           // do not need to scale PID values as the values in EEPROM are already scaled
370 383
           PID_PARAM(Kp, e) = dummy;
@@ -385,6 +398,20 @@ void Config_RetrieveSettings() {
385 398
       for (int q=16; q--;) EEPROM_READ_VAR(i, dummy);  // 4x Kp, Ki, Kd, Kc
386 399
     #endif // !PIDTEMP
387 400
 
401
+    #ifndef PIDTEMPBED
402
+      float bedKp, bedKi, bedKd;
403
+    #endif
404
+
405
+    EEPROM_READ_VAR(i, dummy); // bedKp
406
+    if (dummy != DUMMY_PID_VALUE) {
407
+      bedKp = dummy;
408
+      EEPROM_READ_VAR(i, bedKi);
409
+      EEPROM_READ_VAR(i, bedKd);
410
+    }
411
+    else {
412
+      for (int q=2; q--;) EEPROM_READ_VAR(i, dummy); // bedKi, bedKd
413
+    }
414
+
388 415
     #ifndef DOGLCD
389 416
       int lcd_contrast;
390 417
     #endif
@@ -517,6 +544,12 @@ void Config_ResetDefault() {
517 544
     updatePID();
518 545
   #endif // PIDTEMP
519 546
 
547
+  #ifdef PIDTEMPBED
548
+    bedKp = DEFAULT_bedKp;
549
+    bedKi = scalePID_i(DEFAULT_bedKi);
550
+    bedKd = scalePID_d(DEFAULT_bedKd);
551
+  #endif
552
+
520 553
   #ifdef FWRETRACT
521 554
     autoretract_enabled = false;
522 555
     retract_length = RETRACT_LENGTH;
@@ -660,17 +693,28 @@ void Config_PrintSettings(bool forReplay) {
660 693
     SERIAL_EOL;  
661 694
   #endif // DELTA
662 695
 
663
-  #ifdef PIDTEMP
696
+  #if defined(PIDTEMP) || defined(PIDTEMPBED)
664 697
     SERIAL_ECHO_START;
665 698
     if (!forReplay) {
666 699
       SERIAL_ECHOLNPGM("PID settings:");
667 700
       SERIAL_ECHO_START;
668 701
     }
669
-    SERIAL_ECHOPAIR("   M301 P", PID_PARAM(Kp, 0)); // for compatibility with hosts, only echos values for E0
670
-    SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, 0)));
671
-    SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, 0)));
672
-    SERIAL_EOL;
673
-  #endif // PIDTEMP
702
+    #if defined(PIDTEMP) && defined(PIDTEMPBED)
703
+      SERIAL_EOL;
704
+    #endif
705
+    #ifdef PIDTEMP
706
+      SERIAL_ECHOPAIR("  M301 P", PID_PARAM(Kp, 0)); // for compatibility with hosts, only echos values for E0
707
+      SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, 0)));
708
+      SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, 0)));
709
+      SERIAL_EOL;
710
+    #endif
711
+    #ifdef PIDTEMPBED
712
+      SERIAL_ECHOPAIR("  M304 P", bedKp); // for compatibility with hosts, only echos values for E0
713
+      SERIAL_ECHOPAIR(" I", unscalePID_i(bedKi));
714
+      SERIAL_ECHOPAIR(" D", unscalePID_d(bedKd));
715
+      SERIAL_EOL;
716
+    #endif
717
+  #endif
674 718
 
675 719
   #ifdef FWRETRACT
676 720
 
@@ -679,7 +723,7 @@ void Config_PrintSettings(bool forReplay) {
679 723
       SERIAL_ECHOLNPGM("Retract: S=Length (mm) F:Speed (mm/m) Z: ZLift (mm)");
680 724
       SERIAL_ECHO_START;
681 725
     }
682
-    SERIAL_ECHOPAIR("   M207 S", retract_length);
726
+    SERIAL_ECHOPAIR("  M207 S", retract_length);
683 727
     SERIAL_ECHOPAIR(" F", retract_feedrate*60);
684 728
     SERIAL_ECHOPAIR(" Z", retract_zlift);
685 729
     SERIAL_EOL;
@@ -688,7 +732,7 @@ void Config_PrintSettings(bool forReplay) {
688 732
       SERIAL_ECHOLNPGM("Recover: S=Extra length (mm) F:Speed (mm/m)");
689 733
       SERIAL_ECHO_START;
690 734
     }
691
-    SERIAL_ECHOPAIR("   M208 S", retract_recover_length);
735
+    SERIAL_ECHOPAIR("  M208 S", retract_recover_length);
692 736
     SERIAL_ECHOPAIR(" F", retract_recover_feedrate*60);
693 737
     SERIAL_EOL;
694 738
     SERIAL_ECHO_START;
@@ -696,7 +740,7 @@ void Config_PrintSettings(bool forReplay) {
696 740
       SERIAL_ECHOLNPGM("Auto-Retract: S=0 to disable, 1 to interpret extrude-only moves as retracts or recoveries");
697 741
       SERIAL_ECHO_START;
698 742
     }
699
-    SERIAL_ECHOPAIR("   M209 S", (unsigned long)(autoretract_enabled ? 1 : 0));
743
+    SERIAL_ECHOPAIR("  M209 S", (unsigned long)(autoretract_enabled ? 1 : 0));
700 744
     SERIAL_EOL;
701 745
 
702 746
     #if EXTRUDERS > 1
@@ -720,20 +764,20 @@ void Config_PrintSettings(bool forReplay) {
720 764
       SERIAL_ECHOLNPGM("Filament settings:");
721 765
       SERIAL_ECHO_START;
722 766
     }
723
-    SERIAL_ECHOPAIR("   M200 D", filament_size[0]);
767
+    SERIAL_ECHOPAIR("  M200 D", filament_size[0]);
724 768
     SERIAL_EOL;
725 769
 
726 770
     #if EXTRUDERS > 1
727 771
       SERIAL_ECHO_START;
728
-      SERIAL_ECHOPAIR("   M200 T1 D", filament_size[1]);
772
+      SERIAL_ECHOPAIR("  M200 T1 D", filament_size[1]);
729 773
       SERIAL_EOL;
730 774
       #if EXTRUDERS > 2
731 775
         SERIAL_ECHO_START;
732
-        SERIAL_ECHOPAIR("   M200 T2 D", filament_size[2]);
776
+        SERIAL_ECHOPAIR("  M200 T2 D", filament_size[2]);
733 777
         SERIAL_EOL;
734 778
         #if EXTRUDERS > 3
735 779
           SERIAL_ECHO_START;
736
-          SERIAL_ECHOPAIR("   M200 T3 D", filament_size[3]);
780
+          SERIAL_ECHOPAIR("  M200 T3 D", filament_size[3]);
737 781
           SERIAL_EOL;
738 782
         #endif
739 783
       #endif
@@ -752,7 +796,7 @@ void Config_PrintSettings(bool forReplay) {
752 796
         SERIAL_ECHOLNPGM("Z-Probe Offset (mm):");
753 797
         SERIAL_ECHO_START;
754 798
       }
755
-      SERIAL_ECHOPAIR("   M", (unsigned long)CUSTOM_M_CODE_SET_Z_PROBE_OFFSET);
799
+      SERIAL_ECHOPAIR("  M", (unsigned long)CUSTOM_M_CODE_SET_Z_PROBE_OFFSET);
756 800
       SERIAL_ECHOPAIR(" Z", -zprobe_zoffset);
757 801
     #else
758 802
       if (!forReplay) {

+ 1
- 1
Marlin/temperature.h View File

@@ -72,11 +72,11 @@ extern float current_temperature_bed;
72 72
   float unscalePID_d(float d);
73 73
 
74 74
 #endif
75
+
75 76
 #ifdef PIDTEMPBED
76 77
   extern float bedKp,bedKi,bedKd;
77 78
 #endif
78 79
   
79
-  
80 80
 #ifdef BABYSTEPPING
81 81
   extern volatile int babystepsTodo[3];
82 82
 #endif

Loading…
Cancel
Save