External power to circuit while programming

While I'm designing my next project, I came across a scenario for which I am not sure what would happen, or what I should do to avoid whatever problems I might come across. Basically it's a custom circuit with an Atmel with Arduino bootloader, running LED strings. I will have an external power supply providing 5V to the whole circuit. The question is, what happens when I want to reprogram it (as in, download a new sketch) via FTDI. Because that sketch will be coming from a computer connected via USB to the circuit, I would essentially be providing power both from the USB cable, as well as the external PSU, yes?

My question is, is it safe to do that, is it safe to keep the external supply on, feeding 5V to the circuit, while at the same time also having an FTDI cable connected to download a new sketch? Ideally, I don't want to have to shut off the external circuit each time, just plug, download, and go. So I'm thinking I need to add something to the circuit that prevents feedback somewhere.

I just don't know where, how, or what. Do I add a diode to the FTDI VCC line? Does it also need a fuse as well?

Using a FTDI with your circuit and re-program the chip is Yes and NO. Yes if the whoe circuit did not use more than the PC - USB voltage rail can provide ( they are protected by a fuse ) I talking about the current for the whole circuit. No if the whole circuit is more.

So my idea is :

  1. Remove the chip ( ATMega ) from your board , place into an UNO board. Reprogram. Remove and place into your circuit.

  2. Built you owm chip programer using a ZIF. See my tread --> http://arduino.cc/forum/index.php/topic,87747.0.html Same idea 1 but it simply include a USB-TTL adapter, reset circuit, crystal and a zif socket. Power came from the USB computer.

  3. Use a RS232 board. Like : http://www.schmartboard.com/index.asp?page=products_populated&id=84 It use the 5 V from your circuit. Connect GND, RX to pin 3 , TX to pin 2, CTS with a 0.1 uF cap in serie with the reset pin 1 of the ATMega328P chip.

That's not going to work. It's a custom design, in a enclosure with only wires for external power and an FTDI header sticking out. The thing will be running at all times. Incoming VIN (5V) is split internally, one leg going to drive the LED strips (which together will be pulling upwards of 10A), and the other leg going to the Atmel. When it needs to be reprogrammed, I would connect my FTDI cable to the header sticking out of the enclosure. The external supply is not being switched off for this.

So what happens when I connect the FTDI cable? 5V (or close to that) will be fed into the circuit from the FTDI cable. Will it matter? Essentially it's a second supply in the circuit, and the grounds will be common anyway. But, I need a way to protect it from the LED strips pulling current from it.

In my mind, I need to somehow isolate things. I just don't know how, nor where.

The other option I'm considering is putting an FTDI chip in the circuit, and a USB header so all I'd have to do is plug a USB cable in, and not an actual FTDI cable. Still, I need to figure out how to safely do this.

Yes, look at (track down) the schematic for the Nano or Duem., there's a schottky diode. It's only forward-biased if the Nano/Duem is off.
So, you'll want your device powered before connecting the USB to re-programme. I guess you have to assume the responsibility for getting it right so that some new lines of code don't result a catastrophe. Depending, you might have a test-bed where you could ascertain whether you got it right basically before committing to re-programming in place.

http://site.gravitech.us/Arduino/NANO30/ArduinoNano3_0schematic.pdf

Well yeah, that makes me wonder about any of the Arduino boards. I've never tried it, but what happens if someone has both a wallwart connected to the board providing power, as well as a USB cable programming the thing at the same time. That's the same thing I'm trying to do. So what happens in that scenario? Things go up in smoke? The computer's USB port goes poof? Why? Or why not?

The other option I'm considering is putting an FTDI chip in the circuit, and a USB header so all I'd have to do is plug a USB cable in, and not an actual FTDI cable. Still, I need to figure out how to safely do this.

It's really easy. In the FT232RL info sheet there's a sample circuit that describes how to do this, but basically you connect USB ground to common ground and a 10K resistor to the reset pin, and USB +5V to a 4.7K resistor to the reset pin.

I've built a couple of circuits now with this configuration and have had no problems. I've attached a piece of a schematic showing the layout.

[edit -- the section in the data sheet you want is "Self Powered Configuration" ]

Good luck!

