The Microchip 24F series of microcontrollers has an internal 10-bit A/D. A block diagram of it is shown above. There are a couple of things to note about the diagram – first is that it allows for independent inputs for VREF+ and VREF-. This allows the user to set the dynamic range of the A/D to whatever is appropriate for the input signal. If a very precise and accurate reference is used, accurate absolute A/D measurements can be made. This is a very handy feature. If VREF- is tied to ground, the A/D results are given with the following equation:
So if the Input voltage was 1.250V and Vref was 2.048V, the resulting AD Counts result would be 625. That takes care of the standard ‘vanilla’ use case of the A/D.
Also note in the block diagram there is an internal band-gap reference that can be measured by the A/D: VBG. The information about the band-gap is shown in the table below. It has a +/- 5% accuracy. Unfortunately, this reference cannot be routed to the VREF inputs. An external reference must be used to automatically scale the A/D results.
In cost-sensitive designs, this could cause a problem. Because there is an accurate reference on-board, workaround would be nice.
I ran across this issue just recently. Here is a trick I came up with that allows for using the internal band-gap and alleviating the need for an external reference.
In battery powered designs, it is common for the micro to be powered directly from a battery, without an intervening regulator. In this case, it is common to need to measure the battery voltage to check how much battery life is left. However, if Vdd is used at the Vref, an accurate battery measurement cannot be made. However, if a known voltage is measured the reference voltage (Vdd) can be inferred. The equation below shows how this is done.
In this case, VBG = 1.2V, MaxADCounts = 1024. So, if the A/D Counts = 410, Vdd would be 2.997V. If A/D Counts = 450, Vdd would be 2.73V.
By measuring VBG periodically, Vdd can be determined. If the A/D is used with Vdd as VREF+, accurate absolute measurements can be made by doing ratiometric adjustments. The full equation for this given below.
And Vref is given by
Which gives the complete equation: