LED & Resistor befuddlement

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
I thought this was going to be simple. I have a controller, an LED, a
resistor and a socket. Its a five volt circuit.

I want to plug the LED into the socket in a board. The controller needs to
know whether or not the LED is plugged in, and if the LED is plugged in, it
needs to be able to turn it on and off.

One issue is that the forward voltage of just about any LED puts all the
voltages out in the middle of no-mans land in terms of logic levels.

Anyway, I came up with a solution, but it seems a little too complex and I
get the feeling I'm missing something. My solution is here:
http://miketurco.com/123/ledbef.gif.

Basically, if you put a low on the input and there's an LED in the socket,
the LED will turn on and you'll get a low on the output. If there's no LED,
then you'll see a high on the output.

Is there a way to accomplish this with one i/o pin? Any way to save a part?

Thanks,

Mike







Re: LED & Resistor befuddlement
Quoted text here. Click to load it

Yes, & how about saving 2 parts ? :)

a) If the uC has a ADC on board, you can measure the drop across the
NFET, to sense LED presence.

b) Place a small CAP ~1nF across the IO pin  to gnd, then
Float and readback in atomic form.  Read L = No LED,
Read H = LED is present. If the uC has open Collector &
low leakage port option, it might work with No cap.
-jg


Re: LED & Resistor befuddlement
On Tue, 1 Jun 2004 23:53:15 -0700, the renowned "Mike Turco"

Quoted text here. Click to load it

Watch that the output voltage on the port pin when driving the LED +
Vce on the transistor is guaranteed to be a reliable "0" (with decent
margin). If you're using a micro with (asymmetrical) TTL-compatible
inputs it might be better to flip everything around and use a PNP
(same number of parts).  


Quoted text here. Click to load it

I don't see a simpler (general) way of doing this. In the specific
case of a PIC @5V Vdd driving a GaAlAs super bright red LED at
relatively low current, you should be able to do it with two port pins
(one of which must be a TTL-level input) and no extra parts:


       Output
          o-------------------|
                              |
                              |
                              |
                              |  /
                              V  / LED
                              -
                              |
          o-------------------+
       TTL input              |
                             .-.
                             | |
                          1K | |
                             '-'
                              |
                              |
                             ===
                             GND


Here is a more complex circuit that uses just one port pin and drives
the LED with a small MOSFET rather than the port pin directly. It will
work with pretty much any single junction LED at pretty much any
reasonable current.  


                  +5 o--+-------+
                        |       |
                        |      .-.
                        |      | | 1K
                        |      | |
                        |      '-'
                         >|     |
                          |-----+
                         /|     |  /
                        |       V  /
                        |       -
                       .-.      |   LED
                       | |      |
                    1K | |     .-.
                       '-'     | |
                        |      | | RLED
                        |      '-'
                        |       |
                        |       |
                        |    ||-+
       Port pin         |    ||<-
          o-------------+----||-+ 2N7000/7002
                        |       |
                       .-.      |
                       | |     ===
                   20K | |     GND
                       '-'
                        |
                        |
                       ===
                       GND


If you turn the LED on (output = high) and then tristate the port pin,
and wait, say, 10usec, the pin will read 0 if there is no LED and 1 if
there is an LED.

BTW, this is kind of an unusual requirement. Why do you care if the
LED is there or not? Why not just "try" to turn it on? Are you
switching the program functionality depending on the presence of an
indicator LED?

Best regards,
Spehro Pefhany
--
"it's the network..."                          "The Journey is the reward"
snipped-for-privacy@interlog.com             Info for manufacturers: http://www.trexon.com
We've slightly trimmed the long signature. Click to see the full one.
Re: LED & Resistor befuddlement
On Wed, 02 Jun 2004 11:55:43 GMT, Spehro Pefhany

P.S. one more idea, specific to the PIC with ADC and requiring ZERO
parts beyond the LED and the resistor to set the current and just ONE
port pin.

