Browse Source

Add LCD menu for DAC

jaysonkelly 8 years ago
parent
commit
13c9dcc600
6 changed files with 85 additions and 13 deletions
  1. 12
    1
      Marlin/dac_mcp4728.cpp
  2. 3
    1
      Marlin/dac_mcp4728.h
  3. 9
    0
      Marlin/language_en.h
  4. 17
    11
      Marlin/stepper_dac.cpp
  5. 2
    0
      Marlin/stepper_dac.h
  6. 42
    0
      Marlin/ultralcd.cpp

+ 12
- 1
Marlin/dac_mcp4728.cpp View File

@@ -34,7 +34,7 @@
34 34
 
35 35
 #if ENABLED(DAC_STEPPER_CURRENT)
36 36
 
37
-uint16_t     mcp4728_values[4];
37
+uint16_t     mcp4728_values[XYZE];
38 38
 
39 39
 /**
40 40
  * Begin I2C, get current values (input register and eeprom) of mcp4728
@@ -112,6 +112,17 @@ uint16_t mcp4728_getVout(uint8_t channel) {
112 112
 }
113 113
 */
114 114
 
115
+/* Returns DAC values as a 0-100 percentage of drive strength */
116
+uint16_t mcp4728_getDrvPct(uint8_t channel) {return (uint16_t)(.5+(((float)mcp4728_values[channel]*100)/DAC_STEPPER_MAX));}
117
+
118
+/* Recieves all Drive strengths as 0-100 percent values, updates DAC Values array and calls fastwrite to update the DAC */
119
+void mcp4728_setDrvPct(int16_t pct[XYZE]) {
120
+  for (uint8_t i=0; i <= 3; i++) {
121
+    mcp4728_values[i] = ((float)pct[i] * DAC_STEPPER_MAX)/100;
122
+  }
123
+  mcp4728_fastWrite();
124
+}
125
+
115 126
 /**
116 127
  * FastWrite input register values - All DAC ouput update. refer to DATASHEET 5.6.1
117 128
  * DAC Input and PowerDown bits update.

+ 3
- 1
Marlin/dac_mcp4728.h View File

@@ -32,7 +32,7 @@
32 32
 #if ENABLED(DAC_STEPPER_CURRENT)
33 33
 #include "Wire.h"
34 34
 
35
-#define defaultVDD     5000
35
+#define defaultVDD     DAC_STEPPER_MAX //was 5000 but differs with internal Vref
36 36
 #define BASE_ADDR      0x60
37 37
 #define RESET          0B00000110
38 38
 #define WAKE           0B00001001
@@ -59,6 +59,8 @@ uint8_t mcp4728_setGain_all(uint8_t value);
59 59
 uint16_t mcp4728_getValue(uint8_t channel);
60 60
 uint8_t mcp4728_fastWrite();
61 61
 uint8_t mcp4728_simpleCommand(byte simpleCommand);
62
+uint16_t mcp4728_getDrvPct(uint8_t channel);
63
+void mcp4728_setDrvPct(int16_t pct[XYZE]);
62 64
 
63 65
 #endif
64 66
 #endif

+ 9
- 0
Marlin/language_en.h View File

@@ -544,6 +544,15 @@
544 544
 #ifndef MSG_FILAMENT_CHANGE_OPTION_RESUME
545 545
   #define MSG_FILAMENT_CHANGE_OPTION_RESUME   "Resume print"
546 546
 #endif
547
+#ifndef MSG_DRIVE_STRENGTH
548
+  #define MSG_DRIVE_STRENGTH                  "Drive Strength"
549
+#endif
550
+#ifndef MSG_DAC_PERCENT
551
+  #define MSG_DAC_PERCENT                     "Driver %"
552
+#endif
553
+#ifndef MSG_DAC_EEPROM_WRITE
554
+  #define MSG_DAC_EEPROM_WRITE                "DAC EEPROM Write"
555
+#endif
547 556
 #if LCD_HEIGHT >= 4
548 557
   #ifndef MSG_FILAMENT_CHANGE_INIT_1
549 558
     #define MSG_FILAMENT_CHANGE_INIT_1          "Wait for start"

+ 17
- 11
Marlin/stepper_dac.cpp View File

@@ -49,6 +49,7 @@
49 49
 
50 50
   bool dac_present = false;
51 51
   const uint8_t dac_order[NUM_AXIS] = DAC_STEPPER_ORDER;
52
+  uint16_t dac_channel_pct[XYZE];
52 53
 
53 54
   int dac_init() {
54 55
     #if PIN_EXISTS(DAC_DISABLE)
@@ -86,7 +87,13 @@
86 87
   }
87 88
 
88 89
   static float dac_perc(int8_t n) { return 100.0 * mcp4728_getValue(dac_order[n]) / DAC_STEPPER_MAX; }
89
-  static float dac_amps(int8_t n) { return ((2.048 * mcp4728_getValue(dac_order[n])) / 4096.0) / (8.0 * DAC_STEPPER_SENSE); }
90
+  static float dac_amps(int8_t n) { return (mcp4728_getDrvPct(dac_order[n])*DAC_STEPPER_MAX) / (8.0 * DAC_STEPPER_SENSE); }
91
+  
92
+  int16_t dac_current_get_percent(int8_t axis) {return mcp4728_getDrvPct(dac_order[axis]); }
93
+  void dac_current_set_percents(int16_t pct[XYZE]) {
94
+    LOOP_XYZE(i) dac_channel_pct[i] = pct[dac_order[i]];
95
+    mcp4728_setDrvPct(dac_channel_pct);
96
+  }
90 97
 
91 98
   void dac_print_values() {
92 99
     if (!dac_present) return;
@@ -94,16 +101,15 @@
94 101
     SERIAL_ECHO_START;
95 102
     SERIAL_ECHOLNPGM("Stepper current values in % (Amps):");
96 103
     SERIAL_ECHO_START;
97
-    SERIAL_ECHOPAIR(" X:",  dac_perc(0));
98
-    SERIAL_ECHOPAIR(" (",   dac_amps(0));
99
-    SERIAL_ECHOPAIR(") Y:", dac_perc(1));
100
-    SERIAL_ECHOPAIR(" (",   dac_amps(1));
101
-    SERIAL_ECHOPAIR(") Z:", dac_perc(2));
102
-    SERIAL_ECHOPAIR(" (",   dac_amps(2));
103
-    SERIAL_ECHOPAIR(") E:", dac_perc(3));
104
-    SERIAL_ECHOPAIR(" (",   dac_amps(3));
105
-    SERIAL_CHAR(')');
106
-    SERIAL_EOL;
104
+    SERIAL_ECHOPAIR(" X:",  dac_perc(X_AXIS)); 
105
+    SERIAL_ECHOPAIR(" (",   dac_amps(X_AXIS));
106
+    SERIAL_ECHOPAIR(") Y:", dac_perc(Y_AXIS));
107
+    SERIAL_ECHOPAIR(" (",   dac_amps(Y_AXIS));
108
+    SERIAL_ECHOPAIR(") Z:", dac_perc(Z_AXIS));
109
+    SERIAL_ECHOPAIR(" (",   dac_amps(Z_AXIS));
110
+    SERIAL_ECHOPAIR(") E:", dac_perc(E_AXIS));
111
+    SERIAL_ECHOPAIR(" (",   dac_amps(E_AXIS));
112
+    SERIAL_ECHOLN(")");
107 113
   }
108 114
 
109 115
   void dac_commit_eeprom() {

+ 2
- 0
Marlin/stepper_dac.h View File

@@ -51,5 +51,7 @@ void dac_current_percent(uint8_t channel, float val);
51 51
 void dac_current_raw(uint8_t channel, uint16_t val);
52 52
 void dac_print_values();
53 53
 void dac_commit_eeprom();
54
+int16_t dac_current_get_percent(int8_t axis) ;
55
+void dac_current_set_percents(int16_t pct[XYZE]);
54 56
 
55 57
 #endif // STEPPER_DAC_H

+ 42
- 0
Marlin/ultralcd.cpp View File

@@ -62,6 +62,11 @@ millis_t next_lcd_update_ms;
62 62
 
63 63
 uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to draw, decrements after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
64 64
 
65
+#if ENABLED(DAC_STEPPER_CURRENT)
66
+  #include "stepper_dac.h" //was dac_mcp4728.h MarlinMain uses stepper dac for the m-codes
67
+  uint16_t driverPercent[XYZE];
68
+#endif
69
+
65 70
 #if ENABLED(ULTIPANEL)
66 71
 
67 72
   // place-holders for Ki and Kd edits
@@ -114,6 +119,13 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to
114 119
   static void lcd_control_motion_menu();
115 120
   static void lcd_control_volumetric_menu();
116 121
 
122
+  #if ENABLED(DAC_STEPPER_CURRENT)
123
+    static void dac_driver_commit();
124
+    static void dac_driver_getValues();
125
+    static void lcd_dac_menu();
126
+    static void lcd_dac_write_eeprom();
127
+  #endif
128
+
117 129
   #if ENABLED(LCD_INFO_MENU)
118 130
     #if ENABLED(PRINTCOUNTER)
119 131
       static void lcd_info_stats_menu();
@@ -848,6 +860,32 @@ void kill_screen(const char* lcd_msg) {
848 860
 
849 861
   /**
850 862
    *
863
+   * "Driver current control" submenu items
864
+   *
865
+   */
866
+  #if ENABLED(DAC_STEPPER_CURRENT)
867
+    static void dac_driver_getValues() {LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent(i); } 
868
+  
869
+    static void dac_driver_commit() { dac_current_set_percents(driverPercent); }
870
+  
871
+    static void dac_driver_eeprom_write() { dac_commit_eeprom(); }
872
+    
873
+    static void lcd_dac_menu() {
874
+      dac_driver_getValues();
875
+      START_MENU();    
876
+      MENU_ITEM(back, MSG_CONTROL);
877
+      MENU_ITEM_EDIT_CALLBACK(int3, MSG_X " " MSG_DAC_PERCENT, &driverPercent[X_AXIS], 0, 100, dac_driver_commit);
878
+      MENU_ITEM_EDIT_CALLBACK(int3, MSG_Y " " MSG_DAC_PERCENT, &driverPercent[Y_AXIS], 0, 100, dac_driver_commit);
879
+      MENU_ITEM_EDIT_CALLBACK(int3, MSG_Z " " MSG_DAC_PERCENT, &driverPercent[Z_AXIS], 0, 100, dac_driver_commit);
880
+      MENU_ITEM_EDIT_CALLBACK(int3, MSG_E " " MSG_DAC_PERCENT, &driverPercent[E_AXIS], 0, 100, dac_driver_commit);
881
+      MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
882
+      END_MENU();
883
+    }
884
+  #endif
885
+  
886
+
887
+  /**
888
+   *
851 889
    * "Prepare" submenu items
852 890
    *
853 891
    */
@@ -1529,6 +1567,10 @@ void kill_screen(const char* lcd_msg) {
1529 1567
     #if ENABLED(FWRETRACT)
1530 1568
       MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
1531 1569
     #endif
1570
+    #if ENABLED(DAC_STEPPER_CURRENT)
1571
+      MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu); 
1572
+    #endif
1573
+
1532 1574
     #if ENABLED(EEPROM_SETTINGS)
1533 1575
       MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
1534 1576
       MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);

Loading…
Cancel
Save