Battery voltage monitor and AD conversion for XIAO_ESP32C

Thanks for the response msfujino and sorry for the late reply.

  1. The values of the resistors is not completely perfect, they are 215.4 kOhm and 218.1 kOhm. To account for the different values, I adjusted the multiplication with 2. Instead of 2, I used 2.01253481894, which corresponds to (215.4 + 218.1)/215.4. That seemed to make the error a bit better.
  2. I measured the battery voltage with 3 different measuring devices, which I tested before with constant voltage, and they are accurate.
  3. I haven’t tried putting a 100nF decoupling capacitor, but can try it later today.

I tried to ramp up the voltage and measure the difference. I used a lab power supply and got these values:

  • Input Voltage: 3.50 V < → Measured Voltage: 3.41263 V
  • Input Voltage: 3.60 V <-> Measured Voltage: 3.51939 V
  • Input Voltage: 3.70 V <-> Measured Voltage: 3.60384 V
  • Input Voltage: 3.80 V < → Measured Voltage: 3.70474 V
  • Input Voltage: 3.90 V <-> Measured Voltage: 3.80346 V
  • Input Voltage: 4.00 V <-> Measured Voltage: 3.90416 V
  • Input Voltage: 4.10 V <-> Measured Voltage: 4.00318 V
  • Input Voltage: 4.20 V <-> Measured Voltage: 4.10144 V

The input voltage corresponds to power supply voltage. The measured voltage uses your code for one value, then repeats that 100 times and extracts the average from that. The error fluctuates between 0.081 and 0.099, with the average of 0.093 and the delta difference between min and max error from 0.018.

If you have any more suggestions, how I could solve this, would be pretty nice, as adding an offset is not exactly the solution. But thank you in any case!