I updated the assembler code for the PIC. Here's the latest flow chart:
The flowchart also shows how the F0-F2, CHRG_ and FAULT_ pins are driven to zero when the PIC is running off the battery voltage but change to inputs with weak pull-ups when running off the 5V UPS output rail.
Here's the flow chart for the subroutine to check the battery voltage:
FVR is the Fixed Voltage Reference (set to 4.096V). The FVR and the ADC are normally shutdown when not needed to reduce power. The normal duty cycle is one sample per second. The rolling average is 8 samples.
After a bit of real-time debugging I will post the latest code to the files section of this project. I will also keep this log updated with the latest info regarding the PIC code.