mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-27 13:56:24 +00:00
Fix and improve Power Monitor (#21551)
This commit is contained in:
parent
896123513e
commit
02a99e3f0b
@ -3306,13 +3306,18 @@
|
||||
*/
|
||||
//#define POWER_MONITOR_CURRENT // Monitor the system current
|
||||
//#define POWER_MONITOR_VOLTAGE // Monitor the system voltage
|
||||
#if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
|
||||
#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_VOLTS_PER_VOLT 0.11786 // Input voltage to the MCU analog pin per volt - DO NOT apply more than ADC_VREF!
|
||||
|
||||
#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_CURRENT_OFFSET 0 // Offset (in amps) applied to the calculated current
|
||||
#define POWER_MONITOR_FIXED_VOLTAGE 13.6 // Voltage for a current sensor with no voltage sensor (for power display)
|
||||
#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
|
||||
*
|
||||
|
@ -26,8 +26,11 @@
|
||||
|
||||
#include "power_monitor.h"
|
||||
|
||||
#include "../lcd/marlinui.h"
|
||||
#include "../lcd/lcdprint.h"
|
||||
#if HAS_LCD_MENU
|
||||
#include "../lcd/marlinui.h"
|
||||
#include "../lcd/lcdprint.h"
|
||||
#endif
|
||||
|
||||
#include "../libs/numtostr.h"
|
||||
|
||||
uint8_t PowerMonitor::flags; // = 0
|
||||
@ -54,7 +57,7 @@ PowerMonitor power_monitor; // Single instance - this calls the constructor
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAS_POWER_MONITOR_VREF
|
||||
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||
void PowerMonitor::draw_voltage() {
|
||||
const float volts = getVolts();
|
||||
lcd_put_u8str(volts < 100 ? ftostr31ns(volts) : ui16tostr4rj((uint16_t)volts));
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include "../inc/MarlinConfig.h"
|
||||
|
||||
#define PM_SAMPLE_RANGE 1024
|
||||
#define PM_SAMPLE_RANGE HAL_ADC_RANGE
|
||||
#define PM_K_VALUE 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);
|
||||
}
|
||||
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) {
|
||||
filter_buf = uint32_t(reset_value) << (K_VALUE + K_SCALE);
|
||||
@ -69,19 +69,15 @@ public:
|
||||
};
|
||||
|
||||
#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); }
|
||||
#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)
|
||||
void add_voltage_sample(const uint16_t value) { volts.add_sample(value); }
|
||||
#endif
|
||||
#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); }
|
||||
#else
|
||||
FORCE_INLINE static float getVolts() { return POWER_MONITOR_FIXED_VOLTAGE; }
|
||||
#endif
|
||||
|
||||
#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 toggle_current_display() { TBI(flags, PM_DISP_BIT_I); }
|
||||
#endif
|
||||
#if HAS_POWER_MONITOR_VREF
|
||||
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||
static void draw_voltage();
|
||||
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); }
|
||||
|
@ -42,7 +42,7 @@ void GcodeSuite::M430() {
|
||||
#if ENABLED(POWER_MONITOR_CURRENT)
|
||||
if (parser.seen('I')) { power_monitor.set_current_display(parser.value_bool()); do_report = false; }
|
||||
#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; }
|
||||
#endif
|
||||
#if HAS_POWER_MONITOR_WATTS
|
||||
@ -53,11 +53,11 @@ void GcodeSuite::M430() {
|
||||
SERIAL_ECHOLNPAIR(
|
||||
#if ENABLED(POWER_MONITOR_CURRENT)
|
||||
"Current: ", power_monitor.getAmps(), "A"
|
||||
#if HAS_POWER_MONITOR_VREF
|
||||
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||
" "
|
||||
#endif
|
||||
#endif
|
||||
#if HAS_POWER_MONITOR_VREF
|
||||
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||
"Voltage: ", power_monitor.getVolts(), "V"
|
||||
#endif
|
||||
#if HAS_POWER_MONITOR_WATTS
|
||||
|
@ -498,12 +498,9 @@
|
||||
// Power Monitor sensors
|
||||
#if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
|
||||
#define HAS_POWER_MONITOR 1
|
||||
#endif
|
||||
#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
|
||||
#if ENABLED(POWER_MONITOR_CURRENT) && (ENABLED(POWER_MONITOR_VOLTAGE) || defined(POWER_MONITOR_FIXED_VOLTAGE))
|
||||
#define HAS_POWER_MONITOR_WATTS 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Flag if an EEPROM type is pre-selected
|
||||
|
@ -136,7 +136,7 @@
|
||||
#if ENABLED(POWER_MONITOR_CURRENT)
|
||||
const bool iflag = power_monitor.current_display_enabled();
|
||||
#endif
|
||||
#if HAS_POWER_MONITOR_VREF
|
||||
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||
const bool vflag = power_monitor.voltage_display_enabled();
|
||||
#endif
|
||||
|
||||
@ -148,7 +148,7 @@
|
||||
}
|
||||
#elif ENABLED(POWER_MONITOR_CURRENT)
|
||||
power_monitor.display_item = 0;
|
||||
#elif HAS_POWER_MONITOR_VREF
|
||||
#elif ENABLED(POWER_MONITOR_VOLTAGE)
|
||||
power_monitor.display_item = 1;
|
||||
#endif
|
||||
|
||||
@ -157,7 +157,7 @@
|
||||
#if ENABLED(POWER_MONITOR_CURRENT)
|
||||
if (power_monitor.display_item == 0 && !iflag) ++power_monitor.display_item;
|
||||
#endif
|
||||
#if HAS_POWER_MONITOR_VREF
|
||||
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||
if (power_monitor.display_item == 1 && !vflag) ++power_monitor.display_item;
|
||||
#endif
|
||||
#if HAS_POWER_MONITOR_WATTS
|
||||
@ -170,7 +170,7 @@
|
||||
#if ENABLED(POWER_MONITOR_CURRENT) // Current
|
||||
case 0: if (iflag) power_monitor.draw_current(); break;
|
||||
#endif
|
||||
#if HAS_POWER_MONITOR_VREF // Voltage
|
||||
#if ENABLED(POWER_MONITOR_VOLTAGE) // Voltage
|
||||
case 1: if (vflag) power_monitor.draw_voltage(); break;
|
||||
#endif
|
||||
#if HAS_POWER_MONITOR_WATTS // Power
|
||||
|
@ -42,7 +42,7 @@ void menu_power_monitor() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAS_POWER_MONITOR_VREF
|
||||
#if ENABLED(POWER_MONITOR_VOLTAGE)
|
||||
{
|
||||
bool ena = power_monitor.voltage_display_enabled();
|
||||
EDIT_ITEM(bool, MSG_VOLTAGE, &ena, power_monitor.toggle_voltage_display);
|
||||
|
@ -119,6 +119,7 @@
|
||||
// Misc. Functions
|
||||
//
|
||||
#define LED_PIN P1_31
|
||||
#define POWER_MONITOR_VOLTAGE_PIN P0_25_A2
|
||||
|
||||
//
|
||||
// LCD
|
||||
@ -156,9 +157,8 @@
|
||||
#define SD_MISO_PIN P0_17
|
||||
#define SD_MOSI_PIN P0_18
|
||||
#define SD_SS_PIN P0_16
|
||||
#define SD_DETECT_PIN P1_22
|
||||
#elif SD_CONNECTION_IS(ONBOARD)
|
||||
#undef SD_DETECT_PIN
|
||||
#define SD_DETECT_PIN P0_27
|
||||
#define SD_SCK_PIN P0_07
|
||||
#define SD_MISO_PIN P0_08
|
||||
#define SD_MOSI_PIN P0_09
|
||||
|
Loading…
Reference in New Issue
Block a user