Close

Coding for the PIC

A project log for U1LiUPSRPi

The Ultimate Single Cell Lithium UPS for any Raspberry Pi

Bud BennettBud Bennett 12/11/2018 at 02:110 Comments

I updated the assembler code for the PIC.  Here's the latest flow chart:

The watchdog timer is disabled. There isn't really anywhere for the program to hang (famous last words.) The only interrupt driven routine is the I2C interface -- and if it hangs then all is lost anyway.
The ACPR input is used to both wake up the PIC from sleep (ACPR going low to high) and changing the behavior when the AC power fails (ACPR low). Most of the other code differences revolve around the increased pin count and having to store the pin data in the I2C_STAT register to be transmitted over the I2C bus.

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.

BATCHECK:

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.

Discussions