If a pin is configured as an output, is it safe for current to current to flow into the pin? I have an optoisolator and the anode is connected to a +5V source constantly. The cathode is connected to the pin. When the pin is held low, 33mA of current (max) will flow into the pin. When the pin is high, no current should flow. This is to compensate for my stupidity in ordering inverted logic NMOS gate drivers.
Draining current into output pin
(11 posts) (3 voices)-
Posted 4 years ago #
-
It is safe to 'sink' current into an output pin.
An output pin can normally both source (act as a +V source, 'producing' current) or sink (act as a 0V or Ground sink, 'consuming' current) for current.
(Open Collector only actively 'sinks' to ground)BUT, 33mA is beyond the maximum of the electrical spec for the STM32F103.
The datasheet says ABSOLUTE MAXIMUM 25mA on an I/O pin.
It further specifies operating characteristics based on 8mA, for normal voltage characteristics (Low <= 0.4V), and 20mA for "weaker" drive voltage characteristics (Low <= 1.3V).I might be willing to try it just to quickly test something, but I would want to put something in to sink that much current, like a transistor or MOSFET (but I am a bit conservative on these things :-)
(full disclosure: I am not a member of the LeafLabs staff)
Posted 4 years ago # -
Ok... So I should choose a larger resistor. Maybe something on the order of 500R? I just realized my calculation for 33mA was wrong (I assumed 5V instead of 3.3V), but 22mA is still high. 500 Ohms should be sufficient. I could go as high as a 1K resistor, but then the output starts getting a little weak. Shouldn't be a huge problem because the output goes to a NMOS driver anyway.
Posted 4 years ago # -
So is the anode of the optoisolater connected to 5V or 3.3V?
If it is 3.3V 500 ohm sounds too big.The STM32F data sheet says 20mA/pin, so try to keep under that.
What is the forward voltage drop across the LED?
It is usually about 1.5V worst case,
so 3.3 - 1.5V = 1.8V
with a 'low' of 1.3V (worst case)
1.8V - 1.3V = 0.5V
R = V/I = 0.5V / 20mA = 0.5/0.02 = 25 ohmMinimum/best case LED forward voltage 1.0V (e.g. for a Toshiba optocoupler)
so 3.3V - 1.0V = 2.3V
with a low of 0.4V (optimistic, hence unlikely)
2.3V - 0.4V = 1.9V
R = 1.9V / 0.02A = 95 ohmrunning this again for 8mA
worst case 0.5V/0.008A = 63 ohm
best case 1.9V/0.008A = 238 ohmCheck your data sheet, but 500 ohm may be way to big.
It looks like 100-220 ohm would be okay, and you could measure the actual current, or voltage drop with a meter.
(but no guarantees given, or responsibility taken :-)(full disclosure: I am not a member of the LeafLabs staff)
Posted 4 years ago # -
First, you are correct in that I did not account for the voltage drop across the LED. Second, I actually tested it with a 1K resistor and it worked fine (just the outputs were a little weaker, as in the LEDs were dimmer).
So, the specs on the opto (http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTV-8x6.pdf) show that it has a 1.4V max forward voltage drop (unless that is the threshold voltage). Either way, I will simply measure the current. I know that it will work with a 500 Ohm resistor, so I might just stick with that to be safe.Posted 4 years ago # -
Silntknight -if 500 ohm's works well, fine.
If you need a bit more headroom to allow you to reduce sensitivity, or increase speed, at the other side of the optoisolator, then you might want to estimate how low would be safe.
Estimating a resistor value based on the 1.2V typical forward voltage drop, 8mA, maybe even ignore the worst case 0.4V LOW i.e.
3.3V - 1.2V = 2.1V / 8mA = 263 ohm
nearest preferred is 270 ohm
should be safely within the STM32F spec.Posted 4 years ago # -
Ok. I'll look into that as well. The thing is that I will occasionally be running 2 LEDs in series and at other times, just one. If a 270 Ohm resistor works safely, then I'll probably go with that. Thanks!
Posted 4 years ago # -
With two LEDs in series, the voltage drop calculation becomes:
3.3V -1.2V - 1.2V = 0.9Vthe current calculation for 500 ohms is 0.9V/500ohms = 0.0018, or 1.8mA,
so going for a smaller resistor value, like 270 ohm, which is safe for a single LED, might be more convenient.Posted 4 years ago # -
I agree. That is why I will likely go with the 270 ohm resistor. Thanks again!
Posted 4 years ago # -
I have seen a DC current clamp meter, but is there one that is both ac and dc?
Posted 3 years ago # -
niyaas1 - That looks like an attempt to post a spam ad, so I have broken the link.
You can get a good answer to your question using your favourite search engine, and something like "ac/dc current clamp meter"
Posted 3 years ago #
Reply
You must log in to post.