You can set digital/analog port pins to be a digital output and still
measure the voltage on that pin with the ADC.  

For example, the minimum (3-sigma) output voltage at 5mA with 5V Vdd
is over 100mV. That represents 20 counts on a 10-bit ADC. That's
sinking current, the situation is even better with higher currents,
sourcing current, or with lower Vdd.

Best regards,
Spehro Pefhany
--
"it's the network..."                          "The Journey is the reward"
snipped-for-privacy@interlog.com             Info for manufacturers: http://www.trexon.com
We've slightly trimmed the long signature. Click to see the full one.
Re: LED & Resistor befuddlement
Quoted text here. Click to load it

What a nifty idea!! Now I'm interested to check what other uCs can operate
this way!


Re: LED & Resistor befuddlement
Huh? Have you never read the data sheets and looked at the I/O
structure?  There is no reason why they shouldn't operate this way, in
fact it requires more effort in the way of gating to disable the digital
output. Why handicap a port structure then. The only exception I've seen
has been on some odd micros where the A/D pins are dedicated and are not
mixed with GPIO.

Also, some micros allow you to read the digital state of the pin
directly vs reading the output register when the pin is in output mode.
Why? This is because the resistance from drain to source of the CMOS
output transistor (amongst other things)limits the amount of current
that can be supplied to the load. Sometimes the load can be heavily
capacitive and it could be necessary to check that it has reached the
state that it has been driven to.

General Rule:- READ data sheets, even those funny little charts and
tables, and figures at the end of them :)

--
Peter Jakacki

DM McGowan II wrote:
We've slightly trimmed the long signature. Click to see the full one.
Re: LED & Resistor befuddlement
Quoted text here. Click to load it
operate

If I dealt in electronics every single day then maybe this wouldn't have
seemed so cool.  I remember coming across something along these lines once
or twice and I liked Spehro's idea. If you don't like his idea then I'll
thank you to reply to HIM, not ME.


Re: LED & Resistor befuddlement
Hey, don't get so uppity! It's not that I don't like it, as if that
would have anything to do with it. I was merely surprised that you
weren't aware of this fact. However, since you don't deal in electronics
every single day it is understandable.

My apologies for offending you.

--
Peter Jakacki

DM McGowan II wrote:
We've slightly trimmed the long signature. Click to see the full one.
Re: LED & Resistor befuddlement
Quoted text here. Click to load it
once


Maybe I should only browse news after dinner. :-)


Re: LED & Resistor befuddlement
Quoted text here. Click to load it
... snip ...
Quoted text here. Click to load it

You have a sadly warped idea of newsgroups.  Everything is
public.  Replies are not directed at anyone in particular.  If you
want privacy, use e-mail, and you *may* attain your desire.  This
is public partly because correcting your misapprehensions may be
instructive to someone misinformed by your article.

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
We've slightly trimmed the long signature. Click to see the full one.
Re: LED & Resistor befuddlement
Quoted text here. Click to load it

This is a public forum?


Re: LED & Resistor befuddlement

"DM McGowan II" '
Quoted text here. Click to load it

Anybody with Internet access can read this newsgroup, and a zillion others,
either with a news reader or through groups.google.com.





Re: LED & Resistor befuddlement
Quoted text here. Click to load it

Except that those befuddled users who post using the X-No-archive
header ensure that nobody can ever read their immortal words
through google.

--
Chuck F ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
We've slightly trimmed the long signature. Click to see the full one.
Re: LED & Resistor befuddlement
Quoted text here. Click to load it
... snip ...
Quoted text here. Click to load it

It is not a forum.  It is an international newsgroup.  What you
write is disseminated all over the world to various news servers,
which hold the message for some period of time and allow anyone to
read it.  Some servers will apply their own rules to avoid misuse,
such as discarding messages with excessive cross-posting,
attachments, or html content.

