Design of battery capacity and protection circuit