cancel
Showing results for 
Search instead for 
Did you mean: 

Using VREFINT on STM32C071K8U6 for battery measurement with variable VDDA

Ricko
Senior III

Hi,

I need to measure a 4.2V battery while my MCU's supply varies between 2.0V and 3.3V. Since VDDA is the ADC reference, raw ADC counts will drift as the supply changes.

Is this the correct method?

My plan:

  1. Feed the battery voltage through a 10K/7K5 divider into one ADC channel (scaled to stay below VDDA_min = 2.0V).
  2. Read VREFINT on a second ADC channel.
  3. Use VREFINT (whose true value is known from the factory calibration in system memory) to back-calculate the actual VDDA, then convert the battery channel's raw count into volts.


The formula being:
V_battery = 3.0 V × (VREFINT_CAL / VREFINT_DATA) × (ADC_battery / 4095) × ((R1 + R2) / R2)

 

Is this the correct approach for getting a supply-independent battery reading on this part?


Anything I'm missing... sampling time for VREFINT, divider impedance vs. ADC sample-and-hold, or calibration register quirks specific to the C0 series?

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
EThom.3
Senior III

I haven't used this particular device, but I believe that your method is mostly correct. Reading VREFINT and using that to calculate the actual voltage of other ADC samples seems to be the way to go.

One very minor mistake I can see is that 4095 in your formula should be 4096, as a single ADC count is the reference voltage divided by 4096, not by 4095.

If you haven't already, you may want to read chapter 16.10, "Temperature sensor and internal reference voltage" in the manual, as this explains your exact situation.

Regarding sampling time, with your resistors, I wouldn't go below 350 ns.

View solution in original post

3 REPLIES 3
Ricko
Senior III

Hi,

I hope it’s okay to bump this. I’d be grateful if anyone could take a look or share any suggestions. :)

Thank you

EThom.3
Senior III

I haven't used this particular device, but I believe that your method is mostly correct. Reading VREFINT and using that to calculate the actual voltage of other ADC samples seems to be the way to go.

One very minor mistake I can see is that 4095 in your formula should be 4096, as a single ADC count is the reference voltage divided by 4096, not by 4095.

If you haven't already, you may want to read chapter 16.10, "Temperature sensor and internal reference voltage" in the manual, as this explains your exact situation.

Regarding sampling time, with your resistors, I wouldn't go below 350 ns.

Thank you @EThom.3