From e846c38f97d86108ebcc413baa305e0b185d183d Mon Sep 17 00:00:00 2001 From: richonguzman Date: Thu, 27 Jun 2024 15:39:53 -0400 Subject: [PATCH] externalBatdivider --- data_embed/index.html | 24 ++++++++++++++++++++---- data_embed/script.js | 4 ++-- src/battery_utils.cpp | 12 ++++-------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/data_embed/index.html b/data_embed/index.html index 09b18d2..3bb189c 100644 --- a/data_embed/index.html +++ b/data_embed/index.html @@ -1018,9 +1018,16 @@
- + kOhm
@@ -1075,7 +1082,16 @@
- + kOhm
diff --git a/data_embed/script.js b/data_embed/script.js index 8f012ab..6876fbc 100644 --- a/data_embed/script.js +++ b/data_embed/script.js @@ -162,8 +162,8 @@ function loadSettings(settings) { document.getElementById("battery.internalSleepVoltage").value = settings.battery.internalSleepVoltage.toFixed(1); document.getElementById("battery.sendExternalVoltage").checked = settings.battery.sendExternalVoltage; document.getElementById("battery.externalVoltagePin").value = settings.battery.externalVoltagePin; - document.getElementById("battery.voltageDividerR1").value = settings.battery.voltageDividerR1; - document.getElementById("battery.voltageDividerR2").value = settings.battery.voltageDividerR2; + document.getElementById("battery.voltageDividerR1").value = settings.battery.voltageDividerR1.toFixed(1); + document.getElementById("battery.voltageDividerR2").value = settings.battery.voltageDividerR2.toFixed(1); document.getElementById("battery.monitorExternalVoltage").checked = settings.battery.monitorExternalVoltage; document.getElementById("battery.externalSleepVoltage").value = settings.battery.externalSleepVoltage.toFixed(1); diff --git a/src/battery_utils.cpp b/src/battery_utils.cpp index c9f5a9d..2d46bd4 100644 --- a/src/battery_utils.cpp +++ b/src/battery_utils.cpp @@ -12,12 +12,8 @@ bool shouldSleepLowVoltage = false; float adcReadingTransformation = (3.3/4095); float voltageDividerCorrection = 0.288; - -// for External Voltage Measurment (MAX = 15Volts !!!) -float R1 = 100.000; //in Kilo-Ohms -float R2 = 27.000; //in Kilo-Ohms -float readingCorrection = 0.125; -float multiplyCorrection = 0.035; +float readingCorrection = 0.125; +float multiplyCorrection = 0.035; namespace BATTERY_Utils { @@ -81,8 +77,8 @@ namespace BATTERY_Utils { sampleSum += sample; delayMicroseconds(50); } - - float voltage = ((((sampleSum/100)* adcReadingTransformation) + readingCorrection) * ((R1+R2)/R2)) - multiplyCorrection; + float voltageDividerTransformation = (Config.battery.voltageDividerR1 + Config.battery.voltageDividerR2) / Config.battery.voltageDividerR2; + float voltage = ((((sampleSum/100)* adcReadingTransformation) + readingCorrection) * voltageDividerTransformation) - multiplyCorrection; return voltage; // raw voltage without mapping