I know how to do that Chris, that's not what my question is. Assume it's already in the circuit (or not, doesn't matter), the question is whether it's safe to have the circuit powered with a 5V power supply, driving everything, including the controller, while also having a USB cable plugged in to the controller to reprogram it. What safeguards should I be taking to do that, to avoid the USB getting blown, or anything else for that matter.

Nothing else needed. If you wire the USB connection like this then the Ft232rl chip takes care of the rest.

@KirAsh4

What about my Option 3. ( RS232 ) It need the 5 V from your circuit, and choose the RS232 port of you computer to send the new program. I did that experiment, and work just fine. Might work in your case.

or

Chris Magagna idea, except the 5 V line going to the computer ( USB ) is being disconnected, and connect the 5 V to your circuit.

:~ Crazy Idea...but it just might work...

Oh first, Techone, I didn't mean to completely discount your suggestions. They are all viable solutions, just not for this particular setup. And while the RS232 is possible, not in this particular setup. There's no room. There's barely 7mm of height clearance, and 1.2mm of that will be taken up by the board itself. And almost no computer comes with an RS232 port anymore. :slight_smile: Sure, I can buy a USB to RS232 cable ... but why, when I can design a complete USB solution ...

As for Chris' idea, the FTDI chip doesn't need to be constantly powered, only when the USB cable is connected to program the controller. So I don't think connecting it to the circuit's 5V is necessary.

Here's another question: with an FTDI chip in the circuit, is there a way to tell the micro controller when a USB cable has been plugged in? Before anything is even transmitted through. Plug the cable in, and the controller knows it's there ... is that possible?

Hey Chris, looking at your circuit, I noticed you left CTS unconnected. Shouldn't that be connected to ground? I only ask because I have an actual FTDI board from SparkFun and they have the CTS signal grounded. Datasheet simply says clear to send control input / handshake signal. So I'm not sure if it really matters. Thought I'd ask anyway.

To tell you the truth I'm not sure. I copied that side of the circuit from the Duemilanove, which has CTS going to a header block but isn't otherwise connected.

(http://arduino.cc/en/uploads/Main/arduino-duemilanove-schematic.pdf)

Just don't connect the USB 5v to the system, only use it to power the FTDI chip.

The only other thing to do is to stop the processor from powering up the FTDI through the TX pin, you could do that with a diode and a pullup resistor.


Rob

I just don't know where, how, or what.

Maybe I'm missing something here as I haven't closely read all of the comments. Why don't you just break the 5 volt connection at the FTDI connector in your circuit. It's the one going to pin 3, the red wire on your FTDI cable. I think this is essentially what Gary said in the previous post.

Don

So really I should be using the schematic for USB Bus Powered Configuration, where the FTDI chip is only powered by the USB bus when that gets plugged in. Once removed, that should also kill the FTDI (with the addition of Nomad's suggestion of isolating the TX line, so the uController doesn't end up feeding power back into it.

I don't need the FTDI to be powered for anything other than when the uController needs to be reprogrammed, so feeding it 5V from the rest of the circuit seems like a waste to me. So I'm thinking as long as there is a common ground along both "areas", with the FTDI only getting powered when a USB cable is plugged in, everything should work.

That actually sounds like a good idea. If you wouldn't mind, please let me know how it goes.

Thanks,

Chris

@KirAsh4

It look like you are using the FTDI breakout board ? Right ? I did experiments using that small board. The program a ATMega chip, you need 3 signal. The Rx, Tx and Dtr <-- for the auto-reset - hope I am right ?

And you guys got me thinking... What about using opto-coupler for those signals ? The 5 V and GND is from the computer. ( for the FTDI board ) and signals - tx, rx and dtr go to opto-coupler - 2 out, 1 in. And a few external parts <-- interfacing with the opto-coupler. For space saving, use SMT parts. In that way, you have a complete isolation. I did a fiber-optic link to send data to an Ardiuno. My link work, so this idea.

Just brainstorming here.

KirAsh4:
Because that sketch will be coming from a computer connected via USB to the circuit, I would essentially be providing power both from the USB cable, as well as the external PSU, yes?

My suggestion: a three-pin header on a 0.1" spacing with a two pin shunt to jumper two pins at a time. When the time comes to program the thing via FTDI, switch the shunt over to 'program' mode and hence disable access to the PSU power. When in standalone mode, move the shunt back. The center pin provides power to the board, the two outside pins are connected to USB and PSU 5V, respectively. Takes very little room, dirt simple, works every time.

While you might be able to get away with having the computer provide power while the PSU does also, think of all things that might happen if PSU power starts to creep into your computer. Not worth the risk, no matter how cheap the attached CPU.