--
Chuck F ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
We've slightly trimmed the long signature. Click to see the full one.
Re: LED & Resistor befuddlement
Quoted text here. Click to load it

That was polite sarcasm gentlemen. :-)


Re: LED & Resistor befuddlement
Quoted text here. Click to load it

I haven't thought about this in detail, and I'm probably neglecting
some important point, but why not put a capacitor in parallel with the
LED and its current-limiting resistor? When you want to detect the
LED's presence, follow an algorithm like this:

1. Set pin to output mode, low output
2. Bring pin high.
3. Wait for time t.
4. Set pin to input mode and sample.
5. If pin reads low, increase t and repeat from step 2.

You should see a certain threshhold time t for the LED-absent case,
and if you go much beyond this time, you can assume the LED is
present.

(Assumed: Micro is capable of driving the LED directly, open-emitter
output).

Re: LED & Resistor befuddlement
Quoted text here. Click to load it

Seems to me you guys are all over thinking the problem... or I am
missing something important.  

How about just adding one resistor and using the IO pin as an input when
you want to check for the presence of the LED and as an output when you
want to drive it?  

  ___
   |
   |
   -
  | | R1
  | | current
   -  limiter
   |  ~330 ohms
   |
  ---
  \ / LED
  _V_
   |
   +----------> To MCU IO pin
   |
   -
  | | R2
  | | Light
   -  Pulldown
   |  ~10 kohms
   |
  _|_
  \ /
   V

With this circuit the IO pin will be high if the MCU is not pulling it
down and the LED is installed.  If the IO pin is not driving it low and
no LED is plugged in, the IO pin will be low by R2.  The IO pin can
drive low to turn on the LED.  



--

Rick "rickman" Collins

snipped-for-privacy@XYarius.com
We've slightly trimmed the long signature. Click to see the full one.
Re: LED & Resistor befuddlement
On Wed, 02 Jun 2004 13:06:46 -0400, the renowned rickman

Quoted text here. Click to load it

This will work with good margin for some LEDs and some input buffers,
and not at all or marginally with other choices. For example, a
super-bright green LED will yield about 2.2-2.3V typically at the
input with the above circuit and 5V Vdd. Some input buffers need Vdd *
0.8 worst-case, others are okay at around 1.9-2.0V (the "TTL" type).  

Since this circuit is "measuring" the LED presence with 250uA rather
than 10-20mA, it has less drop and will work with more LEDs than the
circuit I showed, however it has one more component.

Best regards,
Spehro Pefhany
--
"it's the network..."                          "The Journey is the reward"
snipped-for-privacy@interlog.com             Info for manufacturers: http://www.trexon.com
We've slightly trimmed the long signature. Click to see the full one.
Re: LED & Resistor befuddlement
BPing :)

Quoted text here. Click to load it


I would skip the pulldown resistor altogether and simply drive the
output low for a few cycles then switch it back to an input.
The CMOS inputs have more than enough capacitance and a low enough
leakage to hold the charge from the last driven state.

After driving the pin low and floating with no led connected you should
indeed find a logic low on the input even for 100's of microseconds
afterwards.

Normally I use this method for reading dip switches etc where the lead
length is very short. If you want to run it a bit longer you should
shield it somehow.

After driving the pin low and floating it when a led is connected you
should see the input charging up to within Vdd in a very short period.

Method:
1. Drive pin low and switch to output mode
2. Hold for a few cycles
3. Switch pin to input mode
4. Wait for a few cycles
5. Read the input - low = (no led)

This way you can still drive the LED with a high current and you don't
need any additional components.

--
Peter Jakacki


Re: LED & Resistor befuddlement
Quoted text here. Click to load it
... snip ...
Quoted text here. Click to load it

Bad idea.  You just don't leave CMOS input lines open.  They can
drift to a state where both input transistors are on, and just
drawing excess current without limit.

--
fix (vb.): 1. to paper over, obscure, hide from public view; 2.
to work around, in a way that produces unintended consequences
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline