Browse Source

Merge pull request #7136 from thinkyhead/bf_digipot_save

Edit digipot currents via LCD, save to EEPROM
Scott Lahteine 8 years ago
parent
commit
efc6a9c1b8

+ 3
- 3
.travis.yml View File

@@ -202,9 +202,9 @@ script:
202 202
   #
203 203
   # Enable COREYX (swapped)
204 204
   #
205
-  - restore_configs
206
-  - opt_enable COREYX
207
-  - build_marlin
205
+  #- restore_configs
206
+  #- opt_enable COREYX
207
+  #- build_marlin
208 208
   #
209 209
   #
210 210
   ######## Other Standard LCD/Panels ##############

+ 2
- 2
Marlin/Makefile View File

@@ -290,8 +290,8 @@ ifeq ($(HARDWARE_VARIANT), Teensy)
290 290
 SRC = wiring.c
291 291
 VPATH += $(ARDUINO_INSTALL_DIR)/hardware/teensy/cores/teensy
292 292
 endif
293
-CXXSRC = WMath.cpp WString.cpp Print.cpp Marlin_main.cpp	\
294
-	MarlinSerial.cpp Sd2Card.cpp SdBaseFile.cpp SdFatUtil.cpp	\
293
+CXXSRC = WMath.cpp WString.cpp Print.cpp Marlin_main.cpp \
294
+	MarlinSerial.cpp Sd2Card.cpp SdBaseFile.cpp SdFatUtil.cpp \
295 295
 	SdFile.cpp SdVolume.cpp planner.cpp stepper.cpp \
296 296
 	temperature.cpp cardreader.cpp configuration_store.cpp \
297 297
 	watchdog.cpp SPI.cpp servo.cpp Tone.cpp ultralcd.cpp digipot_mcp4451.cpp \

+ 6
- 0
Marlin/Marlin_main.cpp View File

