HeltecV4: Fix battery ADC reading accuracy#2689
Conversation
Correct ADC_MULTIPLIER from 5.42 to 4.9 to match the R27/R28 resistor divider on the schematic (390kΩ + 100kΩ) / 100kΩ = 4.9. Also switch from analogRead() with manual 3.3V/1024 conversion to analogReadMilliVolts() at 12-bit resolution, which uses the ESP32's built-in ADC calibration for improved accuracy. Schematic reference: https://resource.heltec.cn/download/WiFi_LoRa_32_V4
|
Thanks for this PR, I also coincidental changed this in my local branch, so I can confirm it works and is more accurate then the current code 👍 One question: do we also need to change the Attenuation to a smaller range to have an even more accurate reading? Because I think the default is: ADC_ATTEN_DB_11 [0 mV ~ 3100 mV], but because of the voltage divider we will never measure above the 1000mv. e.g.: |
|
Hi @fizzyfuzzle Thanks for testing it. I'm actually still testing mine, was going to wait for full drain and see how it performs before I move it from draft. You raise a good point though. I think the default attenuator is 11dB but it could go as low as 0dB as the standard Lithium Polymer should only go from 615mV to 857mV at the ADC pin with that divider, so well within the 0dB range. Leaving it at the 11dB default would waste ADC counts and introduce more nonlinearity. I think 0dB gives the best linearity and resolution the ESP32-S3 ADC can offer, what do you think? |
The resistor divider (390kΩ/100kΩ) keeps the ADC pin voltage in the 0.61-0.86V range across the full LiPoly range (3.0–4.2V). ADC_2_5db (~1250mV full-scale) uses ~70% of the ADC range at full charge, giving better resolution than the default ADC_11db (~20%) while maintaining headroom over ADC_0db (~950mV) to handle chip-to-chip ADC variation.
|
Actually, you're suggestion if probably better @fizzyfuzzle , 0 dB might not give enough room on the top range for chip to chip variations, 2.5 dB would probably give better compatibility between users. Change is made, I moved it from draft for now but I am still going through a full drain. |
|
Mine reports 93%/ 4.12V when fully charged. I didn't take into account the charging IC cuts off charging to 4.2V. if anyone else has feedback on running this branch and can report their full charge and low charge that would be helpful. Or any other input but I will probably revise this PR. |
Correct
ADC_MULTIPLIERfrom5.42to4.9to match theR27/R28resistor divider on the schematic(390kΩ + 100kΩ) / 100kΩ = 4.9.Also switch from
analogRead()with manual3.3V/1024conversion toanalogReadMilliVolts()at 12-bit resolution, which uses the ESP32's built-in ADC calibration for improved accuracy.Schematic reference: https://resource.heltec.cn/download/WiFi_LoRa_32_V4