# Use microcontroller to measure the microcontrollers voltage

When using an Analog to Digital Converter (ADC) I want to convert to millivolts (mV) afterwards. My microcontroller is running on 3.3V, but I want to measure more accurately to get better result.

$$mV = \frac{adcData}{2^{12}} * V_{cc} * \frac{1}{1000}$$

Vcc is ideally 3.3V, but I want to measure it.

Is there any way to do this, except measuring the voltage with a multimeter on the board directly?

• How accurate do you need it to be? – JYelton Feb 7 '14 at 23:29
• cAMELcASING mv as Mv is pRobably not a Good Idea... – Brian Drummond Feb 8 '14 at 10:43
• @JYelton: I don't have any requirement, just wanted to know any method making it more accurate. – iQt Feb 9 '14 at 14:43

Your equation is a bit confusing. I would write it as:

$$V_{unknown} = \frac{ADCreading}{2^{12}} V_{ref}$$

where Vref is your microcontroller's supply voltage.

In other words, you have to know one voltage in order to measure the other. You either know a priori what Vref is, and calculate Vunknown from that, or you can connect Vunknown to a calibrated standard and solve the equation for Vref:

$$V_{ref} = \frac{2^{12}}{ADCreading} V_{unknown}$$

• I agree my equation was as clear as yours. You are right of course and your answer on how to solve this is one possible solution, but Ignacio got a solution that is more preferred to my application. – iQt Feb 7 '14 at 23:55
• Ah, but if you're going to use the internal reference, then you don't need to know Vcc at all! But you can still use the internal reference to measure Vcc without any external divider using my technique. – Dave Tweed Feb 8 '14 at 0:01
• How can he measure a voltage higher than the ADC reference voltage without an external divider? – alexan_e Feb 8 '14 at 0:08
• By setting VCC as reference and measuring the reference voltage as ADC input. No external dividers or connection needed. Only by software and internal MCU ADC input selector. I personally did this on AVR and STM32. – x4mer Feb 8 '14 at 1:02
• @Phataas: The second equation above is the one you need. If you set V_ref to be V_cc and V_unknown to be the internal reference (whose voltage you know), you can solve for V_ref. – Dave Tweed Feb 8 '14 at 2:23

Use a lower fixed analog reference voltage (e.g. many AVR MCUs have an internal 1.1V reference), and put the supply voltage through a voltage divider in order to reduce it below the reference voltage. This will allow you to measure the reduced supply voltage and get a result that is proportional to it.

• I did not think of using the internal reference! This will do. I am using a ARM Cortex M3, but it has an internal reference as well. Thank you. – iQt Feb 7 '14 at 23:56