Browse Source

Fix and improve Power Monitor (#21551)

gmarsh 3 years ago
parent
commit
a5f0075a60
No account linked to committer's email address

+ 9
- 4
Marlin/Configuration_adv.h View File

@@ -3306,13 +3306,18 @@
3306 3306
  */
3307 3307
 //#define POWER_MONITOR_CURRENT   // Monitor the system current
3308 3308
 //#define POWER_MONITOR_VOLTAGE   // Monitor the system voltage
3309
-#if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
3310
-  #define POWER_MONITOR_VOLTS_PER_AMP   0.05000   // Input voltage to the MCU analog pin per amp  - DO NOT apply more than ADC_VREF!
3311
-  #define POWER_MONITOR_CURRENT_OFFSET -1         // Offset value for current sensors with linear function output
3312
-  #define POWER_MONITOR_VOLTS_PER_VOLT  0.11786   // Input voltage to the MCU analog pin per volt - DO NOT apply more than ADC_VREF!
3309
+
3310
+#if ENABLED(POWER_MONITOR_CURRENT)
3311
+  #define POWER_MONITOR_VOLTS_PER_AMP    0.05000  // Input voltage to the MCU analog pin per amp  - DO NOT apply more than ADC_VREF!
3312
+  #define POWER_MONITOR_CURRENT_OFFSET   0        // Offset (in amps) applied to the calculated current
3313 3313
   #define POWER_MONITOR_FIXED_VOLTAGE   13.6      // Voltage for a current sensor with no voltage sensor (for power display)
3314 3314
 #endif
3315 3315
 
3316
+#if ENABLED(POWER_MONITOR_VOLTAGE)
3317
+  #define POWER_MONITOR_VOLTS_PER_VOLT  0.077933  // Input voltage to the MCU analog pin per volt - DO NOT apply more than ADC_VREF!
3318
+  #define POWER_MONITOR_VOLTAGE_OFFSET  0         // Offset (in volts) applied to the calculated voltage
3319
+#endif
3320
+
3316 3321
 /**
3317 3322
  * CNC Coordinate Systems
3318 3323
  *

+ 6
- 3
Marlin/src/feature/power_monitor.cpp View File

@@ -26,8 +26,11 @@
26 26
 
27 27
 #include "power_monitor.h"
28 28
 
29
-#include "../lcd/marlinui.h"
30
-#include "../lcd/lcdprint.h"
29
+#if HAS_LCD_MENU
30
+  #include "../lcd/marlinui.h"
31
+  #include "../lcd/lcdprint.h"
32
+#endif
33
+
31 34
 #include "../libs/numtostr.h"
32 35
 
33 36
 uint8_t PowerMonitor::flags; // = 0
@@ -54,7 +57,7 @@ PowerMonitor power_monitor; // Single instance - this calls the constructor
54 57
     }
55 58
   #endif
56 59
 
57
-  #if HAS_POWER_MONITOR_VREF
60
+  #if ENABLED(POWER_MONITOR_VOLTAGE)
58 61
     void PowerMonitor::draw_voltage() {
59 62
       const float volts = getVolts();
60 63
       lcd_put_u8str(volts < 100 ? ftostr31ns(volts) : ui16tostr4rj((uint16_t)volts));

+ 9
- 13
Marlin/src/feature/power_monitor.h View File

@@ -23,7 +23,7 @@
23 23
 
24 24
 #include "../inc/MarlinConfig.h"
25 25
 
26
-#define PM_SAMPLE_RANGE 1024
26
+#define PM_SAMPLE_RANGE HAL_ADC_RANGE
27 27
 #define PM_K_VALUE      6
28 28
 #define PM_K_SCALE      6
29 29
 
@@ -35,7 +35,7 @@ struct pm_lpf_t {
35 35
     filter_buf = filter_buf - (filter_buf >> K_VALUE) + (uint32_t(sample) << K_SCALE);
36 36
   }
37 37
   void capture() {
38
-    value = filter_buf * (SCALE * (1.0f / (1UL << (PM_K_VALUE + PM_K_SCALE)))) + (POWER_MONITOR_CURRENT_OFFSET);
38
+    value = filter_buf * (SCALE * (1.0f / (1UL << (PM_K_VALUE + PM_K_SCALE))));
39 39
   }
40 40
   void reset(uint16_t reset_value = 0) {
41 41
     filter_buf = uint32_t(reset_value) << (K_VALUE + K_SCALE);
@@ -69,19 +69,15 @@ public:
69 69
   };
70 70
 
71 71
   #if ENABLED(POWER_MONITOR_CURRENT)
72
-    FORCE_INLINE static float getAmps() { return amps.value; }
72
+    FORCE_INLINE static float getAmps() { return amps.value + (POWER_MONITOR_CURRENT_OFFSET); }
73 73
     void add_current_sample(const uint16_t value) { amps.add_sample(value); }
74 74
   #endif
75 75
 
76
-  #if HAS_POWER_MONITOR_VREF
77
-    #if ENABLED(POWER_MONITOR_VOLTAGE)
78
-      FORCE_INLINE static float getVolts() { return volts.value; }
79
-    #else
80
-      FORCE_INLINE static float getVolts() { return POWER_MONITOR_FIXED_VOLTAGE; }  // using a specified fixed valtage as the voltage measurement
81
-    #endif
82
-    #if ENABLED(POWER_MONITOR_VOLTAGE)
83
-      void add_voltage_sample(const uint16_t value) { volts.add_sample(value); }
84
-    #endif
76
+  #if ENABLED(POWER_MONITOR_VOLTAGE)
77
+    FORCE_INLINE static float getVolts() { return volts.value + (POWER_MONITOR_VOLTAGE_OFFSET); }
78
+    void add_voltage_sample(const uint16_t value) { volts.add_sample(value); }
79
+  #else
80
+    FORCE_INLINE static float getVolts() { return POWER_MONITOR_FIXED_VOLTAGE; }
85 81
   #endif
86 82
 
87 83
   #if HAS_POWER_MONITOR_WATTS
@@ -98,7 +94,7 @@ public:
98 94
       FORCE_INLINE static void set_current_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_I, b); }
99 95
       FORCE_INLINE static void toggle_current_display() { TBI(flags, PM_DISP_BIT_I); }
100 96
     #endif
101
-    #if HAS_POWER_MONITOR_VREF
97
+    #if ENABLED(POWER_MONITOR_VOLTAGE)
102 98
       static void draw_voltage();
103 99
       FORCE_INLINE static bool voltage_display_enabled() { return TEST(flags, PM_DISP_BIT_V); }
104 100
       FORCE_INLINE static void set_voltage_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_V, b); }

+ 3
- 3
Marlin/src/gcode/feature/power_monitor/M430.cpp View File

@@ -42,7 +42,7 @@ void GcodeSuite::M430() {
42 42
     #if ENABLED(POWER_MONITOR_CURRENT)
43 43
       if (parser.seen('I')) { power_monitor.set_current_display(parser.value_bool()); do_report = false; }
44 44
     #endif
45
-    #if HAS_POWER_MONITOR_VREF
45
+    #if ENABLED(POWER_MONITOR_VOLTAGE)
46 46
       if (parser.seen('V')) { power_monitor.set_voltage_display(parser.value_bool()); do_report = false; }
47 47
     #endif
48 48
     #if HAS_POWER_MONITOR_WATTS
@@ -53,11 +53,11 @@ void GcodeSuite::M430() {
53 53
     SERIAL_ECHOLNPAIR(
54 54
       #if ENABLED(POWER_MONITOR_CURRENT)
55 55
         "Current: ", power_monitor.getAmps(), "A"
56
-        #if HAS_POWER_MONITOR_VREF
56
+        #if ENABLED(POWER_MONITOR_VOLTAGE)
57 57
           "  "
58 58
         #endif
59 59
       #endif
60
-      #if HAS_POWER_MONITOR_VREF
60
+      #if ENABLED(POWER_MONITOR_VOLTAGE)
61 61
         "Voltage: ", power_monitor.getVolts(), "V"
62 62
       #endif
63 63
       #if HAS_POWER_MONITOR_WATTS

+ 3
- 6
Marlin/src/inc/Conditionals_adv.h View File

@@ -498,12 +498,9 @@
498 498
 // Power Monitor sensors
499 499
 #if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
500 500
   #define HAS_POWER_MONITOR 1
501
-#endif
502
-#if ENABLED(POWER_MONITOR_CURRENT) && defined(POWER_MONITOR_FIXED_VOLTAGE)
503
-  #define HAS_POWER_MONITOR_VREF 1
504
-#endif
505
-#if BOTH(HAS_POWER_MONITOR_VREF, POWER_MONITOR_CURRENT)
506
-  #define HAS_POWER_MONITOR_WATTS 1
501
+  #if ENABLED(POWER_MONITOR_CURRENT) && (ENABLED(POWER_MONITOR_VOLTAGE) || defined(POWER_MONITOR_FIXED_VOLTAGE))
502
+    #define HAS_POWER_MONITOR_WATTS 1
503
+  #endif
507 504
 #endif
508 505
 
509 506
 // Flag if an EEPROM type is pre-selected

+ 4
- 4
Marlin/src/lcd/dogm/status_screen_DOGM.cpp View File

@@ -136,7 +136,7 @@
136 136
     #if ENABLED(POWER_MONITOR_CURRENT)
137 137
       const bool iflag = power_monitor.current_display_enabled();
138 138
     #endif
139
-    #if HAS_POWER_MONITOR_VREF
139
+    #if ENABLED(POWER_MONITOR_VOLTAGE)
140 140
       const bool vflag = power_monitor.voltage_display_enabled();
141 141
     #endif
142 142
 
@@ -148,7 +148,7 @@
148 148
       }
149 149
     #elif ENABLED(POWER_MONITOR_CURRENT)
150 150
       power_monitor.display_item = 0;
151
-    #elif HAS_POWER_MONITOR_VREF
151
+    #elif ENABLED(POWER_MONITOR_VOLTAGE)
152 152
       power_monitor.display_item = 1;
153 153
     #endif
154 154
 
@@ -157,7 +157,7 @@
157 157
       #if ENABLED(POWER_MONITOR_CURRENT)
158 158
         if (power_monitor.display_item == 0 && !iflag) ++power_monitor.display_item;
159 159
       #endif
160
-      #if HAS_POWER_MONITOR_VREF
160
+      #if ENABLED(POWER_MONITOR_VOLTAGE)
161 161
         if (power_monitor.display_item == 1 && !vflag) ++power_monitor.display_item;
162 162
       #endif
163 163
       #if HAS_POWER_MONITOR_WATTS
@@ -170,7 +170,7 @@
170 170
       #if ENABLED(POWER_MONITOR_CURRENT)                // Current
171 171
         case 0: if (iflag) power_monitor.draw_current(); break;
172 172
       #endif
173
-      #if HAS_POWER_MONITOR_VREF                        // Voltage
173
+      #if ENABLED(POWER_MONITOR_VOLTAGE)                        // Voltage
174 174
         case 1: if (vflag) power_monitor.draw_voltage(); break;
175 175
       #endif
176 176
       #if HAS_POWER_MONITOR_WATTS                       // Power

+ 1
- 1
Marlin/src/lcd/menu/menu_power_monitor.cpp View File

@@ -42,7 +42,7 @@ void menu_power_monitor() {
42 42
   }
43 43
   #endif
44 44
 
45
-  #if HAS_POWER_MONITOR_VREF
45
+  #if ENABLED(POWER_MONITOR_VOLTAGE)
46 46
   {
47 47
     bool ena = power_monitor.voltage_display_enabled();
48 48
     EDIT_ITEM(bool, MSG_VOLTAGE, &ena, power_monitor.toggle_voltage_display);

+ 2
- 2
Marlin/src/pins/lpc1768/pins_GMARSH_X6_REV1.h View File

@@ -119,6 +119,7 @@
119 119
 // Misc. Functions
120 120
 //
121 121
 #define LED_PIN                            P1_31
122
+#define POWER_MONITOR_VOLTAGE_PIN       P0_25_A2
122 123
 
123 124
 //
124 125
 // LCD
@@ -156,9 +157,8 @@
156 157
   #define SD_MISO_PIN                      P0_17
157 158
   #define SD_MOSI_PIN                      P0_18
158 159
   #define SD_SS_PIN                        P0_16
160
+  #define SD_DETECT_PIN                    P1_22
159 161
 #elif SD_CONNECTION_IS(ONBOARD)
160
-  #undef SD_DETECT_PIN
161
-  #define SD_DETECT_PIN                    P0_27
162 162
   #define SD_SCK_PIN                       P0_07
163 163
   #define SD_MISO_PIN                      P0_08
164 164
   #define SD_MOSI_PIN                      P0_09

Loading…
Cancel
Save