USB Phone Charge Guard

Microchip ATtiny10 Attiny13 ATtiny24 ATtiny25 ATtiny44 ATtiny45 ATtiny84 ATtiny85

The ATtiny45/85 USB Phone Charge Guard controls and monitors the charging of phones and other devices (Figure 1). Voltage, current, power and energy are constantly measured via the INA219 and compared with the user limit values. It cuts off the power supply via a MOSFET when a condition selected by the user is reached. This allows the state of charge of the phone's Li-ion battery to be controlled, thereby extending its service life. The user settings are saved in the EEPROM.

USB Phone Charge Guard controls and monitors the charging of phones and other devices.
Figure 1. USB Phone Charge Guard controls and monitors the charging of phones
and other devices.

Characteristics

  • Voltage:3 V - 12 V
  • Current max: 5 A
  • Voltage Measurement Resolution: 4 mV
  • Current Measurement Resolution: 1 mA

Hardware

The device is equipped with a USB-A plug for the input and a USB-A socket for the output, so that it can be plugged between the power supply and the phone (or other consumers). D+ and D- are passed through so that the phone can negotiate the charging protocol.

An INA219 is used to measure voltage and current (Figure 2). The INA219 is a current shunt and power monitor with an I2C-compatible interface. The device monitors both shunt voltage drop and bus supply voltage, with programmable conversion times and filtering. A programmable calibration value, combined with an internal multiplier, enables direct readouts of current in amperes. The selected shunt resistance of 8 milliohms enables both a very small influence on the circuit and a measurement with a resolution of 1 milliampere. For an accurate measurement, a shunt resistor with a low tolerance (1% or better) should be selected.

USB Phone Charge Guard schematic diagram
Figure 2. USB Phone Charge Guard schematic diagram

The device is supplied with 3.3 V via an HT7333 LDO voltage regulator, which taps the input voltage of up to 12 V from the USB bus power.

The connection between the power supply and the phone is switched on and off via an AS3621 P-channel MOSFET. Despite its small size, it can switch up to 30 V with 6 A continuously. Its internal on-resistance is only about 20 milliohms.

All project files available in download section, in project page on Github.com [1] and in EasyEDA [2].

The user interface utilizes five buttons and a 128×64 pixels OLED display (Figure 3). An ATtiny45/85 microcontroller handles the user interface, the control of the power connection and the calculation and display of the measured values.

USB Phone Charger Guard PCB, buttons and components placement.
USB Phone Charger Guard PCB, buttons and components placement.
Figure 3. USB Phone Charger Guard PCB, buttons and components placement.

The INA219 continuously measures current and voltage and transmits the values to the ATtiny via I2C. From this, the ATtiny calculates the other values and displays them on the OLED screen. It controls the connection between the power supply and the phone via the MOSFET depending on the settings chosen by the user. The user settings are saved in the EEPROM and automatically loaded the next time it is used.

I2C OLED Implementation

The I²C protocol implementation is based on a crude bitbanging method. It was specifically designed for the limited resources of ATtiny10 and Attiny13, but it works with some other AVRs (including the ATtiny45/85) as well. The functions for the OLED are adapted to the SSD1306 OLED module, but they can easily be modified to be used for other modules. In order to save resources, only the basic functionalities which are needed for this application are implemented. For a detailed information on the working principle of the I²C OLED implementation visit TinyOLEDdemo.

Accuracy of Time and Capacity Determination

The internal oscillator of the ATtiny is used to determine energy and capacity. The accuracy of the internal oscillator is ±10% with the factory calibration. This can be improved to ±2% or better by manual calibration. The calibration value determined in this way can be set in the source code.

Compiling and Uploading

Since there is no ICSP header on the board, you have to program the ATtiny either before soldering using an SOP adapter, or after soldering using an EEPROM clip. The AVR Programmer Adapter can help with this.

If using the Arduino IDE:

  • Make sure you have installed ATtinyCore [4].
  • Go to Tools -> Board -> ATtinyCore and select Attiny25/45/85 (No bootloader).
  • Go to Tools and choose the following board options:
    • Chip: ATtiny45 or 85 (depending on your chip)
    • Clock: 8 MHz (internal)
    • Millis/Micros: disabled
    • B.O.D.Level: B.O.D. enabled (2.7V)
    • Leave the rest at the default settings
  • Connect your programmer to your PC and to the ATtiny.
  • Go to Tools -> Programmer and select your ISP programmer (e.g. USBasp).
  • Go to Tools -> Burn Bootloader to burn the fuses.
  • Open the PhonChargeGuard sketch and click Upload.

If using the precompiled hex-file

  • Make sure you have installed avrdude [5].
  • Connect your programmer to your PC and to the ATtiny.
  • Open a terminal.
  • Navigate to the folder with the hex-file.
  • Execute the following command (if necessary replace "usbasp" with the programmer you use):

avrdude -c usbasp -p t85 -U lfuse:w:0xe2:m -U hfuse:w:0xd5:m -U efuse:w:0xff:m -U flash:w:phonechargeguard.hex

Operating Instructions

Connect the device between a power supply and the phone (or other consumer).

  • Use the SELECT/INCREASE/DECREASE buttons to set the charging limit.
  • Use the START button to start the charging process (Figure 4).
  • Use the SELECT button during charging to switch between the displayed values.
  • The charging process stops automatically when the set limit value is reached.
USB Phone Charge Guard charging control process.
Figure 4. USB Phone Charge Guard charging control process.

Button Functions

  • RESET: Reset all values
  • SELECT: Select limit type in pause mode / change displayed parameter in charging mode
  • INCREASE: Increase limit value
  • DECREASE: Decrease limit value
  • START: Start/pause charging

Limit Type Function

  • mAh – Stop charging when electric charge reaches the selected value
  • mWh – Stop charging when provided energy reaches the selected value
  • mA – Stop charging when current falls below the selected value (this usually correlates with the state of charge of the battery)
  • min – Stop charging after the selected time in minutes

References

  1. Project page on Github.com
  2. Design files in EasyEDA
  3. TinyCalibrator – OSC Calibrator and High-Voltage Fuse Resetter
  4. ATtinyCore Arduino Hardware Package
  5. AVRDude command-line program

Downloads

  1. Schematic, PCB project, scketch, source files and.hex file

Materials on the topic

  1. Datasheet Microchip ATtiny10
  2. Datasheet Microchip Attiny13
  3. Datasheet Microchip ATtiny24/44/84
  4. Datasheet Microchip Attiny25/45/85
  5. Datasheet Texas Instruments INA219
  6. Datasheet HT7333
  7. Datasheet AOS AO3400
  8. Datasheet Diodes MMBT3904

github.com

You may have to register before you can post comments and get full access to forum.
EMS supplier