Kaynağa Gözat

Edit digipot currents via LCD, save to EEPROM

dot-bob 7 yıl önce
ebeveyn
işleme
b3c36c98fd

+ 57
- 15
Marlin/configuration_store.cpp Dosyayı Görüntüle

@@ -36,13 +36,13 @@
36 36
  *
37 37
  */
38 38
 
39
-#define EEPROM_VERSION "V38"
39
+#define EEPROM_VERSION "V39"
40 40
 
41 41
 // Change EEPROM version if these are changed:
42 42
 #define EEPROM_OFFSET 100
43 43
 
44 44
 /**
45
- * V38 EEPROM Layout:
45
+ * V39 EEPROM Layout:
46 46
  *
47 47
  *  100  Version                                    (char x4)
48 48
  *  104  EEPROM CRC16                               (uint16_t)
@@ -140,24 +140,29 @@
140 140
  *  534  M200 T D  filament_size                    (float x5) (T0..3)
141 141
  *
142 142
  * HAVE_TMC2130:                                    20 bytes
143
- *  554  M906 X    stepperX current                 (uint16_t)
144
- *  556  M906 Y    stepperY current                 (uint16_t)
145
- *  558  M906 Z    stepperZ current                 (uint16_t)
146
- *  560  M906 X2   stepperX2 current                (uint16_t)
147
- *  562  M906 Y2   stepperY2 current                (uint16_t)
148
- *  564  M906 Z2   stepperZ2 current                (uint16_t)
149
- *  566  M906 E0   stepperE0 current                (uint16_t)
150
- *  568  M906 E1   stepperE1 current                (uint16_t)
151
- *  570  M906 E2   stepperE2 current                (uint16_t)
152
- *  572  M906 E3   stepperE3 current                (uint16_t)
153
- *  576  M906 E4   stepperE4 current                (uint16_t)
143
+ *  554  M906 X    Stepper X current                (uint16_t)
144
+ *  556  M906 Y    Stepper Y current                (uint16_t)
145
+ *  558  M906 Z    Stepper Z current                (uint16_t)
146
+ *  560  M906 X2   Stepper X2 current               (uint16_t)
147
+ *  562  M906 Y2   Stepper Y2 current               (uint16_t)
148
+ *  564  M906 Z2   Stepper Z2 current               (uint16_t)
149
+ *  566  M906 E0   Stepper E0 current               (uint16_t)
150
+ *  568  M906 E1   Stepper E1 current               (uint16_t)
151
+ *  570  M906 E2   Stepper E2 current               (uint16_t)
152
+ *  572  M906 E3   Stepper E3 current               (uint16_t)
153
+ *  576  M906 E4   Stepper E4 current               (uint16_t)
154 154
  *
155 155
  * LIN_ADVANCE:                                     8 bytes
156 156
  *  580  M900 K    extruder_advance_k               (float)
157 157
  *  584  M900 WHD  advance_ed_ratio                 (float)
158 158
  *
159
- *  588                                Minimum end-point
160
- * 1909 (588 + 36 + 9 + 288 + 988)     Maximum end-point
159
+ * HAS_MOTOR_CURRENT_PWM:
160
+ *  588  M907 X    Stepper XY current               (uint32_t)
161
+ *  592  M907 Z    Stepper Z current                (uint32_t)
162
+ *  596  M907 E    Stepper E current                (uint32_t)
163
+ *
164
+ *  600                                Minimum end-point
165
+ * 1921 (600 + 36 + 9 + 288 + 988)     Maximum end-point
161 166
  *
162 167
  * ========================================================================
163 168
  * meshes_begin (between max and min end-point, directly above)
@@ -177,6 +182,7 @@ MarlinSettings settings;
177 182
 #include "planner.h"
178 183
 #include "temperature.h"
179 184
 #include "ultralcd.h"
185
+#include "stepper.h"
180 186
 
181 187
 #if ENABLED(INCH_MODE_SUPPORT) || (ENABLED(ULTIPANEL) && ENABLED(TEMPERATURE_UNITS_SUPPORT))
182 188
   #include "gcode.h"
@@ -238,6 +244,10 @@ void MarlinSettings::postprocess() {
238 244
     refresh_bed_level();
239 245
     //set_bed_leveling_enabled(leveling_is_on);
240 246
   #endif
247
+
248
+  #if HAS_MOTOR_CURRENT_PWM
249
+    stepper.refresh_motor_power();
250
+  #endif
241 251
 }
242 252
 
243 253
 #if ENABLED(EEPROM_SETTINGS)
@@ -626,6 +636,13 @@ void MarlinSettings::postprocess() {
626 636
       EEPROM_WRITE(dummy);
627 637
     #endif
628 638
 
639
+    #if HAS_MOTOR_CURRENT_PWM
640
+      for (uint8_t q = 3; q--;) EEPROM_WRITE(stepper.motor_current_setting[q]);
641
+    #else
642
+      const uint32_t dummyui32 = 0;
643
+      for (uint8_t q = 3; q--;) EEPROM_WRITE(dummyui32);
644
+    #endif
645
+
629 646
     if (!eeprom_error) {
630 647
       const int eeprom_size = eeprom_index;
631 648
 
@@ -979,6 +996,13 @@ void MarlinSettings::postprocess() {
979 996
         EEPROM_READ(dummy);
980 997
       #endif
981 998
 
999
+      #if HAS_MOTOR_CURRENT_PWM
1000
+        for (uint8_t q = 3; q--;) EEPROM_READ(stepper.motor_current_setting[q]);
1001
+      #else
1002
+        uint32_t dummyui32;
1003
+        for (uint8_t q = 3; q--;) EEPROM_READ(dummyui32);
1004
+      #endif
1005
+
982 1006
       if (working_crc == stored_crc) {
983 1007
           postprocess();
984 1008
           SERIAL_ECHO_START();
@@ -1309,6 +1333,12 @@ void MarlinSettings::reset() {
1309 1333
     planner.advance_ed_ratio = LIN_ADVANCE_E_D_RATIO;
1310 1334
   #endif
1311 1335
 
1336
+  #if HAS_MOTOR_CURRENT_PWM
1337
+    uint32_t tmp_motor_current_setting[3] = PWM_MOTOR_CURRENT;
1338
+    for (uint8_t q = 3; q--;)
1339
+      stepper.digipot_current(q, (stepper.motor_current_setting[q] = tmp_motor_current_setting[q]));
1340
+  #endif
1341
+
1312 1342
   #if ENABLED(AUTO_BED_LEVELING_UBL)
1313 1343
     ubl.reset();
1314 1344
   #endif
@@ -1788,6 +1818,18 @@ void MarlinSettings::reset() {
1788 1818
       SERIAL_ECHOPAIR("  M900 K", planner.extruder_advance_k);
1789 1819
       SERIAL_ECHOLNPAIR(" R", planner.advance_ed_ratio);
1790 1820
     #endif
1821
+
1822
+    #if HAS_MOTOR_CURRENT_PWM
1823
+      CONFIG_ECHO_START;
1824
+      if (!forReplay) {
1825
+        SERIAL_ECHOLNPGM("Stepper motor currents:");
1826
+        CONFIG_ECHO_START;
1827
+      }
1828
+      SERIAL_ECHOPAIR("  M907 X", stepper.motor_current_setting[0]);
1829
+      SERIAL_ECHOPAIR(" Z", stepper.motor_current_setting[1]);
1830
+      SERIAL_ECHOPAIR(" E", stepper.motor_current_setting[2]);
1831
+      SERIAL_EOL();
1832
+    #endif
1791 1833
   }
1792 1834
 
1793 1835
 #endif // !DISABLE_M503

+ 3
- 1
Marlin/pins_MINIRAMBO.h Dosyayı Görüntüle

@@ -85,7 +85,9 @@
85 85
 #define MOTOR_CURRENT_PWM_Z_PIN  45
86 86
 #define MOTOR_CURRENT_PWM_E_PIN  44
87 87
 // Motor current PWM conversion, PWM value = MotorCurrentSetting * 255 / range
88
-#define MOTOR_CURRENT_PWM_RANGE 2000
88
+#ifndef MOTOR_CURRENT_PWM_RANGE
89
+  #define MOTOR_CURRENT_PWM_RANGE 2000
90
+#endif
89 91
 #define DEFAULT_PWM_MOTOR_CURRENT  {1300, 1300, 1250}
90 92
 
91 93
 //

+ 3
- 1
Marlin/pins_ULTIMAIN_2.h Dosyayı Görüntüle

@@ -74,7 +74,9 @@
74 74
 #define MOTOR_CURRENT_PWM_Z_PIN 45
75 75
 #define MOTOR_CURRENT_PWM_E_PIN 46
76 76
 // Motor current PWM conversion, PWM value = MotorCurrentSetting * 255 / range
77
-#define MOTOR_CURRENT_PWM_RANGE 2000
77
+#ifndef MOTOR_CURRENT_PWM_RANGE
78
+  #define MOTOR_CURRENT_PWM_RANGE 2000
79
+#endif
78 80
 #define DEFAULT_PWM_MOTOR_CURRENT  {1300, 1300, 1250}
79 81
 
80 82
 //

+ 62
- 25
Marlin/stepper.cpp Dosyayı Görüntüle

@@ -72,6 +72,10 @@ block_t* Stepper::current_block = NULL;  // A pointer to the block currently bei
72 72
   bool Stepper::performing_homing = false;
73 73
 #endif
74 74
 
75
+#if HAS_MOTOR_CURRENT_PWM
76
+  uint32_t Stepper::motor_current_setting[3] = PWM_MOTOR_CURRENT;
77
+#endif
78
+
75 79
 // private:
76 80
 
77 81
 uint8_t Stepper::last_direction_bits = 0;        // The next stepping-bits to be output
@@ -1457,35 +1461,30 @@ void Stepper::report_positions() {
1457 1461
 
1458 1462
 #endif // HAS_DIGIPOTSS
1459 1463
 
1460
-#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
1464
+#if HAS_MOTOR_CURRENT_PWM
1461 1465
 
1462
-  void Stepper::digipot_init() {
1463
-    #if HAS_DIGIPOTSS
1464
-      static const uint8_t digipot_motor_current[] = DIGIPOT_MOTOR_CURRENT;
1465
-      SPI.begin();
1466
-      SET_OUTPUT(DIGIPOTSS_PIN);
1467
-      for (uint8_t i = 0; i < COUNT(digipot_motor_current); i++) {
1468
-        //digitalPotWrite(digipot_ch[i], digipot_motor_current[i]);
1469
-        digipot_current(i, digipot_motor_current[i]);
1466
+  void Stepper::refresh_motor_power() {
1467
+    for (uint8_t i = 0; i < COUNT(motor_current_setting); ++i) {
1468
+      switch (i) {
1469
+        #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
1470
+          case 0:
1471
+        #endif
1472
+        #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
1473
+          case 1:
1474
+        #endif
1475
+        #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
1476
+          case 2:
1477
+        #endif
1478
+            digipot_current(i, motor_current_setting[i]);
1479
+        default: break;
1470 1480
       }
1471
-    #elif HAS_MOTOR_CURRENT_PWM
1472
-      #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
1473
-        SET_OUTPUT(MOTOR_CURRENT_PWM_XY_PIN);
1474
-        digipot_current(0, motor_current_setting[0]);
1475
-      #endif
1476
-      #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
1477
-        SET_OUTPUT(MOTOR_CURRENT_PWM_Z_PIN);
1478
-        digipot_current(1, motor_current_setting[1]);
1479
-      #endif
1480
-      #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
1481
-        SET_OUTPUT(MOTOR_CURRENT_PWM_E_PIN);
1482
-        digipot_current(2, motor_current_setting[2]);
1483
-      #endif
1484
-      //Set timer5 to 31khz so the PWM of the motor power is as constant as possible. (removes a buzzing noise)
1485
-      TCCR5B = (TCCR5B & ~(_BV(CS50) | _BV(CS51) | _BV(CS52))) | _BV(CS50);
1486
-    #endif
1481
+    }
1487 1482
   }
1488 1483
 
1484
+#endif // HAS_MOTOR_CURRENT_PWM
1485
+
1486
+#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
1487
+
1489 1488
   void Stepper::digipot_current(const uint8_t driver, const int current) {
1490 1489
 
1491 1490
     #if HAS_DIGIPOTSS
@@ -1494,6 +1493,10 @@ void Stepper::report_positions() {
1494 1493
       digitalPotWrite(digipot_ch[driver], current);
1495 1494
 
1496 1495
     #elif HAS_MOTOR_CURRENT_PWM
1496
+
1497
+      if (WITHIN(driver, 0, 2))
1498
+        motor_current_setting[driver] = current; // update motor_current_setting
1499
+
1497 1500
       #define _WRITE_CURRENT_PWM(P) analogWrite(MOTOR_CURRENT_PWM_## P ##_PIN, 255L * current / (MOTOR_CURRENT_PWM_RANGE))
1498 1501
       switch (driver) {
1499 1502
         #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
@@ -1509,6 +1512,40 @@ void Stepper::report_positions() {
1509 1512
     #endif
1510 1513
   }
1511 1514
 
1515
+  void Stepper::digipot_init() {
1516
+
1517
+    #if HAS_DIGIPOTSS
1518
+
1519
+      static const uint8_t digipot_motor_current[] = DIGIPOT_MOTOR_CURRENT;
1520
+
1521
+      SPI.begin();
1522
+      SET_OUTPUT(DIGIPOTSS_PIN);
1523
+
1524
+      for (uint8_t i = 0; i < COUNT(digipot_motor_current); i++) {
1525
+        //digitalPotWrite(digipot_ch[i], digipot_motor_current[i]);
1526
+        digipot_current(i, digipot_motor_current[i]);
1527
+      }
1528
+
1529
+    #elif HAS_MOTOR_CURRENT_PWM
1530
+
1531
+      #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
1532
+        SET_OUTPUT(MOTOR_CURRENT_PWM_XY_PIN);
1533
+      #endif
1534
+      #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
1535
+        SET_OUTPUT(MOTOR_CURRENT_PWM_Z_PIN);
1536
+      #endif
1537
+      #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
1538
+        SET_OUTPUT(MOTOR_CURRENT_PWM_E_PIN);
1539
+      #endif
1540
+
1541
+      refresh_motor_power();
1542
+
1543
+      // Set Timer5 to 31khz so the PWM of the motor power is as constant as possible. (removes a buzzing noise)
1544
+      SET_CS5(PRESCALER_1);
1545
+
1546
+    #endif
1547
+  }
1548
+
1512 1549
 #endif
1513 1550
 
1514 1551
 #if HAS_MICROSTEPS

+ 14
- 8
Marlin/stepper.h Dosyayı Görüntüle

@@ -91,6 +91,13 @@ class Stepper {
91 91
       static bool performing_homing;
92 92
     #endif
93 93
 
94
+    #if HAS_MOTOR_CURRENT_PWM
95
+      #ifndef PWM_MOTOR_CURRENT
96
+        #define PWM_MOTOR_CURRENT DEFAULT_PWM_MOTOR_CURRENT
97
+      #endif
98
+      static uint32_t motor_current_setting[3];
99
+    #endif
100
+
94 101
   private:
95 102
 
96 103
     static uint8_t last_direction_bits;        // The next stepping-bits to be output
@@ -132,13 +139,6 @@ class Stepper {
132 139
     static volatile long endstops_trigsteps[XYZ];
133 140
     static volatile long endstops_stepsTotal, endstops_stepsDone;
134 141
 
135
-    #if HAS_MOTOR_CURRENT_PWM
136
-      #ifndef PWM_MOTOR_CURRENT
137
-        #define PWM_MOTOR_CURRENT DEFAULT_PWM_MOTOR_CURRENT
138
-      #endif
139
-      static constexpr int motor_current_setting[3] = PWM_MOTOR_CURRENT;
140
-    #endif
141
-
142 142
     //
143 143
     // Positions of stepper motors, in step units
144 144
     //
@@ -279,6 +279,10 @@ class Stepper {
279 279
       return endstops_trigsteps[axis] * planner.steps_to_mm[axis];
280 280
     }
281 281
 
282
+    #if HAS_MOTOR_CURRENT_PWM
283
+      static void refresh_motor_power();
284
+    #endif
285
+
282 286
   private:
283 287
 
284 288
     static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
@@ -380,7 +384,9 @@ class Stepper {
380 384
       // SERIAL_ECHOLN(current_block->final_advance/256.0);
381 385
     }
382 386
 
383
-    static void digipot_init();
387
+    #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
388
+      static void digipot_init();
389
+    #endif
384 390
 
385 391
     #if HAS_MICROSTEPS
386 392
       static void microstep_init();

+ 25
- 1
Marlin/ultralcd.cpp Dosyayı Görüntüle

@@ -1249,6 +1249,7 @@ void kill_screen(const char* lcd_msg) {
1249 1249
    *
1250 1250
    */
