Skip to main content
emobility.academy
B.Tech / BECharging & energyIntermediate About 5 weeksKit + add-ons

CC–CV Charging Supervisor with Termination and Timeout

Build a charging supervisor that monitors the kit's single cell through constant-current and constant-voltage phases, ends the charge on current taper and stops it on a timeout or fault. The supervisor logs every charge with RTC timestamps and shows its state on the LCD.

Uses: ADC · GPIO · RTC

The problem

Lithium-ion cells are charged with a constant current until they reach their voltage limit, then held at that voltage while the current tapers. A charger that does not stop correctly, or runs on with a faulty cell, can overcharge and damage it. Vehicle BMS firmware supervises the charger independently: it checks phase transitions, ends the charge, and enforces timeouts and temperature limits.

Objectives

  • Measure cell voltage, charge current and cell temperature during a full charge
  • Detect the CC and CV phases and end the charge when current falls below a set termination level
  • Enforce safety timeouts, voltage and temperature limits through the charge/discharge relay
  • Log each charge with RTC timestamps and export it over UART for plotting

What you need

From the EV Embedded Development Kit

  • Second STM32F103C8T6 as the Smart BMS unit
  • 1S battery with connector and T-sense input
  • Battery charging unit with its own switch
  • Charge/discharge control relay
  • RTC with CR2032 backup cell
  • BMS power switch, OLED and six navigation buttons
  • 16×2 LCD
  • RGB LEDs and a buzzer
  • Serial UART interface

Software

  • STM32CubeIDE with HAL drivers
  • Embedded C
  • Python with pandas and matplotlib

Extra parts

  • INA219 I2C current and power monitor module, wired in the charge path — The kit does not list current measurement, and CV-phase termination depends on measuring the falling charge current.

This project uses the kit's lithium cell. Respect polarity, never short the terminals, and don't leave the cell charging unattended.

Key concepts

CC–CV charging
The charger first supplies a constant current while voltage rises, then holds the voltage at the cell's limit, typically 4.2 V for common Li-ion cells, while the current falls.
Termination current
In CV the charge is ended when current falls below a fraction of the CC current set by the cell datasheet. Holding the cell at full voltage beyond this adds stress for little extra charge.
Safety timeout
A maximum time for each phase and for the whole charge. If it is exceeded, the cell or charger may be faulty and charging must stop.
Shunt current monitor
The INA219 measures the small voltage across a shunt resistor and reports current and bus voltage over I2C.

