View Full Version : 2 LEDs and one pin left
Jumper
- 13th July 2010, 11:09
Hi All,
I have one red LED and one GREEN led and a few resistors and only ONE pin left on my MCU. It would be nice if there is a way to turn on green or red or have them both off.
Since the pin has 3 states it might be possible but today my brain just can't see how. Current goes in .. one LED is on... Current goes out.. the other one is on. But it is possible to have them both turned off without haveing any leaking current when the pin is in tri-state?
I never plan to have them on at the same time... just both off or one or the other on.
thanks!
mackrackit
- 13th July 2010, 13:47
Output HIGH
Output LOW
Input
Maybe
Jumper
- 13th July 2010, 14:01
and what makes the current not flow thru any of them when the pin is in INPUT?
mackrackit
- 13th July 2010, 14:12
From a data sheet.
Setting a
TRISA bit (= 1) will make the corresponding PORTA pin
an input (i.e., put the corresponding output driver in a
Hi-Impedance mode)
http://en.wikipedia.org/wiki/High_impedance
sayzer
- 13th July 2010, 15:09
1,0
0,1
0,0
LEDs on these states won't be possible by one pin.
Instead, use 4017 with one pin.
I have an example here:
http://www.picbasic.co.uk/forum/showthread.php?t=6548&
ScaleRobotics
- 13th July 2010, 15:20
Can't you?
4601
mackrackit
- 13th July 2010, 17:02
My turn to say DOH!!!
No matter how you connect two LEDs without extra hardware there will be feed back between the two.
A couple transistors or sayzer's solution are in order for this one.
mackrackit
- 13th July 2010, 17:31
How many DOHs are allowed in one day???
DUH code
BLINK:
HIGH PORTG.4
PAUSE 250
LOW PORTG.4
PAUSE 250
TRISG.4 = 1
PAUSE 2000
GOTO BLINK
And
4602
Jumper
- 13th July 2010, 18:00
Then we have the problem with the idle current.... 2 resistors in serie between Vdd and Vss is going to drain the battery. I like the idea! but the idle current will be almost half of what the LED uses when it is turned on (sssuming 5V Vdd and 2V voltagedrop over the led)
I dont have my lab stuff here.. does anyone think the idle current might be lower in the circuit i have attached.. or will smoke come out :-)
Sure there are many ways to solve the problem by adding more things but I am still hoping this will work...
or it will be DOOH and an other design.
Thank you!
rsocor01
- 13th July 2010, 20:02
Jumper,
You can use "one LED" only like the one in the link below. This is pretty much two LEDs put together. It is a red-green 3mm LED.
http://futurlec.com/LED/LED3RG.shtml
1,0
0,1
0,0
LEDs on these states won't be possible by one pin.
Instead, use 4017 with one pin.
I have an example here:
http://www.picbasic.co.uk/forum/showthread.php?t=6548&
However, the bad news is that Sayzer is right. You can't get three states "0,0", "0,1", and "1,0" with only one MCU pin.
Robert
ScaleRobotics
- 13th July 2010, 20:15
However, the bad news is that Sayzer is right. You can't get three states "0,0", "0,1", and "1,0" with only one MCU pin.
Really? Because I am using Dave's code on a 18F26J50 (3.3 volt) with no resistors, and it works like a charm. Red, Blue, off
4604
BLINK:
HIGH PORTA.0
PAUSE 250
LOW PORTA.0
PAUSE 250
TRISA.0 = 1
PAUSE 2000
GOTO BLINK
rsocor01
- 13th July 2010, 20:25
Really? Because I am using Dave's code on a 18F26J50 (3.3 volt) with no resistors, and it works like a charm. Red, Blue, off
BLINK:
HIGH PORTA.0
PAUSE 2500
LOW PORTA.0
PAUSE 2500
TRISA.0 = 1
PAUSE 20000
GOTO BLINK
DOH, :eek:
The trick is in the TRISA.0 = 1 to get both off (the 0,0 state). Nice!
Robert
Darrel Taylor
- 13th July 2010, 21:54
I think this page explains what Walter is doing pretty well ...
http://www.batsocks.co.uk/readme/p_tut_led16.htm
falingtrea
- 14th July 2010, 17:25
Simplest coding would be to generate a square wave signal on the pin, and then set the TRIS based on state of each LED. TRIS would have to be set every time you change the state of the pin in the square wave generating code. That way the LEDs will always be the same brightness. Of course the square wave signal would have to be interrupt driven off of a timer in order to have both LEDs on at the same time.
ScaleRobotics
- 14th July 2010, 17:49
Square wave sounds more difficult than Dave's code, and any square wave will light up both LED's on a two led with 1 output scenario. And Jumper just wants one, or none to light at a time.
sayzer
- 16th July 2010, 12:21
Really? Because I am using Dave's code on a 18F26J50 (3.3 volt) with no resistors, and it works like a charm. Red, Blue, off
4604
BLINK:
HIGH PORTA.0
PAUSE 250
LOW PORTA.0
PAUSE 250
TRISA.0 = 1
PAUSE 2000
GOTO BLINK
Nice trick indeed.
How about RED and BLUE = ON ?
(without ".....Of course the square wave signal would have to be interrupt driven off of a timer in order to have both LEDs on at the same time. " )
ScaleRobotics
- 16th July 2010, 14:37
Nice trick indeed.
How about RED and BLUE = ON ?
(without ".....Of course the square wave signal would have to be interrupt driven off of a timer in order to have both LEDs on at the same time. " )
Nice one Sayzer! I guess that is four states for one pin!
rsocor01
- 17th July 2010, 12:19
Nice one Sayzer! I guess that is four states for one pin!
Yes, the four states can be obtaind with only one pin. Very nice! :)
Now, if you use the red-green LED that I mentioned above a cool project can be made.
http://futurlec.com/LED/LED3RG.shtml
Since red + green = yellow, then with only one pin in the MCU we can obtain four different states in the LED: off, red, green, or yellow. Also, by varying the percentage duty cycle of the square wave different shades of yellow can be obtained. I haven't tried this yet but it might be a cool project.
Robert
sayzer
- 17th July 2010, 12:25
RED and BLUE = ON
The only way I can think of is to connect them in parallel. (if serial, 3.3V will not go through)
:D
rsocor01
- 17th July 2010, 12:40
RED and BLUE = ON
The only way I can think of is to connect them in parallel. (if serial, 3.3V will not go through)
:D
No, that's not what I meant. ;)
If you apply a square wave to this red-green LED, the colors will change so quickly that it will look like it is yellow. I haven't tried it yet, but I'm pretty sure it will look yellow to your eyes.
Robert
mackrackit
- 17th July 2010, 15:30
Hey Robert,
Can you give some example code for how the square wave method would work?
Say you have something like the sliding door app.
Green = full open
Red = closed
OFF = inbetween
Yellow = moving
rsocor01
- 17th July 2010, 17:36
Hey Robert,
Can you give some example code for how the square wave method would work?
Say you have something like the sliding door app.
Green = full open
Red = closed
OFF = inbetween
Yellow = moving
Mackrackit,
I'm going to order this part and test it to see if it works. The square wave is just a simple 50% duty cycle wave. By using the circuit provided by Scalerobotics, then if the square wave is low the red lights up and if the square wave is high then the green lights up.
A rapid changing of colors red -> green -> red -> green -> .... would appear to be yellow. It is just an optical illusion. Remember that I talking about a red-green LED with both colors in the same LED casing. Still, I would need to test it to see if it works.
Robert
4613
mackrackit
- 17th July 2010, 18:27
Looking forward to see your results, it would be very useful.
rsocor01
- 17th July 2010, 23:40
Looking forward to see your results, it would be very useful.
Mackrackit,
I tested this idea with a red-green 10 LED bargraph and yes it works. The setup is different from what we have been discussing in this thread, but the idea of getting a new color (yellow) is the same.
First, I applied a square wave to the circuit with a period of 1.2 seconds and you can see how the color changes between red and green. Next, I applied a square wave with a period of 2 milliseconds per cycle (50% duty cycle) and all you see is a yellow color. Also, If you change the percentage of the duty cycle you get different tones of yellow. This would be very useful for a project like the sliding doors.
Robert
http://www.youtube.com/watch?v=oF8EB62HxaE
mackrackit
- 18th July 2010, 06:21
COOOL!!!!!
I can think of several places where that will come in handy.
Looks like it would make a good article for the wiki. Add a bit of code and schematic for basic use....
muddy0409
- 18th July 2010, 10:35
Tried this on my Breadboard, works a treat.
Hmmm....have to work out how to ad a JPG to this...
BRB
Ah, there it is, I hope. I know it means 2 extra LEDs, but that's gotta be cheaper than changing the PIC or messing around with the power supply.
With the pin as an input, the 5 volt rail is not enough to turn on any of the leds, but setting the pin Hi or Lo the voltage is enough to turn on 2 of them. Also no current drawn during the Input stage.
Mike, K8LH
- 19th July 2010, 21:31
Jumper,
What does the rest of your circuit look like?
Regards, Mike
rsocor01
- 20th July 2010, 16:10
Add a bit of code and schematic for basic use....
Ok.
I attached the schematics to this post. The code is pretty simple. It uses only one pin in the PIC to create four states in the red-green LED. You can get Red, Green, Yellow, or the Off state in the LED using only one pin. Of course, for getting the last state (Off) all the credit goes to mackrackit. He figured that one out :).
START:
HIGH PORTB.0 'Turn on red light
PAUSE 2000
LOW PORTB.0 'Turn on green light
PAUSE 2000
FOR I = 1 TO 2000 'Obtain a yellow light
TOGGLE PORTB.0
PAUSE 1
NEXT I
TRISB.0 = 1 'Turn off LED
PAUSE 2000
GOTO START
4620
Dave
- 20th July 2010, 20:35
I vote for Muddy0409's except, I would put a resistor in series with the processor output lead to limit the output current. This is exactly what I would have proposed except I would have used a couple of zeners instead of the extra led in each leg... If you have an extra inverter available you could modulate one side of a bidirectional led (red/green) and connect the other side thru a resistor to the processor output pin and then place it either high or low and finally to an input state to shut it off.....
Dave Purola,
N8NTA
cncmachineguy
- 9th November 2010, 01:34
Referring to the attachment 2 posts above,
Am I just missing something? by my calcs, assuming 2V drop for the LED's the current would be 3/10000 = .3mA.
Will this be enough to light the LED? By my calcs, I would think 150-200 ohms would be more suitable. Any help to clear this up for me?
Darrel Taylor
- 9th November 2010, 02:05
I don't think the attachment 2 posts above will do any good with 10k resistors.
I had actually started making a flash demo for this when it first started, but with so many options it got too complicated.
I really think the correct theory is in the link from post #13 though. The link is also in the flash below ... under the title. (batsocks.co.uk/ ....)
I only made it through simulating +5V. Things are clickable in the image below ... try it.
At +5V the resistor is 100 ohms (with 2 diodes).
But if your situation is different, perhaps I can add to it. ...
<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="723" HEIGHT="800" ><PARAM NAME="MOVIE" VALUE="http://www.pbpgroup.com/files/2LED/2LEDS_1PIN.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="truSe"><PARAM NAME="QUALITY" VALUE="high"><EMBED SRC="http://www.pbpgroup.com/files/2LED/2LEDS_1PIN.swf" WIDTH="723" HEIGHT="800" PLAY="true" LOOP="true" WMODE="opaque" QUALITY="high" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>
Oh, it says I attached the .dsn file ... I didn't, cause it wasn't done.
But if you have Proteus, I will make it work for all conditions ...
cncmachineguy
- 9th November 2010, 02:31
Thanks Darrel. That is an awesome gadget. Is there any way to get you to replace d2 and d3 with variable resistors (or fixed if need be) and bypass the 200 ohm on the pin? This way it will be closer to the other circuit. I would love to test it (and yes, I am trying to use your sim instead of my breadboard) I think a more approiate value would be 0-1000 ohms. If not, its all good.
Darrel Taylor
- 9th November 2010, 03:33
Well, the problem with that ... is that the variable resistors would only control current.
But the correct operation of the LED's depends on the voltage.
If the total forward voltage of the LED's is less than VDD, both LED's will be ON no matter what the resistor values are. The only difference will be their brightness.
Given a specific VDD voltage, LED color (V forward) and foward current, the correct configuration can be found.
And to add 2 variable resistors to the flash demo, would increase the frames from ~50 to more than 500,000. I'm affraid that will take a few years to create, and you probably won't wait the 2 weeks to download it. :eek:
I suppose it could be done more efficiently.
But again, if you have Proteus, it's a "Piece of Cake".
cncmachineguy
- 9th November 2010, 03:41
thanks darrel, once again, it seems a case of I know not what I ask. Don't worry about the demo then. As for the actual circuit, I will have to mull over why the 2 resistors in series with the led's doesn't create a voltage divider.
I would just LOVE to have proteus. I tried looking it up 1 time, seems it was in the 4 digits, just a little much for me :(
Darrel Taylor
- 9th November 2010, 04:09
Actually, I'd rather know your conditions and do the math.
What is it you need to do with your LED's?
VDD, LED Forward Voltage / Forward Current?
See if the theory works?
... As for the actual circuit, I will have to mull over why the 2 resistors in series with the led's doesn't create a voltage divider.
Because the voltages across the resistors are changed by the voltage drops that are controlled by the LED's.
I would just LOVE to haave proteus. I tried looking it up 1 time, seems it was in the triple digits, just a little much for me :(
That's what I thought too at first.
But they have a $250 "starter version" that gives you a 12F, 16F and an 18F.
Of course it comes with all the other logic chips, analog stuff and test instruments.
Even if it's not the exact chip you target, the "Family" is usually close enough to know your program has a chance.
Beware:
Once you get used to it ...
You probably will spend $1000 for the full PIC version.
cncmachineguy
- 9th November 2010, 04:25
The LED's will be board level indicators, showing drive enables, disabled, or in a fault
red is 2Vf @ 10-20ma green is 2.2Vf @ 10-20ma
Vcc 5V
Now I could use 3.3Vsupply for the LED's But was trying not to add that.
$250 I could deal with, its the beware I am listing too!
rsocor01
- 9th November 2010, 05:08
Yes, after I posted that attachment I realized it was wrong. The correct value for the resistors should be between 100 and 330 ohms depending on the brightness that you want. I'm sorry for the confusion.
Robert
sayzer
- 9th November 2010, 08:13
I am using this technique with 6K8 resistors on 3.1V/1500mcd LEDs.
Vdd is 5.0V.
I am using one pin to simulate TX and RX transmission with two LEDs inside Hserin and Hserout routines.
The light level is more than good enough for the purpose.
I am %100 satisfied with the result.
__________________________
cncmachineguy
- 9th November 2010, 23:15
here was the setup:
5Vdc->R1->2.2vF LED->1.9vF LED->R2->GND
R1=R2
first tried 240 ohm, Great brightness for each, pretty bright with no input :(
next up 1K, simular results just dimmer :(
last 4.7K, No real output for off, bright enough to see with input, but not really enough for an indicator in this app.
So my opinion is everybody in this thread is correct in some respect.
I feel like the best solution is to use a 3.3V supply. that way there is NO way to light both, and each can be nice and bright. Now, question for the masses: can we use a voltage divider to get this 3.3 from 5? This seems to me to be the least costly answer. Just 2 resistors and off we go. Hang a resistor inline with the signal pin and life is good. My perticular application will have 6 sets of LED's so if 1 from each set were on at once, could be 120mA.droping 1.7 volts, that would be 1.7*.12=.2W. That part doesn't seem too bad. Of course they could be strobed so there would never be more than 1 on at a time, then it would be 1.7*.02=.034W
mackrackit
- 9th November 2010, 23:35
can we use a voltage divider to get this 3.3 from 5?
And run the whole thing? Nope.
Using 5 volts with 470 resistors the thing I posted works fine.
cncmachineguy
- 9th November 2010, 23:49
Dave thank you! I actually intended to hook it up this way, but somewhere between yesterday and today I got myself turned around. I even drew it up this way in my schmatic. double DOH! So 470 both sides, makes sense to me!
Prolly the only size sips I didn't order.
Darrel Taylor
- 11th November 2010, 16:21
I want to get a better idea of how these LED circuits will work.
So let's take a look at how the DOH! circuit will perform ...
<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="820" HEIGHT="620" ><PARAM NAME="MOVIE" VALUE="http://www.pbpgroup.com\files\2LED\LED-470.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="true"><PARAM NAME="QUALITY" VALUE="high"><EMBED SRC="http://www.pbpgroup.com\files\2LED\LED-470.swf" WIDTH="820" HEIGHT="620" PLAY="true" LOOP="true" WMODE="opaque" QUALITY="high" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>
It's more significant since you will be using 3 sets of 2-LEDs.
Dave
- 11th November 2010, 16:58
cncmachineguy, The only problem with this circuit arrangement is there will always be current flowing in the circuit even if the LED's are supposedly off...
Dave Purola,
N8NTA
cncmachineguy
- 11th November 2010, 19:35
OK big thanks to Darrel for the sim :)
As for the constant current draw, In this app its no big deal. I will have a 5V 20A supply so I don't think it will be an issue. As long as no ones hot, they can draw all they want. Now I realize this would never be good in a battery app, so I will keep this in mind.
Overall thanks to all who helped out on this thread.
Dave
- 12th November 2010, 11:29
cncmachineguy , Hey, We all have to think GREEN nowdays......
Dave Purola,
N8NTA
sayzer
- 12th November 2010, 16:27
cncmachineguy , Hey, We all have to think GREEN nowdays......
Dave Purola,
N8NTA
I agree :)
If you make a product and it sells let say 1M unit, then; since you are drawing 20mA for nothing, it will cost & consume 20,000A for nothing.
But, the question then would be this : Would I care that much if I could manage to sell 1Million units of anything ?
mackrackit
- 12th November 2010, 16:52
Green?
If we go with DT's first sim and add the four extra diodes to save the 20ma while the part is running. I wonder what the extra "green" cost of manufacturing, shipping and all the rest for the diodes and the possible extra board space for the part all adds up to.
I would guess, just a guess, the energy would be more than 20 ma at 5 volts. And what would it cost to do the study to find out?
cncmachineguy
- 12th November 2010, 18:08
First of all, one or the other LED will be on when power is applied, so current WILL be drawn when the switch is on. And as the system could draw up to 20 Amps plus when you throw in the hot wire, whats a few mA between friends?
Second, the Green LED should be lit most of the time, so it will be green! :)
Thrd, If I were making 1M units, I would change lots of things so as not to need to multiplex the I/O for LEDs, but as I am prolly only gonna make a few, I choose the easy way out. This will be more green because I won't have to spend as much puter time getting things sorted out so I can turn the lights off sooner and go to bed.
BTW, 3 100W light bulbs left on for 365 days would be ~21,900A. I don't think the local utility will notice
cncmachineguy
- 17th November 2010, 00:49
No I haven't put this to bed yet. Ok darrel, or anybody else, hows the sim like this scenerio? Use any values you like for R's. No need for the really cool clicky thing. I;m good with text answers.
4952
mackrackit
- 17th November 2010, 02:13
My SIM..
5 volts with 470 Rs. Much of the brightness will depend on the angle of the LED, physical and radiating.
http://www.youtube.com/watch?v=gEfOU09A4eg
cncmachineguy
- 17th November 2010, 02:26
I like the sim dave! Thank you! I will finish my order now
gadelhas
- 20th November 2010, 20:52
<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="820" HEIGHT="620" ><PARAM NAME="MOVIE" VALUE="http://www.pbpgroup.com\files\2LED\LED-470.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="true"><PARAM NAME="QUALITY" VALUE="high"><EMBED SRC="http://www.pbpgroup.com\files\2LED\LED-470.swf" WIDTH="820" HEIGHT="620" PLAY="true" LOOP="true" WMODE="opaque" QUALITY="high" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>
Hi, everyone;
Can somebody teach me how to do this flash animations, from Proteus?
I have the Proteus 7.7 SP2.
Thanks in advance
Darrel Taylor
- 21st November 2010, 01:51
Well, Proteus doesn't export Flash.
But it does export images in several different formats.
For the animation above, I had to export one image for each possible state.
I used 4 different resistor combinations, and 3 switch states per combination, so it took 12 images for the whole thing.
The images were imported to Aligator Flash Designer from Selteco, where you can add the transition effects and define the sequence according to what people click on. Add some "Circles and Arrows with a paragraph on the back of each one" and you have a Flash Simulation.
The one above took about 8 hours or so.
gadelhas
- 21st November 2010, 20:35
Thank you DT for your explanation!! I will try to do it like you said.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.