Fried the MCU on my DIY PCB, please help investigate what I did wrong - Page 1
Forum section: electronics / beginners

author: glebkooo
author_rank: Contributor
timestamp: June 14, 2023, 11:01:58 pm
content: Hi there!I've designed an UPS for WiFi router - it switches load between an external power supply and a 12V VRLA battery. Additionally, it controls the battery charging process by switching off the relay, thus cutting charger off when the voltage is greater than 14.2V. The charging controller is built using AVR MCU that measures a voltage on the battery via voltage divider.When I did test my prototype I fried the MCU - the magic smoke exited the chip, and now I am trying to figure out what I did wrong in my PCB / schematics design. I would really appreciate any help on this. Please see attachments at the end of the post.Now let me describe the schematics in more details:ATtiny45 here measures a voltage from voltage divider RV1. I've used 4.7V Zener diode here, it should protect the pin from overvoltageMCU controls the relay thru the RELAY_SW line using BSS138 MOSFET Q2The relay and MCU consume 5V, so I built DC-DC step down converter based on AOZ1280CI and power it from the external VRLA charger device that outputs 14.5V at maxThe part of circuit around the Q1 MOSFET switches the supply source either from the external power supply (15V) or from the battery (12V-13.9V)R_ON and R_OFF are inputs with internal pull up resistor enabled. These pins will be used by the external circuit in future to control the charging processFirmware code:https://gist.github.com/Glebka/533fcb96ea4d6e0ee03b3964759d5143Test conditionsI was continuously adjusting relay-on and relay-off thresholds in the code, flashing MCU via ISP connector, then making tests with lab supply connected to J6 instead of real battery, and 5V supply connected to the ISP connector's power lines. Then I was playing with output voltage on my lab supply to simulate different voltage levels of the battery and see how the MCU and relay behaves.When I made a "fatal" test, the RV1 was set to ~50% (equivalent of two 10k resistors in series), lab supply output was set to 14.2V - that should be enough for MCU to switch relay off.I connected and turned on devices in the following order:1. Lab supply (plays role of the battery) connected to the J6, providing 14.2V2. 5V power supply connected to ISP power linesJ2 (external power supply) and J4 (load) were not connected.As a result I observed about 500 mA current consumption on lab supply and a magic smoke from MCU.

author: DrGeoff
author_rank: Frequent Contributor
timestamp: June 14, 2023, 11:08:52 pm
content: VBAT through RV1 into PB4 via a zener clamp will fail. You need current limiting between vbat and the pot. If you wind the pot to the vbat end you have 12V across the zener which will fail short circuit.Also, RdsOn for the relay FET is about 6 ohms at Vgs=4.5V. Not a good device to use. Better to use a BJT instead, like MMBT4401.Was the 5V MCU power supply actually 5V?

author: glebkooo
author_rank: Contributor
timestamp: June 14, 2023, 11:34:33 pm
content: Quote from: DrGeoff on June 14, 2023, 11:08:52 pmQuoteYep, makes sense, thank you.QuoteHmm, will definitely double-check that, thanks.QuoteNo, when lab supply was turned on and 5V supply was connected to the ISP - the voltage on the MCU was 4.9VWhen I was supplying power to J5 (from VRLA charger), while battery, load and external supply were disconnected, there was 4.7V on MCU

author: ArdWar
author_rank: Frequent Contributor
timestamp: June 15, 2023, 08:05:55 pm
content: Did you try to implement an ideal diode or OR-ing circuit with Q1-D2-R5 there? I won't trust a schottky rectifier not to leak enough reverse current to eventually overpower the 100k pulldown and switch off the PMOS, leaving the body diode taking the brunt of VBAT current.You may want to reduce R1 to around 10K or lower. "EXT_PWR" usually don't care that much about additional 1mA quiescent current.Protip: set your PSU current limit to some small current for initial board testing. ~3mA or something for AVR/PIC, ~5mA for ARM, some more for larger ARM and so on. That way you'll knowwhencurrent consumption is way higher than expected, hopefully notafterit happen. You also don't need high current for VBAT simulation since everything are powered thru external 5V supply except U2 quiescent power and RV1 draw. You can limit it to about 2mA (I think)

author: glebkooo
author_rank: Contributor
timestamp: June 15, 2023, 09:11:10 pm
content: Quote from: ArdWar on June 15, 2023, 08:05:55 pmI was trying to implement power path management circuit inspired by this application notehttp://ww1.microchip.com/downloads/en/appnotes/01149c.pdfQuote from: ArdWar on June 15, 2023, 08:05:55 pmThank you for pointing that out, missed to consider that leakage.Quote from: ArdWar on June 15, 2023, 08:05:55 pmThanks, will double-check if my PSU can do that. Always thought it only capable of providing constant voltage or constant current.

author: glebkooo
author_rank: Contributor
timestamp: June 16, 2023, 09:46:07 pm
content: I've made changes to the schematic based on your suggestions, but I am not sure I made a proper calculations.Would really appreciate, if someone get a chance to validate that.On relay control circuit I added a D7, because I want MCU and DC-DC to work only when charger is connected. That is not the case, I guess, when relay is conducting and the power suddenly disappears from charger. Charger can supply 5A @ 14.4V, so I get into trouble picking a proper diode. Could someone please suggest with that? Is there should be a super-duper powerful diode, or it can be replaced with alternative circuit?Then, I followed @DrGeoff's suggestion and replaced FET with BJT, and did the R8 calculation, but not sure I did that correct.What I don't like here is a 10 mA base current flowing from MCU. Generally, it should not be a problem, because data sheet states that MCU can source 40 mA at max. Would it be okay, if I pick IRLML2402 FET as a replacement for BSS138 ?After that, I tried to calculate a proper R11 value (please see RV1-D1 circuit). The datasheet for LL34 zener confused me a bit, please seehttps://www.elektronik.ropla.eu/pdf/stock/lrc/zmm2v0-zmm56.pdfAs I understand, in order to zener do its work, it should be in proper conditions - I should supply enough current, so it can regulate the voltage. However, I didn't find that Izmin datasheet. I don't quite understand what are Irand Vrstands for... So I totally unsure that zener would operate correctly, for example if RV1 = 20kAnd, finally, I changed R5 value as @ArdWar suggestedWould much appreciate any comments and thoughts about that, thank you.

author: DrGeoff
author_rank: Frequent Contributor
timestamp: June 16, 2023, 11:52:23 pm
content: Quote from: glebkooo on June 16, 2023, 09:46:07 pmThe hfe of the BJT is between 40 and 500, so saturating it will only take a few mA for Ic=70mA. You can use a 2k2 base resistor with no problems.Quote from: glebkooo on June 16, 2023, 09:46:07 pmFor regulation the zener normally requires about 4mA of current, however this is being used for clamping. What range are you expecting to present to the pin? It should not be more than the pin's maximum input voltage anyway, without the clamping. There are other ways to clamp the pin using a series resistor and diodes to VCC and GND that usually work better.

author: glebkooo
author_rank: Contributor
timestamp: June 17, 2023, 12:53:05 pm
content: Quote from: DrGeoff on June 16, 2023, 11:52:23 pmThanks, will search the circuit you mentioned. I am trying to measure the battery voltage with ADC, the ADC reference is Vcc - lets say 4.9V. I want to have 4.7V on the pin when the battery voltage is 14.5V , so the range I expect is U <= 4.7V