Using  BOD 2.7V AVR ATTiny85 as Li-ion 18650 4.2V battery discharge protection? - Page 1
Forum section: electronics / projects

author: beduino
author_rank: Regular Contributor
timestamp: October 02, 2019, 12:20:10 am
content: Hello,I'd like to protect Li-ion 18650 4.2Vmax battery which powers directly ATTiny85 consuming a few mA of current probably since running at 8MHz, so idea is to enable 101 BOD 2.7V typical (attached 21.6 Brown-Out Detection from ATTinu85 datasheet),however it is for 3.3Vcc, but Li-ion will be charged by small photovoltaic solar panel up to 4.15Vmax (<4.20V),so probably this trick could do the job and in the case for some reason Li-ion didn't get charged for a long time and its voltage dropped below 2.7V (2.5V in worst case scenario according to BOD datascheet specs) should put AVR into reset state with its pins in high impedance tri-state, so battery discharge below typical 2.7V should be prevented by BOD in AVR MPU itself or I missed something?There shouldn't be problem of running 8Mhz ATTiny85 AVR at voltage range 2.7V - 4.15V (more realistic 3.6V-4.15V since it consumes small power relative to 18650 Li-ion capacity) ?Off, course I will test it right now, but looking for your opion or expierience while maybe someone tried to use AVR BOD to protect Li-ion battery from discharge below 2.7V.So, idea is run ATTiny85 @ 8Mhz with enabled 101 BOD 2.7V typical directly from Li-ion 18650 4.2Vmax at normal conditions up to 3V, but to ensure put it in reset when battery is discharged.Not sure if ATTiny85 can run 8MHz clock at 2.7Vcc, but it should be specified in its datasheetRegards.

author: beduino
author_rank: Regular Contributor
timestamp: October 02, 2019, 12:36:51 am
content: Update: According to ATTiny85 AVR datasheet @ 8MHz 2.7Vcc it needs something about 2.5mA, so it looks like it shoud run at 8MHz internal clock up to 2.7Vcc, so probably enabling 101 BOD 2.7V typical should do the trick and protect 18650 Li-ion?What do you think?Anyway, probably it is time to make experiment and test this, while datasheet looks goodRegards.

author: Kleinstein
author_rank: Super Contributor
timestamp: October 02, 2019, 07:26:26 am
content: The BOD is not very accurate. Still using the BOD function is definitely better than no protection. Even after brown out is detected, there will be a little current draw (maybe a µA and maybe more from the charger circuit).There is the question if the µC really has to run at 8 MHz - may tasks can use an even lower clock.The maximum voltage of a solar panel is not that well defined. It depends on the light intensity and also temperature. So the maximum voltage would need a more reliable limit. If in doubt set the upper limit lower - the capacity will be a little lower at the cost of longer life time.

author: Ian.M
author_rank: Super Contributor
timestamp: October 02, 2019, 08:54:23 am
content: Although BOD is nessercery to prevent incorrect AVR operation during Vcc brownouts, it isn't going to do a great job of LiPO protection. Its accuracy is +/- 0.2V, so the range is 2.7V-2.9V, and as LiPOs are at risk below about 2.65V/cell, and 2.5V is the threshold chosen for many non-resettable 'final disconnect' protection circuits.Therefore it isn't suitable for LiPO protection unless you select your ATtinys on test for above average BOD voltage.Unfortunately your chosen MCU can't do an ADC conversion on its internal 1.1V reference, so you cant use the technique of back-calculating the voltage on Vcc as the ADC reference voltage, from the 1.1V reference reading. If you could, you could monitor Vcc and go into a deep sleep or powerdown mode if Vcc is under 3.0V, only waking up on a pin change AND Vcc>3.0V.Therefore, if you want to avoid the need for an external protection circuit, you may wish to consider changing MCUs to one that can do an ADC conversion on its internal reference. N.B. calibration will be required - with a known Vcc, do an ADC conversion on the reference, and store it in the EEPROM to be used for calculating under and over-voltage thresholds.For overvoltage, have a resistor that can use up the full direct sunlight solar cell output, and switch it on with an I/O pin if Vcc >4.0V.