1251 1251
   #if ENABLED(DAC_STEPPER_CURRENT)
1252
+
1252 1253
     void dac_driver_getValues() { LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); }
1253 1254
 
1254 1255
     void dac_driver_commit() { dac_current_set_percents(driverPercent); }
@@ -1266,7 +1267,27 @@ void kill_screen(const char* lcd_msg) {
1266 1267
       MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
1267 1268
       END_MENU();
1268 1269
     }
1269
-  #endif
1270
+
1271
+  #endif // DAC_STEPPER_CURRENT
1272
+
1273
+  #if HAS_MOTOR_CURRENT_PWM
1274
+
1275
+    void lcd_pwm_menu() {
1276
+      START_MENU();
1277
+      MENU_BACK(MSG_CONTROL);
1278
+      #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
1279
+        MENU_ITEM_EDIT_CALLBACK(long5, MSG_X MSG_Y, &stepper.motor_current_setting[0], 100, 2000, Stepper::refresh_motor_power);
1280
+      #endif
1281
+      #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
1282
+        MENU_ITEM_EDIT_CALLBACK(long5, MSG_Z, &stepper.motor_current_setting[1], 100, 2000, Stepper::refresh_motor_power);
1283
+      #endif
1284
+      #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
1285
+        MENU_ITEM_EDIT_CALLBACK(long5, MSG_E, &stepper.motor_current_setting[2], 100, 2000, Stepper::refresh_motor_power);
1286
+      #endif
1287
+      END_MENU();
1288
+    }
1289
+
1290
+  #endif // HAS_MOTOR_CURRENT_PWM
1270 1291
 
1271 1292
   constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
1272 1293
 
@@ -2894,6 +2915,9 @@ void kill_screen(const char* lcd_msg) {
2894 2915
     #if ENABLED(DAC_STEPPER_CURRENT)
2895 2916
       MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
2896 2917
     #endif
2918
+    #if HAS_MOTOR_CURRENT_PWM
2919
+      MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_pwm_menu);
2920
+    #endif
2897 2921
 
2898 2922
     #if ENABLED(BLTOUCH)
2899 2923
       MENU_ITEM(submenu, MSG_BLTOUCH, bltouch_menu);

Loading…
İptal
Kaydet