How to protect my circuit when programming my microcontroller? - Page 1
Forum section: electronics / beginners

author: mangekyo
author_rank: Contributor
timestamp: November 05, 2022, 04:32:00 pm
content: Hi,I am making a custom "Arduino" that is connected to different sensors.I am using an ATmega 328p, the same processor in Arduino nano.This is the schematic I used as reference:https://www.arduino.cc/en/uploads/Main/Arduino_Nano-Rev3.2-SCH.pdfInstead of a micro usb connector, I am using an FTDI port that will connect to an FTDI to TTL adaptor.A battery connects to a voltage regulator that connects to the microcontrollers VCC port to power it. The voltage regulator also powers some +5V components and I have a different regulator for 3.3V components. In other words. +5V from the regulator goes to VCC.What I don't understand here is, if I remove the battery and connect my PC to the microcontroller for programming. The PC will provide +5V to the microcontrollers VCC port in order to program it.I made this schematic to just explain what I need help with:Now there will be +5V on VCC and the output of the LDO and 0V on the input of the LDO.Wont this make current flow out of the VCC port and into the output of the LDO?If I don't remove the battery, the LDO will provide +5V and the PC will provide +5V and I am not sure what will happen.What do I do here?

author: pqass
author_rank: Super Contributor
timestamp: November 05, 2022, 05:46:28 pm
content: See this thread:https://www.eevblog.com/forum/beginners/lm7805-backfeed-protection/Or maybe you can do what the Arduino UNO does; use a P-MOSFET to disconnect the USB+5V source from positive rail if the battery source is available (in your case, MOSFET after the 7805 output). See (top-center; uses 358 as a comparator to trip MOSFET):https://www.arduino.cc/en/uploads/Main/arduino-uno-schematic.pdf

author: ledtester
author_rank: Super Contributor
timestamp: November 05, 2022, 05:49:15 pm
content: Consider disconnecting the ICSP 5V pin from the MCU board. For instance you could just snip off the pin. During programming both your programmer the MCU board will have to be powered by their own power supplies. The ICSP header will only connect their grounds and the digital signals.As for the L7805, you might need a protection around it like is described on page 13 of this datasheet:https://www.ti.com/lit/ds/symlink/lm1117.pdfEven though it's for the L1117 the same caveat applies to all of the 78xx regulators.Here's why I think it may be a good idea... suppose the battery pack is removed and the circuit is only powered via USB. Your power-on LED will provide a path to GND and it is possible current can flow from Vcc, back through the regulator and through the LED.The Nano schematic doesn't include this diode around the regulator for probably these reasons:1. the output capacitor is only 1uF2. the regulator is protected if VIN is at least 5V3. the regulator is protected if VIN is floating (external power supply not connected)But in the unlikely case where the Nano is powered via USB and, say, a 3V supply is connected to VIN, the regulator may be damaged.

author: mangekyo
author_rank: Contributor
timestamp: November 05, 2022, 05:56:34 pm
content: Thanks for the replies.Arduiono nano can be connected to an external battery and still be connected to a PC for programming. Did I overlook something in this schematic? It's really driving me crazy.https://www.arduino.cc/en/uploads/Main/Arduino_Nano-Rev3.2-SCH.pdf

author: pqass
author_rank: Super Contributor
timestamp: November 05, 2022, 06:07:50 pm
content: Quote from: mangekyo on November 05, 2022, 05:56:34 pmSee "8.4.1 Protection Diodes" here:https://www.ti.com/lit/ds/symlink/lm1117.pdf?ts=1667617390255&ref_url=https%253A%252F%252Fwww.google.com%252FThe LM1117 has the out-to-input production diode.On second thought, the passage is only about brief (cap) surges, so, I don't think the Nano is adequately protected as is; use the out-to-input diode.Also, see my last message on how the UNO does it.

author: ledtester
author_rank: Super Contributor
timestamp: November 05, 2022, 06:12:36 pm
content: What do you mean "connected to a PC for programming"?If you mean programmed via USB through the on-board FT232RL, then the diode in the "+5V auto selector" takes care of deciding how +5V is powered.If you mean programmed via the ICSP port, like from a USBasp, then there is a jumper on the USBasp which controls whether or not it supplies power to the MCU board. See the schematic on this page:https://www.fischl.de/usbasp/

author: magic
author_rank: Super Contributor
timestamp: November 05, 2022, 06:36:08 pm
content: Quote from: mangekyo on November 05, 2022, 05:56:34 pmEverything here is powered from the 1117 regulator and there is a diode which enables things to work at ~4.3V from VUSB when the regulator is unpowered, but blocks the Arduino from attempting to power the PC.Without this diode, the 1117 would be connected in parallel with the internal 5V rail of the PC. Whichever regulator attempts to regulate a higher voltage (even by a few mV) this one would end up "winning" and powering both sides - not a good thing.Unlike LM7805, floating regulators like LM317 and LM1117 have large diodes from the output to the input. LM1117 datasheet states that the regulator can withstand a short pulse of several amps from capacitor discharge. I doubt that anything bad will happen with open circuit on 1117 input and a few volts on the output, and Arduino Nano doesn't seem to be bothered by this either.There will be problems if a depleted battery is connected to VIN and USB charges it through the "5V auto selector" diode and the regulator.LM1117 is quite a power hog consuming 5mA - possibly more than the rest of this board.

author: mangekyo
author_rank: Contributor
timestamp: November 05, 2022, 06:45:17 pm
content: Quote from: ledtester on November 05, 2022, 06:12:36 pmThe output of the 5V reg, +5V from the USB and VCC shares the same node. If you disconnect the battery, the +5V autoseletor will select +5V from the USB to power VCC. Wont this make current flow from VCC into the output of the 5V reg?

author: mangekyo
author_rank: Contributor
timestamp: November 05, 2022, 06:49:09 pm
content: Quote from: magic on November 05, 2022, 06:36:08 pmI think I get it now. Thank you so much! But according to the LM1117 data sheet. The side is optional, it doesn't look like the nano uses this optional diode. But since my circuit has a power on led LED on the input of the regulator, I need to add this diode, right?Quote from: ledtester on November 05, 2022, 05:49:15 pmWhat is providing the protection to the regulator when VIN is floating?

author: ledtester
author_rank: Super Contributor
timestamp: November 05, 2022, 10:04:09 pm
content: I could be wrong but I believe damage to the regulator occurs when current from the output pin exits through the input pin. But if there is no path to ground out of the input pin then no current will flow.That's why I mentioned the location of your power status LED. When the battery is not connected the LED will provide a path for current coming out of the input pin to ground.

author: mangekyo
author_rank: Contributor
timestamp: November 05, 2022, 10:19:49 pm
content: Ah, I see. But there is a path to ground from the output pin to the input pin through the capacitor