author: mikerj
author_rank: Super Contributor
timestamp: October 02, 2019, 11:01:03 am
content: How much current does the BOD take when enabled? That doesn't seem to be specified in the datasheet, and the power down currents are stated with BOD disabled implying it's large enough to impact those values.

author: Ian.M
author_rank: Super Contributor
timestamp: October 02, 2019, 11:14:51 am
content: Datasheet: Figure 22-46. Brownout Detector Current vs. VCCapprox 18uA @3V

author: beduino
author_rank: Regular Contributor
timestamp: October 02, 2019, 05:30:42 pm
content: Thanks everyone for "brain storm" ideas - this is what we are looking for on forumsQuote from: Kleinstein on October 02, 2019, 07:26:26 amYep, that is why I've designed LM317 based Li-ion (not Lipo) charger, since it has around 1.5A internal overcurrent protection and it is easy to set output voltage <4.2V with desent accuracy, so depending on solar panel power and MPU consumption with additonal ICUs (I2C) Li-ion 18650 battery will be charged while running MPU and battery voltage will be always limited to <4.20V (4.15V).Quote from: Ian.M on October 02, 2019, 08:54:23 amI was thinking to make measurement of Vcc as additional feture and probably RESET pin of ATTiny85 could be used to do so, when enabled as I/O ADC0 since it is already connected to MPU Vcc by 10k resistor.

author: beduino
author_rank: Regular Contributor
timestamp: October 02, 2019, 05:36:28 pm
content: Quote from: Ian.M on October 02, 2019, 08:54:23 amI use Li-ion NCR18650PF 2.5V-4.2V with recomended charge current 1.3A - maximum 2.7A, so LM317 internal protectionsn probbaly should do the job as well as I do not expect to use powerfull solar panels to do so, so this charging current will be limited itself by solar panel.I don't use LiPO battery.

author: Siwastaja
author_rank: Super Contributor
timestamp: October 02, 2019, 08:35:45 pm
content: No. LM317 overcurrent protection is NOT suitable for extended time "constant current" operation. It reduces device lifetime and increases the risk of it blowing up - as a short circuit. The current limit is very imprecise as well, and may be well over 3A, which will exceed your cell limits. For example, the TI datasheet does not specify the current limit at all, but a "typical" maximum output current of 2.2A. I wouldn't be surprised to find some regulator units, in specific conditions, could output 4A in current limit mode!Sure, if the solar panel itself limits the current, no problem. Just don't rely on that LM317 protection.Also there is no difference between "li-ion" and "lipo". Actually, there is no such a thing as "lipo" commercially available, except for marketing.You do have a classical fuse designed in?Overall, your describtion sounds alarming. It's very likely you'll end up with some kind of damage and/or fire, although if you use genuine Panasonic cells, all the cell safety features are there to help, and the damage would likely be limited to a slight venting of electrolyte. Still, use your gadget in a closed fire-proof metal box, under surveillance, so that the ejecting flames can't ignite stuff nearby.Remember the protection diode Vout->Vin. One of the first things I learned through trial and error: LM317 blows up randomly when used to charge batteries. And the failure mode is that it becomes a short, overcharging the batteries. Luckily, li-ion cells were not practically available back then and I only killed lead acid cells.You did have that diode in your plans, did you? If not, it's a telltale sign you should take a timeout and start doing this properly.Bare minimum is a reliable CC-CV regulator and a starting voltage validation (say, must be over 2.5V) before enabling the supply. You can do the validation on your MCU - add a way to measure the cell voltage. That way, you can also shut down at a more precise, and more suitable cutoff value - like 2.9V - and keep the BOD as the last line of defence against overdischarge in case of software crash.tldr: LM317 is not suitable for battery charging, especially not li-ion. Look for something else.

