AtMega simple Battery Charger

The idea to use a rechargeable battery for power interruption:

  1. Battery is charged from PWM Pin of AtMega
  2. U1 and U2 is coming to analog inputs of AtMega, so AtMega knows voltage on R1
  3. Current is measured by dropping voltage on R1 as I=(U2-U1)/R
  4. Changing PWM out we can change charging current.

AtMega_BatteryCharger.png

You don't need to measure U1, its alternating 0 and 5V.

michael_x:
You don’t need to measure U1, its alternating 0 and 5V.

The reason for U1 to know the current that is coming through the battery, probably this schema would be better: compositor will change the impulse to constant voltage.

AtMega_BatteryCharger_02.png

Have you calculated how long does it take to charge a battery with 20 mA current? Regarding first drawings, it's right to measure voltage at the output, under load it would drops to 4.2 V or less.

Magician: Have you calculated how long does it take to charge a battery with 20 mA current? Regarding first drawings, it's right to measure voltage at the output, under load it would drops to 4.2 V or less.

probably longer then noted here: http://batteryuniversity.com/learn/article/charging_lithium_ion_batteries

Thats right, about 50 times longer, 50 x 4 hours = 200 hours. You need a transistor, to supply current up to 500 mA from arduino, in this case time would be acceptable 7 hours

no needs for fast charging, Arduino is working 24/7 for my project. power interruption occurred very unlikely, would say once a month/once a week for a relatively short time. To make sure data will not be lost this battery will help. For example timer application.

Than you don't need a PWM pin, simple digital will do charging, and you don't need a current measurements - it'd not be any good or accurate for calculation battery capacitance. Connect digital pin to resistor to battery, and one analog in between battery and resistor. When voltage reach a certain threshold (4.2V or so) you can change pinMode of digital to input and stop charging.

thank you for the help, looks like only one analog pin can be used to charge and read the value every 5-10 minutes: http://arduino.cc/en/Tutorial/AnalogInputPins The analog pins can be used identically to the digital pins, using the aliases A0 (for analog input 0), A1, etc. For example, the code would look like this to set analog pin 0 to an output, and to set it HIGH: pinMode(A0, OUTPUT); digitalWrite(A0, HIGH);

You can do the same thing with an analog I/O pin. Set it high to charge to charge the battery with a resistor to limit the current to the port safe limit and flip the pin to analog, read the battery and then compare, done... just monitor the battery and set both low the low threshold for start of charge and the high for charge termination, you should set a time delay in measuring the battery after charge stops to allow the battery to 'settle' or come to it's normal voltage or without the 'surface' charge, this to prevent early charge termination.

Bob