@@ -9677,10 +9677,13 @@ inline void gcode_M503() {
9677 9677
  */
9678 9678
 inline void gcode_M907() {
9679 9679
   #if HAS_DIGIPOTSS
9680
+
9680 9681
     LOOP_XYZE(i) if (parser.seen(axis_codes[i])) stepper.digipot_current(i, parser.value_int());
9681 9682
     if (parser.seen('B')) stepper.digipot_current(4, parser.value_int());
9682 9683
     if (parser.seen('S')) for (uint8_t i = 0; i <= 4; i++) stepper.digipot_current(i, parser.value_int());
9684
+
9683 9685
   #elif HAS_MOTOR_CURRENT_PWM
9686
+
9684 9687
     #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
9685 9688
       if (parser.seen('X')) stepper.digipot_current(0, parser.value_int());
9686 9689
     #endif
@@ -9690,13 +9693,16 @@ inline void gcode_M907() {
9690 9693
     #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
9691 9694
       if (parser.seen('E')) stepper.digipot_current(2, parser.value_int());
9692 9695
     #endif
9696
+
9693 9697
   #endif
9698
+
9694 9699
   #if ENABLED(DIGIPOT_I2C)
9695 9700
     // this one uses actual amps in floating point
9696 9701
     LOOP_XYZE(i) if (parser.seen(axis_codes[i])) digipot_i2c_set_current(i, parser.value_float());
9697 9702
     // for each additional extruder (named B,C,D,E..., channels 4,5,6,7...)
9698 9703
     for (uint8_t i = NUM_AXIS; i < DIGIPOT_I2C_NUM_CHANNELS; i++) if (parser.seen('B' + i - (NUM_AXIS))) digipot_i2c_set_current(i, parser.value_float());
9699 9704
   #endif
9705
+
9700 9706
   #if ENABLED(DAC_STEPPER_CURRENT)
9701 9707
     if (parser.seen('S')) {
9702 9708
       const float dac_percent = parser.value_float();

+ 57
- 15
Marlin/configuration_store.cpp View File

@@ -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 View File

@@ -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 View File

@@ -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
 //

+ 72
- 32
Marlin/stepper.cpp View File

@@ -72,10 +72,14 @@ 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
-unsigned char Stepper::last_direction_bits = 0;        // The next stepping-bits to be output
78
-unsigned int Stepper::cleaning_buffer_counter = 0;
81
+uint8_t Stepper::last_direction_bits = 0;        // The next stepping-bits to be output
82
+uint16_t Stepper::cleaning_buffer_counter = 0;
79 83
 
80 84
 #if ENABLED(Z_DUAL_ENDSTOPS)
81 85
   bool Stepper::locked_z_motor = false;
@@ -1447,62 +1451,98 @@ void Stepper::report_positions() {
1447 1451
 #if HAS_DIGIPOTSS
1448 1452
 
1449 1453
   // From Arduino DigitalPotControl example
1450
-  void Stepper::digitalPotWrite(int address, int value) {
1451
-    WRITE(DIGIPOTSS_PIN, LOW); // take the SS pin low to select the chip
1452
-    SPI.transfer(address); //  send in the address and value via SPI:
1454
+  void Stepper::digitalPotWrite(const int16_t address, const int16_t value) {
1455
+    WRITE(DIGIPOTSS_PIN, LOW);  // Take the SS pin low to select the chip
1456
+    SPI.transfer(address);      // Send the address and value via SPI
1453 1457
     SPI.transfer(value);
1454
-    WRITE(DIGIPOTSS_PIN, HIGH); // take the SS pin high to de-select the chip:
1458
+    WRITE(DIGIPOTSS_PIN, HIGH); // Take the SS pin high to de-select the chip
1455 1459
     //delay(10);
1456 1460
   }
1457 1461
 
1458 1462
 #endif // HAS_DIGIPOTSS
1459 1463
 
1464
+#if HAS_MOTOR_CURRENT_PWM
1465
+
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;
1480
+      }
1481
+    }
1482
+  }
1483
+
1484
+#endif // HAS_MOTOR_CURRENT_PWM
1485
+
1460 1486
 #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
1461 1487
 
1488
+  void Stepper::digipot_current(const uint8_t driver, const int current) {
1489
+
1490
+    #if HAS_DIGIPOTSS
1491
+
1492
+      const uint8_t digipot_ch[] = DIGIPOT_CHANNELS;
1493
+      digitalPotWrite(digipot_ch[driver], current);
1494
+
1495
+    #elif HAS_MOTOR_CURRENT_PWM
1496
+
1497
+      if (WITHIN(driver, 0, 2))
1498
+        motor_current_setting[driver] = current; // update motor_current_setting
1499
+
1500
+      #define _WRITE_CURRENT_PWM(P) analogWrite(MOTOR_CURRENT_PWM_## P ##_PIN, 255L * current / (MOTOR_CURRENT_PWM_RANGE))
1501
+      switch (driver) {
1502
+        #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
1503
+          case 0: _WRITE_CURRENT_PWM(XY); break;
1504
+        #endif
1505
+        #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
1506
+          case 1: _WRITE_CURRENT_PWM(Z); break;
1507
+        #endif
1508
+        #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
1509
+          case 2: _WRITE_CURRENT_PWM(E); break;
1510
+        #endif
1511
+      }
1512
+    #endif
1513
+  }
1514
+
1462 1515
   void Stepper::digipot_init() {
1516
+
1463 1517
     #if HAS_DIGIPOTSS
1518
+
1464 1519
       static const uint8_t digipot_motor_current[] = DIGIPOT_MOTOR_CURRENT;
1520
+
1465 1521
       SPI.begin();
1466 1522
       SET_OUTPUT(DIGIPOTSS_PIN);
1523
+
1467 1524
       for (uint8_t i = 0; i < COUNT(digipot_motor_current); i++) {
1468 1525
         //digitalPotWrite(digipot_ch[i], digipot_motor_current[i]);
1469 1526
         digipot_current(i, digipot_motor_current[i]);
1470 1527
       }
1528
+
1471 1529
     #elif HAS_MOTOR_CURRENT_PWM
1530
+
1472 1531
       #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
1473 1532
         SET_OUTPUT(MOTOR_CURRENT_PWM_XY_PIN);
1474
-        digipot_current(0, motor_current_setting[0]);
1475 1533
       #endif
1476 1534
       #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
1477 1535
         SET_OUTPUT(MOTOR_CURRENT_PWM_Z_PIN);
1478
-        digipot_current(1, motor_current_setting[1]);
1479 1536
       #endif
1480 1537
       #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
1481 1538
         SET_OUTPUT(MOTOR_CURRENT_PWM_E_PIN);
1482
-        digipot_current(2, motor_current_setting[2]);
1483 1539
       #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
1487
-  }
1488 1540
 
1489
-  void Stepper::digipot_current(uint8_t driver, int current) {
1490
-    #if HAS_DIGIPOTSS
1491
-      const uint8_t digipot_ch[] = DIGIPOT_CHANNELS;
1492
-      digitalPotWrite(digipot_ch[driver], current);
1493
-    #elif HAS_MOTOR_CURRENT_PWM
1494
-      #define _WRITE_CURRENT_PWM(P) analogWrite(P, 255L * current / (MOTOR_CURRENT_PWM_RANGE))
1495
-      switch (driver) {
1496
-        #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
1497
-          case 0: _WRITE_CURRENT_PWM(MOTOR_CURRENT_PWM_XY_PIN); break;
1498
-        #endif
1499
-        #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
1500
-          case 1: _WRITE_CURRENT_PWM(MOTOR_CURRENT_PWM_Z_PIN); break;
1501
-        #endif
1502
-        #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
1503
-          case 2: _WRITE_CURRENT_PWM(MOTOR_CURRENT_PWM_E_PIN); break;
1504
-        #endif
1505
-      }
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
+
1506 1546
     #endif
1507 1547
   }
1508 1548
 
@@ -1550,7 +1590,7 @@ void Stepper::report_positions() {
1550 1590
       microstep_mode(i, microstep_modes[i]);
1551 1591
   }
1552 1592
 
1553
-  void Stepper::microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2) {
1593
+  void Stepper::microstep_ms(const uint8_t driver, const int8_t ms1, const int8_t ms2) {
1554 1594
     if (ms1 >= 0) switch (driver) {
1555 1595
       case 0: WRITE(X_MS1_PIN, ms1); break;
1556 1596
       #if HAS_Y_MICROSTEPS
@@ -1601,7 +1641,7 @@ void Stepper::report_positions() {
1601 1641
     }
1602 1642
   }
1603 1643
 
1604
-  void Stepper::microstep_mode(uint8_t driver, uint8_t stepping_mode) {
1644
+  void Stepper::microstep_mode(const uint8_t driver, const uint8_t stepping_mode) {
1605 1645
     switch (stepping_mode) {
1606 1646
       case 1: microstep_ms(driver, MICROSTEP1); break;
1607 1647
       case 2: microstep_ms(driver, MICROSTEP2); break;

+ 23
- 17
Marlin/stepper.h View File

@@ -91,10 +91,17 @@ 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
-    static unsigned char last_direction_bits;        // The next stepping-bits to be output
97
-    static unsigned int cleaning_buffer_counter;
103
+    static uint8_t last_direction_bits;        // The next stepping-bits to be output
104
+    static uint16_t cleaning_buffer_counter;
98 105
 
99 106
     #if ENABLED(Z_DUAL_ENDSTOPS)
100 107
       static bool locked_z_motor, locked_z2_motor;
@@ -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
     //
@@ -243,20 +243,20 @@ class Stepper {
243 243
     static FORCE_INLINE bool motor_direction(AxisEnum axis) { return TEST(last_direction_bits, axis); }
244 244
 
245 245
     #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
246
-      static void digitalPotWrite(int address, int value);
247
-      static void digipot_current(uint8_t driver, int current);
246
+      static void digitalPotWrite(const int16_t address, const int16_t value);
247
+      static void digipot_current(const uint8_t driver, const int16_t current);
248 248
     #endif
249 249
 
250 250
     #if HAS_MICROSTEPS
251
-      static void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2);
252
-      static void microstep_mode(uint8_t driver, uint8_t stepping);
251
+      static void microstep_ms(const uint8_t driver, const int8_t ms1, const int8_t ms2);
252
+      static void microstep_mode(const uint8_t driver, const uint8_t stepping);
253 253
       static void microstep_readings();
254 254
     #endif
255 255
 
256 256
     #if ENABLED(Z_DUAL_ENDSTOPS)
257
-      static FORCE_INLINE void set_homing_flag(bool state) { performing_homing = state; }
258
-      static FORCE_INLINE void set_z_lock(bool state) { locked_z_motor = state; }
259
-      static FORCE_INLINE void set_z2_lock(bool state) { locked_z2_motor = state; }
257
+      static FORCE_INLINE void set_homing_flag(const bool state) { performing_homing = state; }
258
+      static FORCE_INLINE void set_z_lock(const bool state) { locked_z_motor = state; }
259
+      static FORCE_INLINE void set_z2_lock(const bool state) { locked_z2_motor = state; }
260 260
     #endif
261 261
 
262 262
     #if ENABLED(BABYSTEPPING)
@@ -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 View File

@@ -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…
Cancel
Save