From 6a24a303f26e7162139b3cc3957d0ec388f3d9ec Mon Sep 17 00:00:00 2001 From: Jahnkeanater Date: Fri, 23 Aug 2024 12:37:00 -0500 Subject: [PATCH 1/8] Update main.cpp to add ADC filters Added an IIR filter with a weight of 90% to the battery voltage, charge voltage, and charging current to reduce the noise in the ADC measurements. --- Firmware/LowLevel/src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/LowLevel/src/main.cpp b/Firmware/LowLevel/src/main.cpp index 61969bbf..a8ea973c 100644 --- a/Firmware/LowLevel/src/main.cpp +++ b/Firmware/LowLevel/src/main.cpp @@ -680,12 +680,12 @@ void loop() { updateNeopixel(); status_message.v_battery = - (float) analogRead(PIN_ANALOG_BATTERY_VOLTAGE) * (3.3f / 4096.0f) * ((VIN_R1 + VIN_R2) / VIN_R2); + ((float) analogRead(PIN_ANALOG_BATTERY_VOLTAGE) * (3.3f / 4096.0f) * ((VIN_R1 + VIN_R2) / VIN_R2)) * 0.1f + status_message.v_battery * 0.9f; status_message.v_charge = - (float) analogRead(PIN_ANALOG_CHARGE_VOLTAGE) * (3.3f / 4096.0f) * ((VIN_R1 + VIN_R2) / VIN_R2); + ((float) analogRead(PIN_ANALOG_CHARGE_VOLTAGE) * (3.3f / 4096.0f) * ((VIN_R1 + VIN_R2) / VIN_R2)) * 0.1f + status_message.v_charge * 0.9f; #ifndef IGNORE_CHARGING_CURRENT status_message.charging_current = - (float) analogRead(PIN_ANALOG_CHARGE_CURRENT) * (3.3f / 4096.0f) / (CURRENT_SENSE_GAIN * R_SHUNT); + ((float) analogRead(PIN_ANALOG_CHARGE_CURRENT) * (3.3f / 4096.0f) / (CURRENT_SENSE_GAIN * R_SHUNT)) * 0.1f + status_message.charging_current * 0.9f; #else status_message.charging_current = -1.0f; #endif From 644bec26661926ff6201e78e9994c332363f9da1 Mon Sep 17 00:00:00 2001 From: Jahnkeanater Date: Fri, 23 Aug 2024 13:09:21 -0500 Subject: [PATCH 2/8] Update main.cpp --- Firmware/LowLevel/src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/LowLevel/src/main.cpp b/Firmware/LowLevel/src/main.cpp index a8ea973c..69d0bf7a 100644 --- a/Firmware/LowLevel/src/main.cpp +++ b/Firmware/LowLevel/src/main.cpp @@ -680,12 +680,12 @@ void loop() { updateNeopixel(); status_message.v_battery = - ((float) analogRead(PIN_ANALOG_BATTERY_VOLTAGE) * (3.3f / 4096.0f) * ((VIN_R1 + VIN_R2) / VIN_R2)) * 0.1f + status_message.v_battery * 0.9f; + ((float) analogRead(PIN_ANALOG_BATTERY_VOLTAGE) * (3.3f / 4096.0f) * ((VIN_R1 + VIN_R2) / VIN_R2)) * 0.2f + status_message.v_battery * 0.8f; status_message.v_charge = - ((float) analogRead(PIN_ANALOG_CHARGE_VOLTAGE) * (3.3f / 4096.0f) * ((VIN_R1 + VIN_R2) / VIN_R2)) * 0.1f + status_message.v_charge * 0.9f; + ((float) analogRead(PIN_ANALOG_CHARGE_VOLTAGE) * (3.3f / 4096.0f) * ((VIN_R1 + VIN_R2) / VIN_R2)) * 0.2f + status_message.v_charge * 0.8f; #ifndef IGNORE_CHARGING_CURRENT status_message.charging_current = - ((float) analogRead(PIN_ANALOG_CHARGE_CURRENT) * (3.3f / 4096.0f) / (CURRENT_SENSE_GAIN * R_SHUNT)) * 0.1f + status_message.charging_current * 0.9f; + ((float) analogRead(PIN_ANALOG_CHARGE_CURRENT) * (3.3f / 4096.0f) / (CURRENT_SENSE_GAIN * R_SHUNT)) * 0.2f + status_message.charging_current * 0.8f; #else status_message.charging_current = -1.0f; #endif From c3962f10ec043832e9934d4662ef4470c0ed4cdb Mon Sep 17 00:00:00 2001 From: Jahnkeanater Date: Tue, 27 Aug 2024 20:40:52 -0500 Subject: [PATCH 3/8] Update pins.h added GPOI23 GPIO23 is connected to the PS pin of the onboard RT6150B-33GQW, if it's LOW (default) it's in PFM mode for best efficiency, if it's HIGH it's in PWM mode for improved ripple but worse efficiency at light loads. PWM mode should improve the ADC noise. --- Firmware/LowLevel/src/pins.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Firmware/LowLevel/src/pins.h b/Firmware/LowLevel/src/pins.h index dd79ce9e..055bb895 100644 --- a/Firmware/LowLevel/src/pins.h +++ b/Firmware/LowLevel/src/pins.h @@ -6,6 +6,8 @@ #define PIN_ANALOG_CHARGE_VOLTAGE 26 #define PIN_ANALOG_CHARGE_CURRENT 28 +#define PIN_POWER_SELECT 23 + #define PIN_ENABLE_CHARGE 22 #define PIN_ESC_SHUTDOWN 20 @@ -58,6 +60,8 @@ #define PIN_ANALOG_CHARGE_VOLTAGE 26 #define PIN_ANALOG_CHARGE_CURRENT 28 +#define PIN_POWER_SELECT 23 + #define PIN_ENABLE_CHARGE 22 #define PIN_ESC_SHUTDOWN 20 @@ -94,6 +98,8 @@ #define PIN_ANALOG_CHARGE_VOLTAGE 26 #define PIN_ANALOG_CHARGE_CURRENT 28 +#define PIN_POWER_SELECT 23 + #define PIN_ENABLE_CHARGE 22 #define PIN_ESC_SHUTDOWN 20 From 4528d24bcb8858bce0854a7451bcffa235a41caf Mon Sep 17 00:00:00 2001 From: Jahnkeanater Date: Tue, 27 Aug 2024 20:45:52 -0500 Subject: [PATCH 4/8] Update main.cpp Pull GPIO23 High GPIO23 is connected to the PS pin of the onboard RT6150B-33GQW, if it's LOW (default) it's in PFM mode for best efficiency, if it's HIGH it's in PWM mode for improved ripple but worse efficiency at light loads. PWM mode should improve the ADC noise. --- Firmware/LowLevel/src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Firmware/LowLevel/src/main.cpp b/Firmware/LowLevel/src/main.cpp index 69d0bf7a..ab1079f4 100644 --- a/Firmware/LowLevel/src/main.cpp +++ b/Firmware/LowLevel/src/main.cpp @@ -325,6 +325,8 @@ void manageUISubscriptions() void setup1() { // Core digitalWrite(LED_BUILTIN, HIGH); + // Put the 3.3V power supply into PWM mode. + digitalWrite(PIN_POWER_SELECT, true); } void loop1() { From b47ebe8e8df5d0e341c0769e97d8f5d5494a4be1 Mon Sep 17 00:00:00 2001 From: Jahnkeanater Date: Tue, 27 Aug 2024 20:53:58 -0500 Subject: [PATCH 5/8] Update main.cpp --- Firmware/LowLevel/src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Firmware/LowLevel/src/main.cpp b/Firmware/LowLevel/src/main.cpp index ab1079f4..f1e2f726 100644 --- a/Firmware/LowLevel/src/main.cpp +++ b/Firmware/LowLevel/src/main.cpp @@ -326,7 +326,7 @@ void setup1() { // Core digitalWrite(LED_BUILTIN, HIGH); // Put the 3.3V power supply into PWM mode. - digitalWrite(PIN_POWER_SELECT, true); + digitalWrite(PIN_POWER_SELECT, HIGH); } void loop1() { @@ -387,6 +387,7 @@ void setup() { // Setup pins pinMode(LED_BUILTIN, OUTPUT); + pinMode(PIN_POWER_SELECT, OUTPUT); pinMode(PIN_ENABLE_CHARGE, OUTPUT); digitalWrite(PIN_ENABLE_CHARGE, HIGH); From 303153498bfa793ca0d1445ecc85263d4b4f3a05 Mon Sep 17 00:00:00 2001 From: Jahnkeanater Date: Tue, 27 Aug 2024 21:16:09 -0500 Subject: [PATCH 6/8] Olliewalsh already tried this Looks like other people have already proved that PWM mode doesn't improve the noise. --- Firmware/LowLevel/src/main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Firmware/LowLevel/src/main.cpp b/Firmware/LowLevel/src/main.cpp index f1e2f726..b59611e5 100644 --- a/Firmware/LowLevel/src/main.cpp +++ b/Firmware/LowLevel/src/main.cpp @@ -325,8 +325,6 @@ void manageUISubscriptions() void setup1() { // Core digitalWrite(LED_BUILTIN, HIGH); - // Put the 3.3V power supply into PWM mode. - digitalWrite(PIN_POWER_SELECT, HIGH); } void loop1() { From 3914ca397c4d143349bd274d4d3b8a2cf293641a Mon Sep 17 00:00:00 2001 From: Jahnkeanater Date: Tue, 27 Aug 2024 21:18:21 -0500 Subject: [PATCH 7/8] Update pins.h --- Firmware/LowLevel/src/pins.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Firmware/LowLevel/src/pins.h b/Firmware/LowLevel/src/pins.h index 055bb895..dd79ce9e 100644 --- a/Firmware/LowLevel/src/pins.h +++ b/Firmware/LowLevel/src/pins.h @@ -6,8 +6,6 @@ #define PIN_ANALOG_CHARGE_VOLTAGE 26 #define PIN_ANALOG_CHARGE_CURRENT 28 -#define PIN_POWER_SELECT 23 - #define PIN_ENABLE_CHARGE 22 #define PIN_ESC_SHUTDOWN 20 @@ -60,8 +58,6 @@ #define PIN_ANALOG_CHARGE_VOLTAGE 26 #define PIN_ANALOG_CHARGE_CURRENT 28 -#define PIN_POWER_SELECT 23 - #define PIN_ENABLE_CHARGE 22 #define PIN_ESC_SHUTDOWN 20 @@ -98,8 +94,6 @@ #define PIN_ANALOG_CHARGE_VOLTAGE 26 #define PIN_ANALOG_CHARGE_CURRENT 28 -#define PIN_POWER_SELECT 23 - #define PIN_ENABLE_CHARGE 22 #define PIN_ESC_SHUTDOWN 20 From 7bee7d66769b9d400a7f16bde9165c0e382724d2 Mon Sep 17 00:00:00 2001 From: Jahnkeanater Date: Tue, 27 Aug 2024 21:19:05 -0500 Subject: [PATCH 8/8] Update main.cpp --- Firmware/LowLevel/src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Firmware/LowLevel/src/main.cpp b/Firmware/LowLevel/src/main.cpp index b59611e5..69d0bf7a 100644 --- a/Firmware/LowLevel/src/main.cpp +++ b/Firmware/LowLevel/src/main.cpp @@ -385,7 +385,6 @@ void setup() { // Setup pins pinMode(LED_BUILTIN, OUTPUT); - pinMode(PIN_POWER_SELECT, OUTPUT); pinMode(PIN_ENABLE_CHARGE, OUTPUT); digitalWrite(PIN_ENABLE_CHARGE, HIGH);