From 3d73c7836fd357b2d6ab9a8d7fa486ff6033cf32 Mon Sep 17 00:00:00 2001 From: OE1WKL Date: Tue, 10 Dec 2024 16:59:57 +0100 Subject: [PATCH] Fixed battery measurement for M32 w. Heltec WifiKit 3.0 Fixed battery measurement for M32 w. Heltec WifiKit 3.0 --- Software/src/Version 6/MorsePreferences.cpp | 2 +- Software/src/Version 6/m32_v6.ino | 33 +++++++++++++++++---- Software/src/Version 6/morsedefs.h | 6 ++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/Software/src/Version 6/MorsePreferences.cpp b/Software/src/Version 6/MorsePreferences.cpp index a6b78f8..1d087f2 100644 --- a/Software/src/Version 6/MorsePreferences.cpp +++ b/Software/src/Version 6/MorsePreferences.cpp @@ -747,7 +747,7 @@ String MorsePreferences::getValueLine(prefPos pos) { } break; case posVAdjust: - volt = (int16_t) (voltage_raw * (MorsePreferences::vAdjust * 12.9)); // recalculate millivolts for new adjustment + volt = (int16_t) (voltage_raw * (MorsePreferences::vAdjust * VOLT_CALIBRATE)); // recalculate millivolts for new adjustment sprintf(numBuffer, "%4d mV", volt); str = String(numBuffer); break; diff --git a/Software/src/Version 6/m32_v6.ino b/Software/src/Version 6/m32_v6.ino index 839b897..84a4a80 100644 --- a/Software/src/Version 6/m32_v6.ino +++ b/Software/src/Version 6/m32_v6.ino @@ -653,12 +653,16 @@ void displayStartUp(uint16_t volt) { #endif MorseOutput::displayBatteryStatus(volt); //prepare board version, just in case we want to switch to M32protocol later on +#ifdef ARDUINO_heltec_wifi_kit_32_V3 + brd = "M32Pocket"; +#else if (MorsePreferences::boardVersion == 3) brd = "1st edition"; else if (MorsePreferences::boardVersion == 4) brd = "2nd edition"; else brd = "unknown"; +#endif delay(2000); } @@ -2120,7 +2124,10 @@ String cleanUpProSigns( String &input ) { //// measure battery voltage in mV int16_t batteryVoltage() { /// measure battery voltage and return result in milliVolts - +#ifdef PIN_ADC_CTRL + #define ADC_Ctrl PIN_ADC_CTRL + pinMode(ADC_Ctrl,OUTPUT); +#endif #ifdef PIN_VEXT // board version 3 requires Vext being on for reading the battery voltage if (MorsePreferences::boardVersion == 3) @@ -2129,18 +2136,28 @@ int16_t batteryVoltage() { /// measure battery voltage and return result in else if (MorsePreferences::boardVersion == 4) digitalWrite(PIN_VEXT,HIGH); #endif - +#ifdef ARDUINO_heltec_wifi_kit_32_V3 + digitalWrite(ADC_Ctrl,LOW); + delay(100); +#endif double v= 0; int counts = 4; for (int i=0; i 4092) /// invalid measurement return 0; + +#ifndef ARDUINO_heltec_wifi_kit_32_V3 //return -0.000000000009824 * pow(reading,3) + 0.000000016557283 * pow(reading,2) + 0.000854596860691 * reading + 0.065440348345433; return -0.000000000000016 * pow(reading,4) + 0.000000000118171 * pow(reading,3)- 0.000000301211691 * pow(reading,2)+ 0.001109019271794 * reading + 0.034143524634089; -} // Added an improved polynomial, use either, comment out as required + // Added an improved polynomial, use either, comment out as required +#else + return -0.000000000009824 * pow(reading,3) + 0.000000016557283 * pow(reading,2) + 0.000854596860691 * reading + 0.065440348345433; +#endif +} diff --git a/Software/src/Version 6/morsedefs.h b/Software/src/Version 6/morsedefs.h index 1bcd585..4454fa7 100644 --- a/Software/src/Version 6/morsedefs.h +++ b/Software/src/Version 6/morsedefs.h @@ -146,6 +146,12 @@ const int HF_Pin = PIN_HF; // for the HF PWM generation const int HF_Pin = 22; #endif +/// voltage calibration factor +#ifdef ARDUINO_heltec_wifi_kit_32_V3 +#define VOLT_CALIBRATE 18.9 +#else +#define VOLT_CALIBRATE 12.9 +#endif /// where are the touch paddles? #ifdef PIN_TOUCH_LEFT