There really is not magic.
Connect your voltage reference (I use an LM4120-4096) to AN3. Make certain that you connect the GND of the reference to the PIC GND pins.
Also, you will need to connect a .2uF capacitor from the reference output to GND. That is stated on the datasheet of the part.
If the voltage you want to measure is less than 4.096V, then just put a 2K resistor from the analog input pin to your battery.
Note that if your battery is connected, and the PIC does not have power, you will need to use a FET switch between the two, otherwise the battery will discharge through the un-powered PIC.
At any rate, I always use a 2K resistor in series with all PIC pins for protection.
Set up the chip's A/D according to the datasheet. It isn't any more complicated than that.
Bookmarks