Browse Source

Fix and improve Power Monitor (#21551)

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

+ 9
- 4
Marlin/Configuration_adv.h View File

3306
  */
3306
  */
3307
 //#define POWER_MONITOR_CURRENT   // Monitor the system current
3307
 //#define POWER_MONITOR_CURRENT   // Monitor the system current
3308
 //#define POWER_MONITOR_VOLTAGE   // Monitor the system voltage
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
   #define POWER_MONITOR_FIXED_VOLTAGE   13.6      // Voltage for a current sensor with no voltage sensor (for power display)
3313
   #define POWER_MONITOR_FIXED_VOLTAGE   13.6      // Voltage for a current sensor with no voltage sensor (for power display)
3314
 #endif
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
  * CNC Coordinate Systems
3322
  * CNC Coordinate Systems
3318
  *
3323
  *

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

26
 
26
 
27
 #include "power_monitor.h"
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
 #include "../libs/numtostr.h"
34
 #include "../libs/numtostr.h"
32
 
35
 
33
 uint8_t PowerMonitor::flags; // = 0
36
 uint8_t PowerMonitor::flags; // = 0
54
     }
57
     }
55
   #endif
58
   #endif
56
 
59
 
57
-  #if HAS_POWER_MONITOR_VREF
60
+  #if ENABLED(POWER_MONITOR_VOLTAGE)
58
     void PowerMonitor::draw_voltage() {
61
     void PowerMonitor::draw_voltage() {
59
       const float volts = getVolts();
62
       const float volts = getVolts();
60
       lcd_put_u8str(volts < 100 ? ftostr31ns(volts) : ui16tostr4rj((uint16_t)volts));
63
       lcd_put_u8str(volts < 100 ? ftostr31ns(volts) : ui16tostr4rj((uint16_t)volts));

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

23
 
23
 
24
 #include "../inc/MarlinConfig.h"
24
 #include "../inc/MarlinConfig.h"
25
 
25
 
26
-#define PM_SAMPLE_RANGE 1024
26
+#define PM_SAMPLE_RANGE HAL_ADC_RANGE
27
 #define PM_K_VALUE      6
27
 #define PM_K_VALUE      6
28
 #define PM_K_SCALE      6
28
 #define PM_K_SCALE      6
29
 
29
 
35
     filter_buf = filter_buf - (filter_buf >> K_VALUE) + (uint32_t(sample) << K_SCALE);
35
     filter_buf = filter_buf - (filter_buf >> K_VALUE) + (uint32_t(sample) << K_SCALE);
36
   }
36
   }
37
   void capture() {
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
   void reset(uint16_t reset_value = 0) {
40
   void reset(uint16_t reset_value = 0) {
41
     filter_buf = uint32_t(reset_value) << (K_VALUE + K_SCALE);
41
     filter_buf = uint32_t(reset_value) << (K_VALUE + K_SCALE);
69
   };
69
   };
70
 
70
 
71
   #if ENABLED(POWER_MONITOR_CURRENT)
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
     void add_current_sample(const uint16_t value) { amps.add_sample(value); }
73
     void add_current_sample(const uint16_t value) { amps.add_sample(value); }
74
   #endif
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
   #endif
81
   #endif
86
 
82
 
87
   #if HAS_POWER_MONITOR_WATTS
83
   #if HAS_POWER_MONITOR_WATTS
98
       FORCE_INLINE static void set_current_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_I, b); }
94
       FORCE_INLINE static void set_current_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_I, b); }
99
       FORCE_INLINE static void toggle_current_display() { TBI(flags, PM_DISP_BIT_I); }
95
       FORCE_INLINE static void toggle_current_display() { TBI(flags, PM_DISP_BIT_I); }
100
     #endif
96
     #endif
101
-    #if HAS_POWER_MONITOR_VREF
97
+    #if ENABLED(POWER_MONITOR_VOLTAGE)
102
       static void draw_voltage();
98
       static void draw_voltage();
103
       FORCE_INLINE static bool voltage_display_enabled() { return TEST(flags, PM_DISP_BIT_V); }
99
       FORCE_INLINE static bool voltage_display_enabled() { return TEST(flags, PM_DISP_BIT_V); }
