Battery sense for T-Echo

Copied battery stuff from RAK4631 to T-Echo
I got the voltage divider figures for T_Echo from SoftRF at
https://github.com/lyusupov/SoftRF/blob/master/software/firmware/source/SoftRF/src/platform/nRF52.h

I dont have a T-Echo so this code
HAS NOT BEEN TESTED
1.2-legacy
claes 2021-08-10 10:07:40 +02:00
rodzic 04c5ac0d7c
commit 5110a6de82
2 zmienionych plików z 21 dodań i 1 usunięć

Wyświetl plik

@ -299,7 +299,7 @@ void PowerFSM_setup()
// On most boards we use light-sleep to be our main state, but on NRF52 we just stay in DARK // On most boards we use light-sleep to be our main state, but on NRF52 we just stay in DARK
State *lowPowerState = &stateLS; State *lowPowerState = &stateLS;
auto meshSds = 0; uint32_t meshSds = 0;
#ifndef NRF52_SERIES #ifndef NRF52_SERIES
// We never enter light-sleep or NB states on NRF52 (because the CPU uses so little power normally) // We never enter light-sleep or NB states on NRF52 (because the CPU uses so little power normally)

Wyświetl plik

@ -251,6 +251,26 @@ External serial flash WP25R1635FZUIL0
// To debug via the segger JLINK console rather than the CDC-ACM serial device // To debug via the segger JLINK console rather than the CDC-ACM serial device
// #define USE_SEGGER // #define USE_SEGGER
// Battery
// The battery sense is hooked to pin A0 (4)
// it is defined in the anlaolgue pin section of this file
// and has 12 bit resolution
#define BATTERY_SENSE_RESOLUTION_BITS 12
#define BATTERY_SENSE_RESOLUTION 4096.0
// Definition of milliVolt per LSB => 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096
#define VBAT_MV_PER_LSB (0.73242188F)
// Voltage divider value => 100K + 100K voltage divider on VBAT = (100K / (100K + 100K))
#define VBAT_DIVIDER (0.5F)
// Compensation factor for the VBAT divider
#define VBAT_DIVIDER_COMP (2.0)
// Fixed calculation of milliVolt from compensation value
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
#undef AREF_VOLTAGE
#define AREF_VOLTAGE 3.0
#define VBAT_AR_INTERNAL AR_INTERNAL_3_0
#define ADC_MULTIPLIER VBAT_DIVIDER_COMP
#define VBAT_RAW_TO_SCALED(x) (REAL_VBAT_MV_PER_LSB * x)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif