Fix and improve Power Monitor (#21551)
This commit is contained in:
parent
84c79d7531
commit
a5f0075a60
@ -3306,13 +3306,18 @@
|
|||||||
*/
|
*/
|
||||||
//#define POWER_MONITOR_CURRENT // Monitor the system current
|
//#define POWER_MONITOR_CURRENT // Monitor the system current
|
||||||
//#define POWER_MONITOR_VOLTAGE // Monitor the system voltage
|
//#define POWER_MONITOR_VOLTAGE // Monitor the system voltage
|
||||||
#if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
|
|
||||||
|
#if ENABLED(POWER_MONITOR_CURRENT)
|
||||||
#define POWER_MONITOR_VOLTS_PER_AMP 0.05000 // Input voltage to the MCU analog pin per amp - DO NOT apply more than ADC_VREF!
|
#define POWER_MONITOR_VOLTS_PER_AMP 0.05000 // Input voltage to the MCU analog pin per amp - DO NOT apply more than ADC_VREF!
|
||||||
#define POWER_MONITOR_CURRENT_OFFSET -1 // Offset value for current sensors with linear function output
|
#define POWER_MONITOR_CURRENT_OFFSET 0 // Offset (in amps) applied to the calculated current
|
||||||
#define POWER_MONITOR_VOLTS_PER_VOLT 0.11786 // Input voltage to the MCU analog pin per volt - DO NOT apply more than ADC_VREF!
|
|
||||||
#define POWER_MONITOR_FIXED_VOLTAGE 13.6 // Voltage for a current sensor with no voltage sensor (for power display)
|
#define POWER_MONITOR_FIXED_VOLTAGE 13.6 // Voltage for a current sensor with no voltage sensor (for power display)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||||
|
#define POWER_MONITOR_VOLTS_PER_VOLT 0.077933 // Input voltage to the MCU analog pin per volt - DO NOT apply more than ADC_VREF!
|
||||||
|
#define POWER_MONITOR_VOLTAGE_OFFSET 0 // Offset (in volts) applied to the calculated voltage
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CNC Coordinate Systems
|
* CNC Coordinate Systems
|
||||||
*
|
*
|
||||||
|
@ -26,8 +26,11 @@
|
|||||||
|
|
||||||
#include "power_monitor.h"
|
#include "power_monitor.h"
|
||||||
|
|
||||||
#include "../lcd/marlinui.h"
|
#if HAS_LCD_MENU
|
||||||
#include "../lcd/lcdprint.h"
|
#include "../lcd/marlinui.h"
|
||||||
|
#include "../lcd/lcdprint.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "../libs/numtostr.h"
|
#include "../libs/numtostr.h"
|
||||||
|
|
||||||
uint8_t PowerMonitor::flags; // = 0
|
uint8_t PowerMonitor::flags; // = 0
|
||||||
@ -54,7 +57,7 @@ PowerMonitor power_monitor; // Single instance - this calls the constructor
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_POWER_MONITOR_VREF
|
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||||
void PowerMonitor::draw_voltage() {
|
void PowerMonitor::draw_voltage() {
|
||||||
const float volts = getVolts();
|
const float volts = getVolts();
|
||||||
lcd_put_u8str(volts < 100 ? ftostr31ns(volts) : ui16tostr4rj((uint16_t)volts));
|
lcd_put_u8str(volts < 100 ? ftostr31ns(volts) : ui16tostr4rj((uint16_t)volts));
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "../inc/MarlinConfig.h"
|
#include "../inc/MarlinConfig.h"
|
||||||
|
|
||||||
#define PM_SAMPLE_RANGE 1024
|
#define PM_SAMPLE_RANGE HAL_ADC_RANGE
|
||||||
#define PM_K_VALUE 6
|
#define PM_K_VALUE 6
|
||||||
#define PM_K_SCALE 6
|
#define PM_K_SCALE 6
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ struct pm_lpf_t {
|
|||||||
filter_buf = filter_buf - (filter_buf >> K_VALUE) + (uint32_t(sample) << K_SCALE);
|
filter_buf = filter_buf - (filter_buf >> K_VALUE) + (uint32_t(sample) << K_SCALE);
|
||||||
}
|
}
|
||||||
void capture() {
|
void capture() {
|
||||||
value = filter_buf * (SCALE * (1.0f / (1UL << (PM_K_VALUE + PM_K_SCALE)))) + (POWER_MONITOR_CURRENT_OFFSET);
|
value = filter_buf * (SCALE * (1.0f / (1UL << (PM_K_VALUE + PM_K_SCALE))));
|
||||||
}
|
}
|
||||||
void reset(uint16_t reset_value = 0) {
|
void reset(uint16_t reset_value = 0) {
|
||||||
filter_buf = uint32_t(reset_value) << (K_VALUE + K_SCALE);
|
filter_buf = uint32_t(reset_value) << (K_VALUE + K_SCALE);
|
||||||
@ -69,19 +69,15 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if ENABLED(POWER_MONITOR_CURRENT)
|
#if ENABLED(POWER_MONITOR_CURRENT)
|
||||||
FORCE_INLINE static float getAmps() { return amps.value; }
|
FORCE_INLINE static float getAmps() { return amps.value + (POWER_MONITOR_CURRENT_OFFSET); }
|
||||||
void add_current_sample(const uint16_t value) { amps.add_sample(value); }
|
void add_current_sample(const uint16_t value) { amps.add_sample(value); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_POWER_MONITOR_VREF
|
|
||||||
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
|
||||||
FORCE_INLINE static float getVolts() { return volts.value; }
|
|
||||||
#else
|
|
||||||
FORCE_INLINE static float getVolts() { return POWER_MONITOR_FIXED_VOLTAGE; } // using a specified fixed valtage as the voltage measurement
|
|
||||||
#endif
|
|
||||||
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||||
|
FORCE_INLINE static float getVolts() { return volts.value + (POWER_MONITOR_VOLTAGE_OFFSET); }
|
||||||
void add_voltage_sample(const uint16_t value) { volts.add_sample(value); }
|
void add_voltage_sample(const uint16_t value) { volts.add_sample(value); }
|
||||||
#endif
|
#else
|
||||||
|
FORCE_INLINE static float getVolts() { return POWER_MONITOR_FIXED_VOLTAGE; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_POWER_MONITOR_WATTS
|
#if HAS_POWER_MONITOR_WATTS
|
||||||
@ -98,7 +94,7 @@ public:
|
|||||||
FORCE_INLINE static void set_current_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_I, b); }
|
FORCE_INLINE static void set_current_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_I, b); }
|
||||||
FORCE_INLINE static void toggle_current_display() { TBI(flags, PM_DISP_BIT_I); }
|
FORCE_INLINE static void toggle_current_display() { TBI(flags, PM_DISP_BIT_I); }
|
||||||
#endif
|
#endif
|
||||||
#if HAS_POWER_MONITOR_VREF
|
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||||
static void draw_voltage();
|
static void draw_voltage();
|
||||||
FORCE_INLINE static bool voltage_display_enabled() { return TEST(flags, PM_DISP_BIT_V); }
|
FORCE_INLINE static bool voltage_display_enabled() { return TEST(flags, PM_DISP_BIT_V); }
|
||||||
FORCE_INLINE static void set_voltage_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_V, b); }
|
FORCE_INLINE static void set_voltage_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_V, b); }
|
||||||
|
@ -42,7 +42,7 @@ void GcodeSuite::M430() {
|
|||||||
#if ENABLED(POWER_MONITOR_CURRENT)
|
#if ENABLED(POWER_MONITOR_CURRENT)
|
||||||
if (parser.seen('I')) { power_monitor.set_current_display(parser.value_bool()); do_report = false; }
|
if (parser.seen('I')) { power_monitor.set_current_display(parser.value_bool()); do_report = false; }
|
||||||
#endif
|
#endif
|
||||||
#if HAS_POWER_MONITOR_VREF
|
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||||
if (parser.seen('V')) { power_monitor.set_voltage_display(parser.value_bool()); do_report = false; }
|
if (parser.seen('V')) { power_monitor.set_voltage_display(parser.value_bool()); do_report = false; }
|
||||||
#endif
|
#endif
|
||||||
#if HAS_POWER_MONITOR_WATTS
|
#if HAS_POWER_MONITOR_WATTS
|
||||||
@ -53,11 +53,11 @@ void GcodeSuite::M430() {
|
|||||||
SERIAL_ECHOLNPAIR(
|
SERIAL_ECHOLNPAIR(
|
||||||
#if ENABLED(POWER_MONITOR_CURRENT)
|
#if ENABLED(POWER_MONITOR_CURRENT)
|
||||||
"Current: ", power_monitor.getAmps(), "A"
|
"Current: ", power_monitor.getAmps(), "A"
|
||||||
#if HAS_POWER_MONITOR_VREF
|
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||||
" "
|
" "
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if HAS_POWER_MONITOR_VREF
|
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||||
"Voltage: ", power_monitor.getVolts(), "V"
|
"Voltage: ", power_monitor.getVolts(), "V"
|
||||||
#endif
|
#endif
|
||||||
#if HAS_POWER_MONITOR_WATTS
|
#if HAS_POWER_MONITOR_WATTS
|
||||||
|
@ -498,12 +498,9 @@
|
|||||||
// Power Monitor sensors
|
// Power Monitor sensors
|
||||||
#if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
|
#if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
|
||||||
#define HAS_POWER_MONITOR 1
|
#define HAS_POWER_MONITOR 1
|
||||||
#endif
|
#if ENABLED(POWER_MONITOR_CURRENT) && (ENABLED(POWER_MONITOR_VOLTAGE) || defined(POWER_MONITOR_FIXED_VOLTAGE))
|
||||||
#if ENABLED(POWER_MONITOR_CURRENT) && defined(POWER_MONITOR_FIXED_VOLTAGE)
|
|
||||||
#define HAS_POWER_MONITOR_VREF 1
|
|
||||||
#endif
|
|
||||||
#if BOTH(HAS_POWER_MONITOR_VREF, POWER_MONITOR_CURRENT)
|
|
||||||
#define HAS_POWER_MONITOR_WATTS 1
|
#define HAS_POWER_MONITOR_WATTS 1
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Flag if an EEPROM type is pre-selected
|
// Flag if an EEPROM type is pre-selected
|
||||||
|
@ -136,7 +136,7 @@
|
|||||||
#if ENABLED(POWER_MONITOR_CURRENT)
|
#if ENABLED(POWER_MONITOR_CURRENT)
|
||||||
const bool iflag = power_monitor.current_display_enabled();
|
const bool iflag = power_monitor.current_display_enabled();
|
||||||
#endif
|
#endif
|
||||||
#if HAS_POWER_MONITOR_VREF
|
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||||
const bool vflag = power_monitor.voltage_display_enabled();
|
const bool vflag = power_monitor.voltage_display_enabled();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -148,7 +148,7 @@
|
|||||||
}
|
}
|
||||||
#elif ENABLED(POWER_MONITOR_CURRENT)
|
#elif ENABLED(POWER_MONITOR_CURRENT)
|
||||||
power_monitor.display_item = 0;
|
power_monitor.display_item = 0;
|
||||||
#elif HAS_POWER_MONITOR_VREF
|
#elif ENABLED(POWER_MONITOR_VOLTAGE)
|
||||||
power_monitor.display_item = 1;
|
power_monitor.display_item = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -157,7 +157,7 @@
|
|||||||
#if ENABLED(POWER_MONITOR_CURRENT)
|
#if ENABLED(POWER_MONITOR_CURRENT)
|
||||||
if (power_monitor.display_item == 0 && !iflag) ++power_monitor.display_item;
|
if (power_monitor.display_item == 0 && !iflag) ++power_monitor.display_item;
|
||||||
#endif
|
#endif
|
||||||
#if HAS_POWER_MONITOR_VREF
|
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||||
if (power_monitor.display_item == 1 && !vflag) ++power_monitor.display_item;
|
if (power_monitor.display_item == 1 && !vflag) ++power_monitor.display_item;
|
||||||
#endif
|
#endif
|
||||||
#if HAS_POWER_MONITOR_WATTS
|
#if HAS_POWER_MONITOR_WATTS
|
||||||
@ -170,7 +170,7 @@
|
|||||||
#if ENABLED(POWER_MONITOR_CURRENT) // Current
|
#if ENABLED(POWER_MONITOR_CURRENT) // Current
|
||||||
case 0: if (iflag) power_monitor.draw_current(); break;
|
case 0: if (iflag) power_monitor.draw_current(); break;
|
||||||
#endif
|
#endif
|
||||||
#if HAS_POWER_MONITOR_VREF // Voltage
|
#if ENABLED(POWER_MONITOR_VOLTAGE) // Voltage
|
||||||
case 1: if (vflag) power_monitor.draw_voltage(); break;
|
case 1: if (vflag) power_monitor.draw_voltage(); break;
|
||||||
#endif
|
#endif
|
||||||
#if HAS_POWER_MONITOR_WATTS // Power
|
#if HAS_POWER_MONITOR_WATTS // Power
|
||||||
|
@ -42,7 +42,7 @@ void menu_power_monitor() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_POWER_MONITOR_VREF
|
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||||
{
|
{
|
||||||
bool ena = power_monitor.voltage_display_enabled();
|
bool ena = power_monitor.voltage_display_enabled();
|
||||||
EDIT_ITEM(bool, MSG_VOLTAGE, &ena, power_monitor.toggle_voltage_display);
|
EDIT_ITEM(bool, MSG_VOLTAGE, &ena, power_monitor.toggle_voltage_display);
|
||||||
|
@ -119,6 +119,7 @@
|
|||||||
// Misc. Functions
|
// Misc. Functions
|
||||||
//
|
//
|
||||||
#define LED_PIN P1_31
|
#define LED_PIN P1_31
|
||||||
|
#define POWER_MONITOR_VOLTAGE_PIN P0_25_A2
|
||||||
|
|
||||||
//
|
//
|
||||||
// LCD
|
// LCD
|
||||||
@ -156,9 +157,8 @@
|
|||||||
#define SD_MISO_PIN P0_17
|
#define SD_MISO_PIN P0_17
|
||||||
#define SD_MOSI_PIN P0_18
|
#define SD_MOSI_PIN P0_18
|
||||||
#define SD_SS_PIN P0_16
|
#define SD_SS_PIN P0_16
|
||||||
|
#define SD_DETECT_PIN P1_22
|
||||||
#elif SD_CONNECTION_IS(ONBOARD)
|
#elif SD_CONNECTION_IS(ONBOARD)
|
||||||
#undef SD_DETECT_PIN
|
|
||||||
#define SD_DETECT_PIN P0_27
|
|
||||||
#define SD_SCK_PIN P0_07
|
#define SD_SCK_PIN P0_07
|
||||||
#define SD_MISO_PIN P0_08
|
#define SD_MISO_PIN P0_08
|
||||||
#define SD_MOSI_PIN P0_09
|
#define SD_MOSI_PIN P0_09
|
||||||
|
Loading…
Reference in New Issue
Block a user