From b64113411c83d6f6f6947d9ae94faa65406d32dd Mon Sep 17 00:00:00 2001 From: cccc Date: Fri, 10 Jul 2020 11:43:04 +0800 Subject: [PATCH] Add current offset for POWER_MONITOR sensor (#18600) --- Marlin/Configuration_adv.h | 1 + Marlin/src/feature/power_monitor.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index f1c52a0ee..e102cb411 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3029,6 +3029,7 @@ //#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! #define POWER_MONITOR_FIXED_VOLTAGE 13.6 // Voltage for a current sensor with no voltage sensor (for power display) #endif diff --git a/Marlin/src/feature/power_monitor.h b/Marlin/src/feature/power_monitor.h index 00b45b0f9..9db356d7b 100644 --- a/Marlin/src/feature/power_monitor.h +++ b/Marlin/src/feature/power_monitor.h @@ -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)))); + value = filter_buf * (SCALE * (1.0f / (1UL << (PM_K_VALUE + PM_K_SCALE)))) + (POWER_MONITOR_CURRENT_OFFSET); } void reset(uint16_t reset_value = 0) { filter_buf = uint32_t(reset_value) << (K_VALUE + K_SCALE);