2
\$\begingroup\$

schematic

simulate this circuit – Schematic created using CircuitLab

I want to be able to turn on a single LED with either one of these two micro-controllers. Would there be anything wrong with this simple approach? The LED would experience double the current if both IC pins are grounded, but it wouldn't be enough to damage it; also the LED only blinks for a couple hundred milliseconds in any case, and never stays on constantly. Max sink current is also a non issue.

Please let me know if I am making a mistake or not.

edit for clarification: U2 pin is an open drain power good indicator that goes low automatically when usb power is supplied. U1 will turn on LED based on a couple of software events

\$\endgroup\$
6
  • 3
    \$\begingroup\$ Can you run the I/O pins in "open drain" mode? \$\endgroup\$ – jonk Jun 13 '20 at 0:16
  • 2
    \$\begingroup\$ i re-read your post and i think that it is unclear how you want the circuit to behave ... toggle means to change state ... do you actually mean turn on from either micocontroller? ... or do you want it to behave like a house light that can be controlled by two separate wall switches? \$\endgroup\$ – jsotola Jun 13 '20 at 0:44
  • \$\begingroup\$ Edited post; I just need to toggle the led when either 1) A USB power source is supplied to the board (handled by the open drain PG pin on U2 automatically), or 2) When a couple of software events happen on U1 \$\endgroup\$ – JPMorgan Jun 13 '20 at 1:01
  • \$\begingroup\$ I just need the LED to turn on* \$\endgroup\$ – JPMorgan Jun 13 '20 at 1:07
  • \$\begingroup\$ Fix your question: toggle does not equate to turn-on. \$\endgroup\$ – Andy aka Jun 13 '20 at 10:00
4
\$\begingroup\$

It's not a good idea!. Do this: Replace the two resistors with two diodes (1n4148 for example), with cathode towards the micros. Add a resistor in series with the LED.

\$\endgroup\$
6
  • 2
    \$\begingroup\$ Ok, or I may just tie the U2 output to a pin on U1 and recognize low in software. U2's pin is a power good pin. \$\endgroup\$ – JPMorgan Jun 13 '20 at 0:07
  • 1
    \$\begingroup\$ Yeah, u can also do that but it's a burden to your firmware. if I were u, I would use the diode method with no problem for anyone. \$\endgroup\$ – Hamid R. Tanhaei Jun 13 '20 at 0:14
  • 1
    \$\begingroup\$ Why do you say this isn't a good idea? \$\endgroup\$ – pericynthion Jun 13 '20 at 0:32
  • \$\begingroup\$ That's an extra part and probably an extra BOM line item, worth avoiding if possible. \$\endgroup\$ – pericynthion Jun 13 '20 at 0:38
  • 1
    \$\begingroup\$ when one pin zero and the other pin is one, what would be the result?! a 1.5v on the cathode of LED. so there's an uncertainty whether the LED is on or off or with a weak light, also an excessive current between two pins. when both pins are zero the LED will turn on with a more light. \$\endgroup\$ – Hamid R. Tanhaei Jun 13 '20 at 0:39
1
\$\begingroup\$

Provided both U1 and U2 are powered by the same supply (or supplies that turn on and turn off together), this would work fine. As you note, more current will flow and the LED will be brighter when both outputs are low, but that's not a problem (maybe it's even a desirable feature depending on what you're trying to indicate). Some current will also flow from one micro's output driver to the other when one is high and the other is low. That's not really a problem either unless you are very power-constrained, but you could avoid it by tri-stating the pins when you aren't trying to turn on the LED.

\$\endgroup\$
1
\$\begingroup\$

You say that two microcontrollers are trying to drive this LED. If that's the case, there is a high probability this can be solved in software. Most* microcontroller pins that are capable of digital outputs are some type of "GPIO", or General Purpose Input/Output, meaning they can function as either an input or an output. Furthermore, several microcontrollers have the capability of operating in an "open-drain" mode, which means there is a way to make it so that the output pin only sinks current.

Here's some pseudocode for how that would work, as well as a schematic:

// Microcontroller 1 (U1)    
U1.P1.Out = 0 // Drive 0V to the output pin of U1. Don't need to change this again
U1.P1.Out_EN = 0 // Disable U1 drive

// Microcontroller 2 (U2)
U2.P1.Out = 0 // Drive 0V to the output pin of U2. Don't need to change this again
U2.P1.Out_EN = 0 // Disable U2 drive

// Microcontroller 1 Turns on LED
// U1.P1.Out_EN = 1 // Enable U1 Drive
    
// Microcontroller 2 Turns on LED (still stays on, no drive contention)
// U2.P1.Out_EN = 1 // Enable U2 Drive

schematic

simulate this circuit – Schematic created using CircuitLab

Now, you can add diodes (right example) to make it a bit more foolproof. Both examples require a shared Ground/VSS, and the VDD should be the same.

\$\endgroup\$
3
  • \$\begingroup\$ Thank you, the code is no issue, I'm now just curious about the possible harm to either IC when both could go low. From a couple people, I'm hearing that the current wouldn't be a problem, from others I hear it's "unlikely" to cause problems, and others that say "no way, must throw in diodes." So I'm a little conflicted. \$\endgroup\$ – JPMorgan Jun 13 '20 at 2:18
  • \$\begingroup\$ The "Safest method" above is the best way to go. In your original post you have approx 7 mA when one driver is on, and that is the current if one or both is no now. That should be a safe number for most modern microcontrollers. There is no problem or conflict, and no additional LED current, if both drivers are low at the same time \$\endgroup\$ – AnalogKid Jun 13 '20 at 3:36
  • \$\begingroup\$ @JPMorgan When both outputs are driven low, there shouldn't be any risk of damage (assuming that each output could drive them individually). The real danger is from U1 driving the output low, and U2 driving the output high. In that case, you will have a short-circuit of the power supply. If U1 is open-drain, then D3 could be safely omitted. \$\endgroup\$ – W5VO Jun 13 '20 at 14:21
1
\$\begingroup\$

If you operate the pins in open-drain mode (either the pin has an explicit open-drain mode or you tristate the output - change it to an input) then connecting them the way you have cannot damage the drivers. So what you have is fine if you write the firmware correctly.

Worst case is that they "fight" and the LED goes on only dimly or not visibly at all (depending on color and efficiency) since it only sees 1.65V open circuit. The two resistors effectively "isolate" the outputs from each other so no damage occurs if a firmware error or some kind of hardware glitch causes them both to be driven in opposite direction with one actively driving high.

Most MCUs can be programmed to do that on their GPIO pins.

Diodes are not a good solution, particularly if you intend to drive a blue or white LED since 3.3V is barely enough voltage to start with.

You could also use a single gate/buffer chip: (of course in that case you would configure the GPIO pins as push-pull outputs)

schematic

simulate this circuit – Schematic created using CircuitLab

P.S. Note that sometimes bad things can happen if the two microcontrollers have independent power supplies and one can be off (even momentarily) when the other is on. If this is a possibility, it might be better to drive two discrete MOSFETs with one resistor.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.