author: beduino
author_rank: Regular Contributor
timestamp: October 03, 2019, 09:47:11 pm
content: Quote from: Siwastaja on October 02, 2019, 08:35:45 pmI've made modifications to this current-limited charger circuit shown in TI LM317 datasheet as shown below,to limit charging current to around 100mA and let schottky diode BAT85 charge batery as close as possible to 4.11V on LM317 adjusted output voltage:Why LM317 is not suitable for battery charging?It will depend on application whether use dedicated Li-ion batery charger or use something as simple like above.This is not designed for aircraft PSU or mobile phone, etc.Charging current is limited to as low as 100mA while MPU power consumption will be below 10mA.One of the concerns is however that LM317 datasheet shows output current 10mA-1.5A, so maybe additional resistor (470 Ohm) needed to ensure load around 10mA for proper output voltage regulation?What do you think about such low current limited around 100mA Li-ion 4.11V charger?

author: Siwastaja
author_rank: Super Contributor
timestamp: October 05, 2019, 02:19:28 pm
content: The output diode makes the voltage regulation suck beyond laughable. Too much variation in Vf in function of temperature, current and unit variation. You can make it work safely using worst-case values but then you are trading off a lot of cell capacity.Yes, LM317 can be used in a charger circuit, but not alone / as is. Addition of CC is a good start.You still lack starting voltage and temperature qualification check. You can kind of ignore the temperature issue and manage that manually, but voltage check is very important and easy to forget to do manually.I'd either do this properly, or do it even more cheaply, i.e., use the existing microcontroller to connect the solar cell directly to the cell, using a single FET and cell & panel voltage sensing, and write perfect software that never crashes.

author: beduino
author_rank: Regular Contributor
timestamp: October 05, 2019, 10:25:11 pm
content: Quote from: Siwastaja on October 05, 2019, 02:19:28 pmI used BAT85 (200mA) schottky diode (thanks to ~100mA charge current limit) and voltage drop on fully charged capacitor 220uF during the tests was only ~0.11V, since on LM317 output I've 4.13V and after diode on charged capacitor 4.02V without any load.Not such a big deal whether battery will be charged to 4.13V or slightly below 4V under a few mA load.I used detailed design procedure shown in LM317 datasheet including IADJ current 50uA and it is nice that calculated theoretical output voltage 4.11V is very close to measured 4.13VQuote from: Siwastaja on October 05, 2019, 02:19:28 pmYep, you need calculator, too

author: Siwastaja
author_rank: Super Contributor
timestamp: October 06, 2019, 07:38:11 am
content: Quote from: beduino on October 05, 2019, 10:25:11 pmYes, and BAT85 (Nexperia datasheet) is defined to have up to 800mV drop at 100mA at room temperature. There is no minimum defined. At 10mV, the max at Tamb=25 is still 400mV. Quite a difference to your measured 0.11V. Taking temperature variation into account, basically it can be anything between around 0.1 and 1.0V, roughly. Hence, the regulation sucks.Measuring single-unit values on lab bench is design by luck. For li-ion voltage regulation, do not design by luck, using unregulated elements (such as diode drops). Close the loop against actual voltage reference, reading at the cell terminals.Of course this doesn't matter. It's likely good enough. Sometimes the cell may charge fully, sometimes to approx. 80%, sometimes slowly, sometimes more quickly. You have no control, and you won't know, but it's likely within acceptable limits for you.Quote from: beduino on October 05, 2019, 10:25:11 pmAnd a bunch of external components to deal with the current limiting, and the output diode.And you still have no pre-condition check. You have a nice fireball generator. An overdischarged cell is full of dissolved copper, ready to grow dendrites to short out the cell when full charging current is applied.An integrated lithium ion charging IC would do all this much easier. I'm all for thinking outside of box and trying dangerous things, but forcing an LM317 do it isn't very innovative, either.

