王达业

ATtiny85 charge protector

 
Overview

Open source agreement

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. ( http://creativecommons.org/licenses/by-sa/3.0/ )

Introduction

ATtiny45/85 USB Phone Charge Guard controls and monitors charging of phones and other devices. Voltage, current, power and energy are continuously measured via the INA219 and compared with user limit values. When user-selected conditions are reached, it cuts off power through the MOSFET. This controls the charge state of your phone's lithium-ion battery, extending its lifespan. User settings are stored in EEPROM.


Author: Stefan Wagner

Original project link: https://oshwlab.com/wagiminator/attiny85-phone-charge-guard

Project video (YouTube): https://youtu.be/9DHBoqHImcM

Firmware (Github): https://github.com/wagiminator/ATtiny85-PhoneChargeGuard


Circuit description


USB

The device comes with a USB-A plug for input and a USB-A socket for output so that it can be plugged in between a power source and your phone (or other consumer). D+ and D- are passed so that the phone can negotiate the charging protocol.


Voltage and current measurements

An INA219 is used to measure voltage and current. The INA219 is a current shunt and power monitor with an I²C compatible interface. The device monitors shunt voltage drop and bus supply voltage with programmable transition times and filtering. Programmable calibration values ​​combined with internal multipliers enable direct reading of current in amperes. The 8 milliohm shunt resistor was chosen to have very little effect on the circuit while allowing measurements to be made with 1 milliamp resolution. For accurate measurements, choose a shunt resistor with low tolerance (1% or better)


voltage stabilization

The device supplies 3.3V via the HT7333 LDO regulator, which draws input voltages up to 12V from the USB bus power.


MOSFET

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


Operation interface

The user interface uses five buttons and a 128x64 pixel OLED display. An ATtiny45/85 microcontroller handles the user interface, the power connection of the measured values ​​and the control of the calculation and display.


image

image


Software description

illustrate


The INA219 continuously measures current and voltage and transmits the values ​​to the ATtiny via I²C. From this, ATtiny calculates other values ​​and displays them on the OLED screen. It controls the connection between the power supply and the phone through MOSFETs according to the settings selected by the user. User settings are saved in EEPROM and will be loaded automatically the next time you use it.


I²C OLED implementation

The I²C protocol implementation is based on a crude bitbanging approach. It is designed specifically for the limited resources of the ATtiny10 and ATtiny13, but it will also work with some other AVRs (including the ATtiny45/85). The OLED functionality is for the SSD1306 OLED module, but can be easily modified for use with other modules. To save resources, only the basic functionality required by this application has been implemented. For more information on how the I²C OLED implementation works, visit TinyOLEDdemo .


Accuracy of time and capacity determination

The ATtiny's internal oscillator is used to determine energy and capacity. When factory calibrated, the internal oscillator is accurate to +/-10%. This can be improved to +/-2% or better with manual calibration. Calibration values ​​determined in this way can be set in the source code.


Compile and upload

Since there is no ICSP header on the board, you must program the ATtiny before soldering using the SOP adapter or after soldering using the EEPROM programming clip. The AVR programming adapter can help in this regard.


If using Arduino IDE

  • Make sure you have ATtinyCore installed .
  • Go to Tools -> Board -> ATtinyCore and select ATtiny25/45/85 (No bootloader).
  • Go to Tools and select the following board options:
  • Chip : ATtiny45 or 85 (depending on your chip)
  • Clock : 8 MHz (internal)
  • Millis/Micros : Disabled
  • BODLevel : BOD enabled (2.7V)
  • Leave the rest at default settings
  • Connect your programmer to your PC and ATtiny.

  • Go to Tools->Programmer and select your ISP programmer (e.g. USBasp).

  • Go to Tools -> Burn Bootloader to burn the fuse.

  • Open the PhonChargeGuard sketch and click Upload .

    • -

If using precompiled hex files

  • Make sure you have avrdude installed.
  • Connect your programmer to your PC and ATtiny.
  • Open a terminal.
  • Navigate to the folder containing the hex file.
  • Execute the following command (if necessary, replace "usbasp" with the programmer you are using):
  • 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

If using makefile (Linux/Mac)

Make sure you have the avr-gcc toolchain and avrdude installed. Connect your programmer to your PC and ATtiny. If you are not using ATtiny85, open the makefile and change the chip, if you are not using usbasp, change the programmer. Open a terminal. Navigate to the folder containing the makefile and Arduino sketch. Run "make install" to compile, burn fuses and upload firmware.


Instructions

  1. Connect the device between the power source and the phone (or other consumer).
  2. Use the SELECT/INCREASE/DECREASE buttons to set charging limits.
  3. Use the START button to start the charging process.
  4. Use the SELECT button to switch between displayed values ​​during charging.
  5. When the set limit is reached, the charging process stops automatically.

image


Key Function:

button Function
RESET reset all values
SELECT Select restriction type in pause mode/change display parameters in charging mode
INCREASE increase limit value
DECREASE Lower limit value
START Start/pause charging

Selectable charging limits


Restriction type Function
mAh Stop charging when the battery reaches the selected value
mWh Stop charging when the supplied energy reaches the selected value
mA Stops charging when the current falls below a selected value (this is usually related to the battery's state of charge)
min Stop charging after selected time in minutes

characteristic

scope maximum value
Voltage 3V-12V
current 5AMAX
Voltage measurement rate 4mV
Current measurement rate 1mA

refer to


  1. ATtiny45/85 datasheet
  2. INA219 datasheet
  3. SSD1306 datasheet
  4. HT7333 datasheet
  5. AS3621 datasheet

image




参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-07-06 15:51:45

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号