Universal Charger PIC16F877A

Universal Charger PIC16F877A

The device Charger PIC16F877A  is made on a PIC16F877A microcontroller and C++ programming language, SDCC compiler. Able to charge most  known batteries with custom charge parameters. The display shows all the necessary information (current, voltage, time, mode). During the charge, the temperature is controlled.

Principals and technical Specifications:

  • Rechargeable batteries: NiCd, NiMh, LiPo, Li-on, LiPoly, SLA
  • EEprom 256 kB for storing data on the charge / discharge process without using a UART PC; the ability to connect to a PC to display the charge / discharge process;
  • Maximum charge current: 0-5A
  • Maximum discharge current : 440mA (I = U / R -> I = 12/27 -> I = 0.444mA)
  • Function modes: 0: NiMh, 1: SLA, 2: NiCd, 3: LiPo, 4: Li-Ion
  • Maximum number of cans: 6
  • Maximum battery capacity : 3000 mA
  • Battery temperature rise, 10K thermistor
  • PWM frequency 16kHz
  • Temperature: The temperature value is calculated using a thermistor assembled in a voltage divider.
  • Voltage resolution,   5V / 1024 = 4.88mV
  • Battery voltage:  The voltage on the battery is calculated using a voltage divider 18k and 56k
    V = 18000 / (18000 + 56000) = 0.2432
    Voltage resolution per division 5V / 1024 = 4.88mV,  Coefficient N = 229.008 / 0.2432 = 20.07 mV per division.
  • Maximum of measured voltage 20.07 * 1024 = 20.5V
  • Current measurement: Current value is taken from a shunt of 0,1 ohm, further amplified by an operational amplifier.
  • In current measurement, resistance 3k3 and 19k play an important role Gain A = 1 + (19k / 3k3) = 6.76
  • Maximum measured current value I = 4.88 / 6.76 * Ishunt = 7.2257A
  • Current resolution, 7226mA / 1024 = 7.06mA per division.
  • NiMh NiCd charge

Schematic diagram:

Part-list for Charger PIC16F877A

Printed Circuit Board PCB Charger PIC16F877A

Charger PIC16F877A assembling

User Manual:

Charge/discharge analysis of NiCd and NiMh batteries
Charging is the process of restoring the original capacity of a discharged battery. In order to achieve a longer life, it must be loaded with the appropriate method.

Several methods are used to load rechargeable cells:
1. Fast current charging: 1CmA (fast charging temperature: 0 C to 40 C). In order to control and stop fast charging, it is recommended to charge at more than 0.5CmA but less than 1CmA. Charging batteries at more than 1CmA can cause safety ventilation to be triggered by increasing the internal pressure of the batteries, causing electrolyte leakage. When the temperature of the batteries is detected by a thermistor or other type of sensor, and its temperature is below 0 C or above 40 C at the beginning of the charge, a floating charge must be performed, instead of a fast charge. A fast charge must be stopped when any of the values ​​described below reaches the indicated level:

  • Upper voltage limit control : Approx. 1.8V/cell. This charging method is changed to floating if the battery voltage reaches approximately 1.8V / cell due to problems or malfunction.
  • Value of dV/dt (or peak delta cut) : 5 to 10mV/cell. When the battery voltage drops from its peak by 5 to 10mV / cell during fast charging, it must be stopped, and the charging method must be changed to floating.
  • Value of dT/dt (or cut by temperature) : 1 to 2 C/min. When an increase in battery temperature per unit of time is detected in the thermistor or other type of temperature sensor during rapid charging, and the temperature increase is detected by the sensor, the rapid charging must stop and the charging method Switch to floating.
  • Time limit : 90 minutes.

2. To charge excessively discharged batteries, first apply floating charge  and then proceed with fast charging once the battery voltage has risen.

Initial voltage for fast charging: Approx. 0.8V/cell with a current of 0.2 ~ 0.3 CmA.


  • Initial wait : 10 minutes. This prevents the dV/dt detection circuits from being activated for the specified time at the beginning of the fast charge. However, dT/dt detection may be active in this period. This is necessary for batteries that were left uncharged for a long time or were excessively discharged, etc. The initial wait is necessary to prevent the load from stopping (to prevent malfunctions) due to pseudos -dV/dt.
  • Floating or maintenance current : 0.033 to 0.05 CmA. When the current  is high, the temperature of the batteries increases, causing the battery characteristics to deteriorate.
  • Fast charging time : 60 minutes.
  • Total time : 10 to 20 hours. Overcharging a NiXX battery, even on floating or maintenance charges, causes deterioration in battery characteristics. To prevent overloading by floating load or any other method, a timer must be provided to regulate the total charging time.

Analysis of charge / discharge of SLA (Sealed Lead-Acid) Lead-Acid

batteries Unlike NiXX batteries, these types of batteries are charged at fixed voltages instead of fixed currents.

Charging method :

  1. Check if the battery. If it is OK, start charging at constant current at capacity/10.
  2. When the voltage reaches 2.55V / cell switch to constant voltage load at 2.45V/cell.
  3. If the current drops below capacity/20 then change to floating load.
  4. Charge in floating form at 2.25V/cell for an indefinite time (maximum recommended 20 hours).

Requirements :

An SLA battery should not be discharged at less than 1.5V/cell.
Maximum voltage for SLA batteries is 3V/cell.

Charge / discharge analysis of LiPO (polymer lithium) and LiIon (lithium ion) batteries

Charging method :
1. Constant current up to 1C until the voltage reaches 4.2V/cell.
2. Constant voltage at 4.2V/cell until the current drops to capacity/15.
3. Floating load at capacity/30 for 30 minutes.

Requirements :
A LiPO battery should not be discharged at less than 2.5V/cell.
Maximum voltage for LiPO (polymer lithium) batteries is 4.5V/cell.

Based on these recommendations, I designed the charger with the following characteristics:

Description Default value

Maximum charging current: 0 to 5A
Maximum discharge current: 440mA
Modes: 0: NiMh, 1: SLA, 2: NiCd, 3: LiPo, 4: LiIon
Cell capacity: 3000mAh
Number of cells: (1 to 19) 6

Load: (0.1 to 25.5) (10) -> 3000 * 1.0 = 3A
Discharge: (0.1 to 25.5) (40) -> 3000 * 4.0 = 12A

Peak delta wait: 10 minutes

Low voltage cut-off (per cell):
NiCd (0 to 2550) 800mV
NiMh (0 to 2550) 1000mV
LiPo (2500 to 3500) 3000mV
SLA (1500 to 2500) 2000mV

Delta peak ( 0 to 255):
NiCd 10mV
NiMh 5mV

Maximum voltage per cell:
NiCd 1680mV
NiMh 1680mV
LiPo (3500 to 4500) 4200mV
SLA (2000 to 3000) 2500mV (2.5V x 6 cells = 15V – maximum voltage for 12V SLA)

Final current (% of current) initial load, 0 to 255):
LiPo (5%) -> 3000 * 5/100 = 150mA
SLA (5%) -> 3000 * 5/100 = 150mA

NiCd and NiMh 65 min at 1C, 130 min for 0.5 C, etc.

Download files:

Reference: link


  1. اين ملف HEX لبرمجة البك ؟

Leave a Reply