author: beduino
author_rank: Regular Contributor
timestamp: October 06, 2019, 10:41:36 am
content: I've found those articles very usefull:https://batteryuniversity.com/learn/article/charging_lithium_ion_batteriesQuote from: Siwastaja on October 06, 2019, 07:38:11 amIt will never fully charge while maximum charge voltage is limited by LM317 to 4.11V and BAT85 diode limits additionally even under small load, but this is what I'm loking for - more charge cycles at very low charge current.https://batteryuniversity.com/index.php/learn/article/bu_808b_what_causes_li_ion_to_dieQuoteQuote from: Siwastaja on October 06, 2019, 07:38:11 amCharging current is limited to ~100mA, so as you noticed at this point voltage drop on BAT85 might be around 800mV, so at such load we can have around 3.3V on batery which is around 30% capacity, but at loads at the range of 4mA (eg. 8MHz ATTiny85 in active state on its internal oscilator) charge current is stil close to 16mA based on 0.11V voltage drop on 6.8 ohm current limiting resistor, so we will see during the a few day tests how close cell voltage could be to 4V achived with electrolite capacitor without any load.Quote from: Siwastaja on October 06, 2019, 07:38:11 amAnother story is charging in low temperatures and I'm not sure how many of those available li-ion charging IC deal with such conditions.http://batteryuniversity.com/learn/article/charging_at_high_and_low_temperaturesQuoteWhile, I do not need too high charging currents, maybe even this circuit could charge li-ion in temperatures below zero since 0.02C, where eg.: C: 2500mA is 50mA at –30°C, so I can limit this charging current to this level just by using 2 times bigger current limiting resistor and this is a beauty of such simple designs of course depending on application.This is not for life critical applications, but it might be used to keep running sensors in bike computer, where Li-ion 18650 cells can be hidden easily into a frame and only a few might be needed.It is acceptable to charge only 60% if it prolongs battery life.http://batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteriesQuote

author: Siwastaja
author_rank: Super Contributor
timestamp: October 06, 2019, 12:43:15 pm
content: Your issue is, you are assuming things and overlooking obvious advice, and trusting a well-known and widely debunked fake site (yes, their content quality has definitely gone up, but still, be careful.)For example, this graph which plots the voltage from 0 and starts the charging from 2.5V gives a false impression that this would be something that happens normally, while it isn't.The fact that your current is limited to "only" 100mA is meaningless. It's still in massive violation of the approved post-overdischarge conditioning cycle. The actual process varies, but it still requires voltage pre-checks, charging at around C/100 only, and adding timeouts and voltage checks mid-process.But just don't implement conditioning. It's optional and can only save a small subset of failed cells. Don't make the cells fail in the first place, and detect failed cells to prevent fire.Never just connect a 18650 cell to a 100mA, 4.1V CC-CV source. Check the voltage first. If < about 2.5V, discard the cell. If you want to implement the conditioning cycle, learn to do it properly. Yes, a 100mA current source is less likely to blow the cell up, than, say, 1000mA current source, but it can do it. All it needs to do is to plate the dissolved copper within the separator, and you have an internal short. This can happen at 100mA, given enough time.And yes, integrated li-ion charger ICs should have temperature qualification check. If not,they are crappy and dangerousyou just need to implement it yourself. The ones I have used do it.But for your own hobby project, it's not that dangerous to skip the temperature check. Especially at such low charge rates, and less than full charge voltage, which reduces the lithium plating risk at low temperatures. I'd say you are OK down to, say, -10 degC.

