# Low resistance current limiting on GPIO pin

I'm trying to find a good solution for protecting the GPIO pin of an ATmega32u4 in short circuit conditions. Normally I would just use a simple resistor but that isn't the best option for this use case.

What the circuit should do is generate a Wiegand signal for which one data line looks like this:

That is: the signal line is normally at 5V, but when sending a data bit the signal is pulled to ground for somewhere between 30-200μs after which the signal should be high again for at least 1ms. So not really a high speed signal.

The electronic circuit I currently have looks like this:

The ATmega chip produces either 5 or 0 volts at the output of a GPIO pin, which is now current limited by R1. Then it goes into the harsh outside world with a cable of up to 100 meters in length. After which it enters an unknown circuit which should read the wiegand signal. Since wiegand isn't defined very well I'm seeing all kinds of different reading circuits. The most difficult one I encountered was a chip with a pullup resistor R3 = 495 ohm, R2 > 500 kohm and Vpullup = 3.23V. Since I'm using R1 = 270 ohm, this resulted in these values when trying to send the signal:

Signal High: 5 - (5-3.23)*270/(270+495) = 4.37V

Signal Low: 3.23*270/(270+495) = 1.14V

Of which the signal low was too high to trigger a low on the input side.

To get the best signal it would be great if I could remove R1, effectively setting R1 = 0 ohm in this circuit (+ the GPIO output resistance). However this would lead to a too large current draw from the GPIO pin under short circuit conditions, which are likely to happen due to wiring with screw plugs.

From the ATmega datasheet, the absolute maximum sink/source current on a GPIO pin is 40mA, let's say 35mA to be on the safe side. Furthermore from the "I/O pin Output Voltage vs Source Current at 5V" graph from the datasheet we can find that the GPIO output resistance is about 40 ohm. So I'm considering these options to limit the current:

1. Keep using a simple resistor with the lowest possible value. I.e. 5V / 0.035A - 40 ohm = 103 ohm -> 110 ohm. This will get the low signal in the example circuit to 3.23*150/(150+495) = 0.75V. Still a bit too high for my liking.
2. Use the smallest PPTC resettable fuse I can find: the Littelfuse zeptoSMDC0015F. With an initial resistance between 10 and 60 ohm and a hold current of 15mA. Although time to trip might be large and resistance increases if it's getting hot which might happen in a server room.
3. Use a push pull digital isolator with short circuit protection like the MAX14930AASE+, which has ESD protection built in as added bonus but does cost much more than a resistor (€2,51 for 1)
4. Use a bidirectional current sense amplifier like the INA2181A1IDGSR. With the added benefit that I can inform the user that the output is in a short circuit state, but with the downside that I need to continuously monitor the output of the ic at an analog input of the ATmega chip.

What do you think is the best option? Are there other options I missed? Or shouldn't I worry about short circuit conditions and just use a small resistor (e.g. 47 ohm) as said here?

--EDIT--

Based on your suggestions I'll probably be using a circuit like the one below. This also allows the B GPIO pin to be used as input such that the circuit can both be used for input and output wiegand signals.

• A separate line driver chip is a good possibility. You can find one with current limit / short-circuit protection, and a speed that is appropriate for your application. Also look into ESD/transient protection and termination (on both ends). On the receiving end, AC termination may be an attractive option for the unidirectional case. Feb 11, 2021 at 21:17
• Are Wiegand interfaces 5V these days? The last time I saw them used, they were using 12V. Do you have to be compatible with the 12V interface? The MCU pin can't handle that directly. Feb 11, 2021 at 21:21
• @Justme The 12V line is only to power the devices, 5V is the data line Feb 11, 2021 at 21:34

Why don't you drive it from some power line able to support higher current. For example, from Vcc=5V directly via P-ch MOSFET, that you will open and close using GPIO. I suggest some 10k-100k (you can do some math and experiment, but any should work probably) pulldown on that line to make sure the line is at 0 when the MOSFET is not conducting (pulldown on drain side on my picture; load on my picture = your line's output). If you find MOSFET quick enough, and there is plenty of fast MOSFETs, you'll be fine. After all, your intervals aren't all that quick, I'd bet almost any logic level MOSFET that works with 5V would fit. Provided it's rated for the maximum current you expect, not that it's big anyway.

CORRECTION

Since the receiving end has built-in pullup resistor, the transistor's role would be to pull the line down at the right time. For that purpose you use N-channel or BJT instead. A quick google search revealed that BJT are faster switches than MOSFETs, but these days they're all quick, and certainly quick enough for your application, so it's up to you (but don't forget to look at the datasheet). This correction is sponsored by @Justme.

• Ah nice idea! Although it's probably better to have a pullup resistor on the drain side, and GND on the source side to combat the pullup voltage from the receiver end. Feb 11, 2021 at 21:50
• It won't work that way. The MOSFET always conducts in another direction due to body diode (also present in the picture)
– Ilya
Feb 11, 2021 at 21:57
• and the @Justme just proposed the same solution just with replacing MOSFET with BJT, the core idea is the same)
– Ilya
Feb 11, 2021 at 21:58
• @Ilya I did not specifically say BJT, I simply said transistor. A NPN BJT or N-channel FET will do. The P-channel solution will not work as mentioned by OP, as Wiegand interface is pulled up by resistor and pulled down by a transistor. Feb 11, 2021 at 22:19
• ok I looked at the original schematic again, you're right, there's a pullup on the receiving end, so the transistor should pull down. Then yes, an N-Channel or BJT, agree.
– Ilya
Feb 11, 2021 at 22:25

None of the above solutions you mentioned. Simply a transistor to pull the tens or hundreds of milliamperes low to ground, it can still be limited by series resistance but much lower in value than you must use with the MCU.

• Ah yes, that might also be a good solution. Thanks! Feb 11, 2021 at 21:51

You can do something like this:

simulate this circuit – Schematic created using CircuitLab

(part numbers conceptual, not necessarily optimal).

The second circuit is rather more bulletproof, capable of handling large transients with current limited to a couple hundred mA, but more costly.