Ver código fonte

Edit digipot currents via LCD, save to EEPROM

dot-bob 8 anos atrás
pai
commit
b3c36c98fd

+ 57
- 15
Marlin/configuration_store.cpp Ver arquivo

36
  *
36
  *
37
  */
37
  */
38
 
38
 
39
-#define EEPROM_VERSION "V38"
39
+#define EEPROM_VERSION "V39"
40
 
40
 
41
 // Change EEPROM version if these are changed:
41
 // Change EEPROM version if these are changed:
42
 #define EEPROM_OFFSET 100
42
 #define EEPROM_OFFSET 100
43
 
43
 
44
 /**
44
 /**
45
- * V38 EEPROM Layout:
45
+ * V39 EEPROM Layout:
46
  *
46
  *
47
  *  100  Version                                    (char x4)
47
  *  100  Version                                    (char x4)
48
  *  104  EEPROM CRC16                               (uint16_t)
48
  *  104  EEPROM CRC16                               (uint16_t)
140
  *  534  M200 T D  filament_size                    (float x5) (T0..3)
140
  *  534  M200 T D  filament_size                    (float x5) (T0..3)
141
  *
141
  *
142
  * HAVE_TMC2130:                                    20 bytes
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
  * LIN_ADVANCE:                                     8 bytes
155
  * LIN_ADVANCE:                                     8 bytes
156
  *  580  M900 K    extruder_advance_k               (float)
156
  *  580  M900 K    extruder_advance_k               (float)
157
  *  584  M900 WHD  advance_ed_ratio                 (float)
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
  * meshes_begin (between max and min end-point, directly above)
168
  * meshes_begin (between max and min end-point, directly above)
177
 #include "planner.h"
182
 #include "planner.h"
178
 #include "temperature.h"
183
 #include "temperature.h"
179
 #include "ultralcd.h"
184
 #include "ultralcd.h"
185
+#include "stepper.h"
180
 
186
 
181
 #if ENABLED(INCH_MODE_SUPPORT) || (ENABLED(ULTIPANEL) && ENABLED(TEMPERATURE_UNITS_SUPPORT))
187
 #if ENABLED(INCH_MODE_SUPPORT) || (ENABLED(ULTIPANEL) && ENABLED(TEMPERATURE_UNITS_SUPPORT))
182
   #include "gcode.h"
188
   #include "gcode.h"
238
     refresh_bed_level();
244
     refresh_bed_level();
239
     //set_bed_leveling_enabled(leveling_is_on);
245
     //set_bed_leveling_enabled(leveling_is_on);
240
   #endif
246
   #endif
247
+
248
+  #if HAS_MOTOR_CURRENT_PWM
249
+    stepper.refresh_motor_power();
250
+  #endif
241
 }
251
 }
242
 
252
 
243
 #if ENABLED(EEPROM_SETTINGS)
253
 #if ENABLED(EEPROM_SETTINGS)
626
       EEPROM_WRITE(dummy);
636
       EEPROM_WRITE(dummy);
627
     #endif
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
     if (!eeprom_error) {
646
     if (!eeprom_error) {
630
       const int eeprom_size = eeprom_index;
647
       const int eeprom_size = eeprom_index;
631
 
648
 
979
         EEPROM_READ(dummy);
996
         EEPROM_READ(dummy);
980
       #endif
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
       if (working_crc == stored_crc) {
1006
       if (working_crc == stored_crc) {
983
           postprocess();
1007
           postprocess();
984
           SERIAL_ECHO_START();
1008
           SERIAL_ECHO_START();
1309
     planner.advance_ed_ratio = LIN_ADVANCE_E_D_RATIO;
1333
     planner.advance_ed_ratio = LIN_ADVANCE_E_D_RATIO;
1310
   #endif
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
   #if ENABLED(AUTO_BED_LEVELING_UBL)
1342
   #if ENABLED(AUTO_BED_LEVELING_UBL)
1313
     ubl.reset();
1343
     ubl.reset();
1314
   #endif
1344
   #endif
1788
       SERIAL_ECHOPAIR("  M900 K", planner.extruder_advance_k);
1818
       SERIAL_ECHOPAIR("  M900 K", planner.extruder_advance_k);
1789
       SERIAL_ECHOLNPAIR(" R", planner.advance_ed_ratio);
1819
       SERIAL_ECHOLNPAIR(" R", planner.advance_ed_ratio);
1790
     #endif
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
 #endif // !DISABLE_M503
1835
 #endif // !DISABLE_M503

+ 3
- 1
Marlin/pins_MINIRAMBO.h Ver arquivo

85
 #define MOTOR_CURRENT_PWM_Z_PIN  45
85
 #define MOTOR_CURRENT_PWM_Z_PIN  45
86
 #define MOTOR_CURRENT_PWM_E_PIN  44
86
 #define MOTOR_CURRENT_PWM_E_PIN  44
87
 // Motor current PWM conversion, PWM value = MotorCurrentSetting * 255 / range
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
 #define DEFAULT_PWM_MOTOR_CURRENT  {1300, 1300, 1250}
91
 #define DEFAULT_PWM_MOTOR_CURRENT  {1300, 1300, 1250}
90
 
92
 
91
 //
93
 //

+ 3
- 1
Marlin/pins_ULTIMAIN_2.h Ver arquivo

74
 #define MOTOR_CURRENT_PWM_Z_PIN 45
74
 #define MOTOR_CURRENT_PWM_Z_PIN 45
75
 #define MOTOR_CURRENT_PWM_E_PIN 46
75
 #define MOTOR_CURRENT_PWM_E_PIN 46
76
 // Motor current PWM conversion, PWM value = MotorCurrentSetting * 255 / range
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
 #define DEFAULT_PWM_MOTOR_CURRENT  {1300, 1300, 1250}
80
 #define DEFAULT_PWM_MOTOR_CURRENT  {1300, 1300, 1250}
79
 
81
 
80
 //
82
 //

+ 62
- 25
Marlin/stepper.cpp Ver arquivo

72
   bool Stepper::performing_homing = false;
72
   bool Stepper::performing_homing = false;
73
 #endif
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
 // private:
79
 // private:
76
 
80
 
77
 uint8_t Stepper::last_direction_bits = 0;        // The next stepping-bits to be output
81
 uint8_t Stepper::last_direction_bits = 0;        // The next stepping-bits to be output
1457
 
1461
 
1458
 #endif // HAS_DIGIPOTSS
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
   void Stepper::digipot_current(const uint8_t driver, const int current) {
1488
   void Stepper::digipot_current(const uint8_t driver, const int current) {
1490
 
1489
 
1491
     #if HAS_DIGIPOTSS
1490
     #if HAS_DIGIPOTSS
1494
       digitalPotWrite(digipot_ch[driver], current);
1493
       digitalPotWrite(digipot_ch[driver], current);
1495
 
1494
 
1496
     #elif HAS_MOTOR_CURRENT_PWM
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
       #define _WRITE_CURRENT_PWM(P) analogWrite(MOTOR_CURRENT_PWM_## P ##_PIN, 255L * current / (MOTOR_CURRENT_PWM_RANGE))
1500
       #define _WRITE_CURRENT_PWM(P) analogWrite(MOTOR_CURRENT_PWM_## P ##_PIN, 255L * current / (MOTOR_CURRENT_PWM_RANGE))
1498
       switch (driver) {
1501
       switch (driver) {
1499
         #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
1502
         #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
1509
     #endif
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
 #endif
1549
 #endif
1513
 
1550
 
1514
 #if HAS_MICROSTEPS
1551
 #if HAS_MICROSTEPS

+ 14
- 8
Marlin/stepper.h Ver arquivo

91
       static bool performing_homing;
91
       static bool performing_homing;
92
     #endif
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
   private:
101
   private:
95
 
102
 
96
     static uint8_t last_direction_bits;        // The next stepping-bits to be output
103
     static uint8_t last_direction_bits;        // The next stepping-bits to be output
132
     static volatile long endstops_trigsteps[XYZ];
139
     static volatile long endstops_trigsteps[XYZ];
133
     static volatile long endstops_stepsTotal, endstops_stepsDone;
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
     // Positions of stepper motors, in step units
143
     // Positions of stepper motors, in step units
144
     //
144
     //
279
       return endstops_trigsteps[axis] * planner.steps_to_mm[axis];
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
   private:
286
   private:
283
 
287
 
284
     static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
288
     static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
380
       // SERIAL_ECHOLN(current_block->final_advance/256.0);
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
     #if HAS_MICROSTEPS
391
     #if HAS_MICROSTEPS
386
       static void microstep_init();
392
       static void microstep_init();

+ 25
- 1
Marlin/ultralcd.cpp Ver arquivo

1249
    *
1249
    *
1250
    */
1250
    */
1251
   #if ENABLED(DAC_STEPPER_CURRENT)
1251
   #if ENABLED(DAC_STEPPER_CURRENT)
1252
+
1252
     void dac_driver_getValues() { LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); }
1253
     void dac_driver_getValues() { LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); }
1253
 
1254
 
1254
     void dac_driver_commit() { dac_current_set_percents(driverPercent); }
1255
     void dac_driver_commit() { dac_current_set_percents(driverPercent); }
1266
       MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
1267
       MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
1267
       END_MENU();
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
   constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
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
     #if ENABLED(DAC_STEPPER_CURRENT)
2915
     #if ENABLED(DAC_STEPPER_CURRENT)
2895
       MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
2916
       MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
2896
     #endif
2917
     #endif
2918
+    #if HAS_MOTOR_CURRENT_PWM
2919
+      MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_pwm_menu);
2920
+    #endif
2897
 
2921
 
2898
     #if ENABLED(BLTOUCH)
2922
     #if ENABLED(BLTOUCH)
2899
       MENU_ITEM(submenu, MSG_BLTOUCH, bltouch_menu);
2923
       MENU_ITEM(submenu, MSG_BLTOUCH, bltouch_menu);

Carregando…
Cancelar
Salvar