diff options
author | Seon Rozenblum <seon@unexpectedmaker.com> | 2023-09-27 20:38:35 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2023-09-29 14:09:15 +1000 |
commit | 77ae0a0948d5c4de4efecefbba27f9aded9b79e2 (patch) | |
tree | 9d04ca51c8138b4c4ad0434a4f9590c67e2aa194 | |
parent | 276bfa3146534f5b6a0130309f3b166fb2a77e25 (diff) | |
download | micropython-77ae0a0948d5c4de4efecefbba27f9aded9b79e2.tar.gz micropython-77ae0a0948d5c4de4efecefbba27f9aded9b79e2.zip |
esp32/boards: Fix VBAT voltage calculation for UM S3 boards.
Signed-off-by: Seon Rozenblum <seon@unexpectedmaker.com>
-rw-r--r-- | ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py | 3 | ||||
-rw-r--r-- | ports/esp32/boards/UM_PROS3/modules/pros3.py | 3 | ||||
-rw-r--r-- | ports/esp32/boards/UM_TINYS3/modules/tinys3.py | 3 |
3 files changed, 6 insertions, 3 deletions
diff --git a/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py b/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py index 1ba919ceae..b6f486f3d8 100644 --- a/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py +++ b/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py @@ -65,8 +65,9 @@ def get_battery_voltage(): This is an approximation only, but useful to detect if the charge state of the battery is getting low. """ adc = ADC(Pin(VBAT_SENSE)) # Assign the ADC pin to read + adc.atten(ADC.ATTN_2_5DB) # Needs 2.5DB attenuation for max voltage of 1.116V w/batt of 4.2V measuredvbat = adc.read() - measuredvbat /= 4095 # divide by 4095 as we are using the default ADC attenuation of 0dB + measuredvbat /= 3657 # Divide by 3657 as we are using 2.5dB attenuation, which is max input of 1.25V = 4095 counts measuredvbat *= 4.2 # Multiply by 4.2V, our max charge voltage for a 1S LiPo return round(measuredvbat, 2) diff --git a/ports/esp32/boards/UM_PROS3/modules/pros3.py b/ports/esp32/boards/UM_PROS3/modules/pros3.py index 7f95902936..4e5b2e9656 100644 --- a/ports/esp32/boards/UM_PROS3/modules/pros3.py +++ b/ports/esp32/boards/UM_PROS3/modules/pros3.py @@ -41,8 +41,9 @@ def get_battery_voltage(): This is an approximation only, but useful to detect if the charge state of the battery is getting low. """ adc = ADC(Pin(VBAT_SENSE)) # Assign the ADC pin to read + adc.atten(ADC.ATTN_2_5DB) # Needs 2.5DB attenuation for max voltage of 1.116V w/batt of 4.2V measuredvbat = adc.read() - measuredvbat /= 4095 # divide by 4095 as we are using the default ADC attenuation of 0dB + measuredvbat /= 3657 # Divide by 3657 as we are using 2.5dB attenuation, which is max input of 1.25V = 4095 counts measuredvbat *= 4.2 # Multiply by 4.2V, our max charge voltage for a 1S LiPo return round(measuredvbat, 2) diff --git a/ports/esp32/boards/UM_TINYS3/modules/tinys3.py b/ports/esp32/boards/UM_TINYS3/modules/tinys3.py index 06bbb5ff82..6aa1f185f6 100644 --- a/ports/esp32/boards/UM_TINYS3/modules/tinys3.py +++ b/ports/esp32/boards/UM_TINYS3/modules/tinys3.py @@ -41,8 +41,9 @@ def get_battery_voltage(): This is an approximation only, but useful to detect if the charge state of the battery is getting low. """ adc = ADC(Pin(VBAT_SENSE)) # Assign the ADC pin to read + adc.atten(ADC.ATTN_2_5DB) # Needs 2.5DB attenuation for max voltage of 1.116V w/batt of 4.2V measuredvbat = adc.read() - measuredvbat /= 4095 # divide by 4095 as we are using the default ADC attenuation of 0dB + measuredvbat /= 3657 # Divide by 3657 as we are using 2.5dB attenuation, which is max input of 1.25V = 4095 counts measuredvbat *= 4.2 # Multiply by 4.2V, our max charge voltage for a 1S LiPo return round(measuredvbat, 2) |