Why not use the onboard AtoD convertors? 10-bit precision should be more than is needed.
Are you using a voltage regulator to power the PIC? If it is relatively precise (1% ish) then you should be fine to use that as your reference voltage. Just use a voltage divider to feed the AtoD input.
Otherwise you may need an external voltage reference. 3-pin voltage refs are cheap and plentiful. I'd guess you need around a 2.5V reference.
Set your voltage divider so it doesn't exceed 2.5V when the battery is fully charged. Then just do the math to determine A/D value at 3.0V.
Here's some code for 18F2525 so may need to change register names, etc. But the concept is the same. Note, I only use 8 bits to keep it simple. It's accurate enough for my app:
battery_monitor: '
TRISA.0 = 1 'make AN0 input
ADCON1 = 14 'AN0 = analog in
ADCON0.1 = 1 'start AD
wait_ad:
pause 1
IF ADCON0.1 = 1 then wait_ad
batt_v = ADRESH
ADCON1 = 15 'return pins to digital
TRISA.0 = 0 'output
IF batt_v < 150 then batt_warn
Bookmarks