Step-by-step guide

  1. 1

    Read the datasheets and set limits

    Identify the cell type from its label and find its datasheet: maximum charge voltage, recommended charge current, termination current and the temperature range for charging. Find the kit charging unit's set current from its documentation or by measurement. Write a limits table: CV voltage, termination current, per-phase timeouts, and minimum and maximum charging temperature. Read the cell-safety rules: check polarity before connecting, never short the terminals, and never leave a charge unattended.

    Checkpoint: A signed limits table with each value traced to the cell or charger documentation.

  2. 2

    Board setup and relay control

    Enable the DIP switches for the battery, charging unit, relay, RTC, LCD, LEDs and UART. In CubeMX set the BMS controller to 72 MHz, configure the ADC with DMA for cell voltage and T-sense, I2C for the INA219 and RTC, a UART at 115200 baud and the relay GPIO with charging disabled at reset. Use the kit schematic to confirm which relay position connects the charging unit to the cell.

    Checkpoint: Toggling the relay from the UART console visibly connects and disconnects the charger, with the cell voltage rising slightly when connected.

  3. 3

    Calibrate voltage and temperature

    Find the voltage divider ratio on the cell measurement from the schematic, then calibrate the ADC reading against a multimeter at two points to get gain and offset. Average 16 samples per reading. Convert the T-sense reading to temperature using the sensor's characteristic (for an NTC, the Beta equation or a lookup table). Compare against a thermometer at room temperature.

    Checkpoint: Displayed voltage matches the multimeter within 10 mV, and temperature matches a reference thermometer within the sensor's tolerance.

  4. 4

    Add and check current measurement

    Wire the INA219 in series with the charge path on the cell side, with polarity marked. Configure its calibration register for the shunt fitted and the expected current range, and read the current and bus-voltage registers. Verify the sign: charge current should read positive. Cross-check by switching on one resistive load with the charger off and comparing the reading with cell voltage divided by the measured load resistance.

    Checkpoint: Charge and discharge currents read with the correct signs and agree with the cross-check within a few per cent.

  5. 5

    Supervisor state machine

    Implement states: idle, pre-check, CC, CV, complete, fault. Pre-check verifies voltage and temperature are within range before closing the relay. Move from CC to CV when voltage reaches within a small margin of the CV limit and current starts to fall. In CV, end the charge when current stays below the termination level for a debounce time. Any fault opens the relay and latches until a button press acknowledges it.

    Checkpoint: A state diagram in the report matches the code, and each transition prints a time-stamped line over UART.

  6. 6

    Timeouts and protection

    Start a phase timer on entry to CC and CV and a total-charge timer at start, using the RTC for wall-clock time and a hardware timer for the fast loop. Stop the charge if any timer expires, if voltage exceeds the absolute limit, if temperature leaves the charging window or if current exceeds a ceiling. Test each limit by temporarily lowering it in a test build rather than stressing the cell.

    Checkpoint: Each protection, triggered with a lowered test threshold, opens the relay and shows the correct fault code.

  7. 7

    Display and alerts

    Show phase, voltage, current, temperature and elapsed time on the LCD, and the same summary on the BMS OLED. Use RGB colours: blue for CC, cyan for CV, green for complete, red for fault. Sound a short buzzer pattern on completion and a distinct pattern on fault. Keep display updates in the main loop at a low rate so they never delay the protection checks, and show the active fault code in plain words so a user knows why charging stopped.

    Checkpoint: The display updates at least twice a second without flicker and every state has a distinct colour and message.

  8. 8

    Logging and export

    Record one sample per second with RTC timestamp, voltage, current, temperature and state into a RAM ring buffer and stream it over UART. Write a Python script to plot voltage and current against time, mark the CC-to-CV transition and termination point, and integrate current to report charge delivered in mAh. Add the run number and the limit settings to the start of each log so that plots can always be traced back to the exact configuration that produced them.

    Checkpoint: A plot of a complete supervised charge clearly shows the CC phase, the CV taper and the termination point.

  9. 9

    Test and document

    Run at least three supervised charges from different starting voltages, staying present throughout. Compare termination current, total time and mAh delivered across runs. Document the design, the limits table, the protection tests and the plots, and note the effect of INA219 shunt resolution on termination accuracy. Let the cell rest between charges and record room temperature for each run. Explain any differences between runs, for example a longer CV phase when the starting voltage was higher.

    Checkpoint: The report includes three charge plots, a protection test table and a results summary.

Testing & validation

  • Three supervised full charges with plotted voltage, current and phase
  • Termination current at end of charge compared with the set level
  • Each protection (over-voltage, temperature window, timeouts, over-current) triggered with lowered test thresholds
  • Voltage and current readings checked against a multimeter

Expected results

A supervisor on the Smart BMS unit that tracks the CC and CV phases, ends the charge on current taper, enforces timeouts and limits through the relay, and produces time-stamped charge logs and plots.

Take it further

  • Send charge state and limits as CAN frames to a vehicle control unit
  • Estimate state of health from the length of the CV phase over many charges
  • Add a temperature-derated termination voltage
  • Store charge history in SPI flash for a service menu

Viva and review questions

Why measure current if the charger already does CC–CV?

The supervisor is an independent check: it confirms the phases, decides termination from the tapering current, and catches a charger or cell that behaves abnormally.

Why have a timeout at all?

A faulty cell may never reach the termination current, for example because of internal leakage; without a timeout the charger would hold it at full voltage indefinitely.

Why do you debounce the termination condition?

Current readings are noisy near the termination level; requiring the condition for a set time avoids stopping early on a single low sample.

Related EV projects

All 100 EV projects