as3525v2-usb: define number of enpoints correctly, write interrupt handler
[kugel-rb.git] / docs / CHARGING_ALGORITHM
blob4a89cac1498952fda6fce38af0a53a29999a04ee
1 CHARGING ALGORITHM
3 This doc and a part of the charger implementation (especially voltage curves, 
4 remaining time estimation, trickle charge) is written by Uwe Freese. If you
5 miss some information here, write to mail@uwe-freese.de.
9 [INTRODUCTION]
11 This doc describes how the charging works for the recorder. The algorithm
12 can be found in firmware/powermgmt.[c|h]. Debug output is done in
13 apps/debug_menu.c.
15 Charging for the player and the FM/V2 recorder is done by the hardware and
16 therefore isn't implemented in rockbox. Only the functions that
17 calculate the battery level are also used for these models.
19 All following information is related to the recorder.
22 [TECHNICAL POSSIBILITIES AJB]
24 - The AJB can read the voltage of the battery (all four cells in series,
25   resulting in about 5V).
26 - We can switch the charging current (about 350mA, constant) on and off.
29 [VOLTAGE CURVES]
31 See http://www.uwe-freese.de/hardware-projekte/rockbox/ladeverfahren.html
32 for some voltage curves taken while charging and decharging an AJB.
34 These voltage curves are implemented as arrays in rockbox. We can then 
35 calculate how full the batteries are (in percent) after taking the actual 
36 voltage. Both voltage curves (charging and decharging) are used here.
39 [CHARGE OVERVIEW]
41 - If voltage drops under a certain value (with "deep discharge" option on the 
42   value is a lot lower), charging is started.
43 - If end of charge is detected, go to top off charge.
44 - Make the batteries completely full. 90 minutes of top off charge (voltage
45   regulation at a higher value).
46 - After that, trickle charge (voltage regulation at a nominal battery value).
47   The trickle charge will continue as long as the charger is plugged in (this
48   is a change from the original charge algorithm).
51 [NORMAL CHARGE]
53 When charging is started, the charger is turned on. The batteries are charged
54 with a constant current of about 350mA. The charging is stopped for three
55 reasons:
57 - the voltage goes down in a 5 min interval (delta peak, see below)
58 - the voltage goes up only a little bit in an 30 min interval (is mainly
59   constant)
60 - the charging duration exceeds a maximum duration
63 [DYNAMIC MAX DURATION CALCULATION]
65 The max duration is calculated dynamically. The time depends on how full the
66 battery is when charging is started. For a nearly full battery, the max
67 duration is low, for an empty one, it is a high value. The exact formula can
68 be found in the source code. The battery capacity is also considered here.
71 [LIION BATTERY IN FM RECORDER]
73 (todo)
74 http://www.seattlerobotics.org/encoder/200210/LiIon2.pdf
77 [DELTA PEAK - WHY DOES IT WORK?]
79 Delta peak means to detect that the battery voltage goes down when the
80 batteries are full.
82 Two facts on batteries are the reason why this works:
84 - If the batteries are full, the charging current cannot charge the battery
85   anymore.
86   So the energy is absorbed by heating up the battery.
87 - Each battery has a negative temperature coefficient, that means the voltage
88   goes down when the temperature goes up.
90 NiMH batteries have a smaller delta peak than NiCd, but is is enough for
91 Rockbox to detect that the batteries are full (in theory :-).
93 Related documents on the web:
95   http://www.nimhbattery.com/nimhbattery-faq.htm questions 3 & 4
96   http://www.powerpacks-uk.com/Charging%20NiMh%20Batteries.htm
97   http://www.angelfire.com/electronic/hayles/charge1.html (soft start idea)
98   http://www.powerstream.com/NiMH.htm (discouraging)
99   http://www.panasonic.com/industrial/battery/oem/images/pdf/nimhchar.pdf
100   http://www.duracell.com/oem/Pdf/others/nimh_5.pdf (discharging)
101   http://www.duracell.com/oem/Pdf/others/nimh_6.pdf (charging)
102   Philips TEA1102/1103/1104 PDFs available at www.philips.com.
105 [TOP OFF CHARGE AND TRICKLE CHARGE]
107 After a normal charge is completed, trickle charging is started. That means 
108 charging to keep the batteries full. While trickle charge in other (stand
109 alone) chargers means charging the amount that the battery loses because of
110 self decharging, here it's charging the amount the AJB consumes when it's on.
111 That's because it is not possible to switch off the AJB when charging is done.
112 It goes on again and then the archos firmware charger code would charge again.
113 So we have trickle charge in rockbox.
115 In simple words, rockbox charges about 15 seconds per minute in trickle mode.
116 An AJB consumes 100 mA when it's on and the charging current is about 350mA.
117 So charging 15 s and decharge 45 s will keep the batteries full.
119 But the number of seconds the charger is on in trickle charge mode is
120 also adjusted dynamically. Rockbox tries to hold the battery level at
121 5,65 V (top off charge, that means "make the batteries completely full")
122 for 90 minutes, then a level of 5,45 V. If the voltage drops below the
123 desired value, rockbox will charge one second more the next minute. If
124 is is greater than this value, is will charge one second less.
126 The number of seconds the charger is on in top off and trickle charge
127 modes is also dependant on the charger's output voltage: if the charger
128 supplies less than about 10v, the current into the batteries is less and
129 thus the percentage on is increased to maintain the proper current into
130 the batteries.
132 The original recharging algorithm stopped trickle charging after 12 hours,
133 at which time the battery would be discharged until the the batteries
134 fell below the "start charging" level.  At that time the charge cycle
135 would be repeated.
137 The time limit was removed by Jerry Van Baren (along with other changes)
138 in the February, 2005 timeframe.  The rationale for this is that the
139 trickle charge level is very low.  In addition, it is disconcerting to
140 have a AJR plugged in and "recharged" only to find out that the battery
141 is only 86% full.  This was giving the Rockbox recharging algorithm a
142 bad name and frustrating our users.
144 Many chargers do top off and trickle charge by feeding a constant (low)
145 current to the batteries. Rockbox, as described, makes a voltage regulation.
146 That's because the power consumption of the AJB changes when backlight is
147 on/disk is spinning etc. and doing a voltage regulation is the simplest way
148 to charge exactly the needed amount.
150 There are two charge ICs I want to mention here: The Philips TEA1102 and
151 TEA1103 do voltage regulation for NiCd and NiMH at 1,325 V per cell. That
152 would be 5,3 V for four cells, but I think 5,45 V is best for Rockbox with the
153 maximum time of 12 hours.
154 Note that the voltage values are taken in the part of a minute where 
155 the charger is off, so the values are a little bit smaller than the actual 
156 average of the whole 60 seconds.
157 The Philips TEA1102 top-off charge time (with 0,15 C) is one hour.
159 My test results with trickle charge (battery capacities measured with an 
160 external charger):
162 - after normal charge and top off time: 1798, 1834, 1819, 1815 mAh
163 - after normal + top off + trickle charge (12h): 1784, 1748, 1738, 1752 mAh
164 - charged with external charger: 1786, 1819, 1802, 1802 mAh
166 Result: Trickle charge works. :)
169 [REMAINING TIME ESTIMATION]
171 In simple words, it is
173 remaining time = remaining battery energy / power consumption of AJB
175 With using the battery curves described above and the battery capacity you 
176 selected in the settings menu, the remaining capacity is calculated. For the 
177 power consumption, a usual constant value is used. If the LED backlight is set 
178 to always on, it is also considered. Having a modified Jukebox with 8 MB of
179 RAM leads to about 22 percent longer estimated running time.
182 [BATTERY DISPLAY HOW THE USER EXPECTS IT]
184 To not confuse the user with the shown battery level, some tricks are used in 
185 the battery level calculation (this does not affect the charging algorithm, 
186 because it uses the raw voltages):
188 - if charging is completed, top-off charge or trickle charge is running,
189   always set the battery level to 100%
190 - the battery level is only allowed to change 1% per minute (exception: when
191   usb is connected, it is allowed to go 3% down/min)
192 - after turning on the device, add another 5% to the battery level, because
193   the drive is used heavily when booting and the voltage usually gets a
194   little higher after that (rebounds)
197 [WHICH CHARGING MODE TO USE]
199 Jerry Van Baren's revised recommendation: Select "deep discharge OFF"
200 and "trickle charge ON".  This will keep your batteries charged up and
201 IMHO will not damage them.
203 Original recommendation:
205 A special case: If you use your AJR connected to the power supply all
206 the time or if you fill up the batteries that are still nearly full every
207 night, it is recommended that you make a complete charge cycle from time to 
208 time. Select "deep discharge ON" and "trickle charge OFF" and wait till the
209 whole cycle is over (you can speed up the discharging a little bit by turning
210 on the LED backlight). Even if the battery sellers say NiMH cells don't show a
211 memory effect, I recommend making this procedure from time to time (every 10th
212 charging cycle). BUT: Don't recharge the batteries completely every time if
213 you don't have to.