I have started using 18650 LiPo batteries for my projects. Many of these batteries are salvaged from laptop battery packs or other appliances. I needed a reliable way to find the capacity of these batteries to decide which ones to use and which ones to discard.

A battery capacity meter is basically a constant-current discharge circuit and a reliable timer. The timer measures how much time a fully charged battery takes to discharge to a specific voltage. Also, it should prevent deep discharge of the battery.
This is fairly simple logic, so initially I selected a PIC16F676 microcontroller. Basically, the code sets up an interrupt-driven timer. An interrupt-driven timer ensures timing accuracy. Then, I put a simple program to display the elapsed time and remaining capacity. It will also check when the battery voltage falls below the cutoff level. To improve accuracy, the battery voltage is taken as the average of ten readings. Once the cutoff voltage is reached, the program will display the battery capacity by multiplying elapsed time by drain current.
Unfortunately, the PIC16F676 has only 1KB flash memory; the compiled code came to 1.3 KB. Trying to reduce the code size with ChatGPT did not improve the situation much. So I had to move to a controller with more memory, which is the PIC16F690. As the Battery Capacity Meter will be used only occasionally, I did not plan any enclosure for it.