author: beduino
author_rank: Regular Contributor
timestamp: October 06, 2019, 09:15:55 pm
content: Quote from: Siwastaja on October 06, 2019, 12:43:15 pmLets take a look at "reference" Li-ion charger 4.2V based on TP4056 with TEMP1 connected to GND which means disabled cell temperature sensingHowever, on this PCB TP4056 Vin is 8Vmax, so we still might need somekind of DC-DC converter eg. with MPPT feature.Anyway, if this is 1A capable cell charger (not sure 22? TP4056 PROG2 resistor value), Li-ion NCR18650A datasheet says that below 10 degrees (above 0 degs I guess) to charge 0.25C instead of 0.5C, where C is around 3000mAh, so we need toTP4056 PROG2 resistor to value to be below 0.75A recomended charge current and still this thing will try to charge full at level 4.2V, which I do not like.We can replace PROG2 resistor to 10k to get 130mA charge current, but we can't set lets say 3.92V maximum charge voltage in TP4056.So, as we can see sometimes, when you buy li-ion charger like shown above, you do not know what is going on inside unless you take it apart and dig into its ICs datasheetsQuote from: Siwastaja on October 06, 2019, 12:43:15 pmWe can cut using grinder PCB above exactly in half vertically and we have DW01A typical application circuit which probably does what you'are talking about, hovever with 4.3V+/-50mV overcharge and 3V overdischarge and some histeresis for those, I guessConclusion is, maybe we could use this TP4056 PCB for charging to lower maximum Li-ion cell voltage around 3.9Vmax with charge current limited to 130mA by replacing PROG2 re4sistor to 10k accordingn to TP4056 datasheet and lower down charge voltage from 4.2V by adding not BAT85 which is my supprise has rather huge Vf drop at 100mA, but use instead eg. SS24 2A schottky diode where datasheets says around 0.3Vf at 0.1A at room temperature 25 degsProbably, it could be also good idea add 100uF capacitor before diode at TP4056 output, so it could charge capacitor instead of battery, but let oryginal DW01A circuit disconnect battery when overdischarged or overcharged?We have still temperature sensing disabled (shorted to GND) in TP4056 on this board, but we have overdischarge and overcharge protection.For the moment in my oryginal LM317 based circuit simply by changing BAT85 to something like mentioned SS24 with lower Vf @ 100mA, I think could do the job, but in the case to make charging & discharging more safe for battery (regardless of MPU BOD feature) maybe this micro usb TP4056 based Li-ion charging PCB could be usefull?What, do you think?

author: beduino
author_rank: Regular Contributor
timestamp: October 06, 2019, 09:30:26 pm
content: Update: R3 smd resistor is of course marked "122" which is 1.2 kΩ for 1A charge current on shown above TP4056 based micro usb Li-ion charger PCB,so by changing PROG2 pin to 10k we can have 130mA charge current

author: Siwastaja
author_rank: Super Contributor
timestamp: October 07, 2019, 06:25:27 am
content: Since you have an ATTiny85 in your system, you can also add voltage and temperature qualification with a trivial piece of software. Pseudocode:if(readInternalTempSensor() > -5 degC && readInternalTempSensor() < 50 degC && readCellVoltage() > 2.7V && readCellVoltage() < 4.15V)enablePinHigh();elseenablePinLow();

author: beduino
author_rank: Regular Contributor
timestamp: October 07, 2019, 11:38:35 pm
content: Yep, I have temperature sensing availablle in ATTINY85 MPU, but I do not like idea of using ADC and loose one of precious pins for this, so maybe it could be better add hardware protection with additional NTC temp sensor when needed in more critical application.Anyway, meantime I've added to my oryginal LM317 based circuit 33k resistor in parallel to existing 2.2k and... nice 3.94V output from regulator very close to calculated 3.93V in this caseWhen we do not take into account IADJ*R2 we are off around: 50uA*2.062k ~0.1V ,so I'm supprised how close to detailed design output voltage formula from LM317 datasheet real circuit is (without load)

author: xani
author_rank: Frequent Contributor
timestamp: October 09, 2019, 01:44:54 pm
content: Quote from: Siwastaja on October 06, 2019, 12:43:15 pmCare to elaborate ? Haven't seen any "debunking" of it here (or maybe I search forum wrong) and while their articles could definitely cite their sources better they are mostly useful info