esp32/boards: Fix VBAT voltage calculation for UM S3 boards.

Signed-off-by: Seon Rozenblum <seon@unexpectedmaker.com>
This commit is contained in:
Seon Rozenblum 2023-09-27 20:38:35 +10:00 committed by Damien George
parent 276bfa3146
commit 77ae0a0948
3 changed files with 6 additions and 3 deletions

View File

@ -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. 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 = 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 = 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 measuredvbat *= 4.2 # Multiply by 4.2V, our max charge voltage for a 1S LiPo
return round(measuredvbat, 2) return round(measuredvbat, 2)

View File

@ -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. 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 = 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 = 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 measuredvbat *= 4.2 # Multiply by 4.2V, our max charge voltage for a 1S LiPo
return round(measuredvbat, 2) return round(measuredvbat, 2)

View File

@ -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. 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 = 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 = 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 measuredvbat *= 4.2 # Multiply by 4.2V, our max charge voltage for a 1S LiPo
return round(measuredvbat, 2) return round(measuredvbat, 2)