104
       FORCE_INLINE static void set_voltage_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_V, b); }
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
     #if ENABLED(POWER_MONITOR_CURRENT)
42
     #if ENABLED(POWER_MONITOR_CURRENT)
43
       if (parser.seen('I')) { power_monitor.set_current_display(parser.value_bool()); do_report = false; }
43
       if (parser.seen('I')) { power_monitor.set_current_display(parser.value_bool()); do_report = false; }
44
     #endif
44
     #endif
45
-    #if HAS_POWER_MONITOR_VREF
45
+    #if ENABLED(POWER_MONITOR_VOLTAGE)
46
       if (parser.seen('V')) { power_monitor.set_voltage_display(parser.value_bool()); do_report = false; }
46
       if (parser.seen('V')) { power_monitor.set_voltage_display(parser.value_bool()); do_report = false; }
47
     #endif
47
     #endif
48
     #if HAS_POWER_MONITOR_WATTS
48
     #if HAS_POWER_MONITOR_WATTS
53
     SERIAL_ECHOLNPAIR(
53
     SERIAL_ECHOLNPAIR(
54
       #if ENABLED(POWER_MONITOR_CURRENT)
54
       #if ENABLED(POWER_MONITOR_CURRENT)
55
         "Current: ", power_monitor.getAmps(), "A"
55
         "Current: ", power_monitor.getAmps(), "A"
56
-        #if HAS_POWER_MONITOR_VREF
56
+        #if ENABLED(POWER_MONITOR_VOLTAGE)
57
           "  "
57
           "  "
58
         #endif
58
         #endif
59
       #endif
59
       #endif
60
-      #if HAS_POWER_MONITOR_VREF
60
+      #if ENABLED(POWER_MONITOR_VOLTAGE)
61
         "Voltage: ", power_monitor.getVolts(), "V"
61
         "Voltage: ", power_monitor.getVolts(), "V"
62
       #endif
62
       #endif
63
       #if HAS_POWER_MONITOR_WATTS
63
       #if HAS_POWER_MONITOR_WATTS

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

498
 // Power Monitor sensors
498
 // Power Monitor sensors
499
 #if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
499
 #if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
500
   #define HAS_POWER_MONITOR 1
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
 #endif
504
 #endif
508
 
505
 
509
 // Flag if an EEPROM type is pre-selected
506
 // Flag if an EEPROM type is pre-selected

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

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

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

42
   }
42
   }
43
   #endif
43
   #endif
44
 
44
 
45
-  #if HAS_POWER_MONITOR_VREF
45
+  #if ENABLED(POWER_MONITOR_VOLTAGE)
46
   {
46
   {
47
     bool ena = power_monitor.voltage_display_enabled();
47
     bool ena = power_monitor.voltage_display_enabled();
48
     EDIT_ITEM(bool, MSG_VOLTAGE, &ena, power_monitor.toggle_voltage_display);
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
 // Misc. Functions
119
 // Misc. Functions
120
 //
120
 //
121
 #define LED_PIN                            P1_31
121
 #define LED_PIN                            P1_31
122
+#define POWER_MONITOR_VOLTAGE_PIN       P0_25_A2
122
 
123
 
123
 //
124
 //
124
 // LCD
125
 // LCD
156
   #define SD_MISO_PIN                      P0_17
157
   #define SD_MISO_PIN                      P0_17
157
   #define SD_MOSI_PIN                      P0_18
158
   #define SD_MOSI_PIN                      P0_18
158
   #define SD_SS_PIN                        P0_16
159
   #define SD_SS_PIN                        P0_16
160
+  #define SD_DETECT_PIN                    P1_22
159
 #elif SD_CONNECTION_IS(ONBOARD)
161
 #elif SD_CONNECTION_IS(ONBOARD)
160
-  #undef SD_DETECT_PIN
161
-  #define SD_DETECT_PIN                    P0_27
162
   #define SD_SCK_PIN                       P0_07
162
   #define SD_SCK_PIN                       P0_07
163
   #define SD_MISO_PIN                      P0_08
163
   #define SD_MISO_PIN                      P0_08
164
   #define SD_MOSI_PIN                      P0_09
164
   #define SD_MOSI_PIN                      P0_09

Loading…
Cancel
Save