Pins as inputs/outputs .. sinking and sourcing current
CassLan
Posts: 586
I have a quick question, which although I'm pretty sure I've figured out...it would still be helpful if anyone can lend some insight.
I picked up some LED matrix boards at the expo, and I'd like to drive them from the prop.
They happen to bi-color but that part doesn't really matter just yet.
they are 5x7
So I was assuming I would make 1 pin and output and set it high, and another pin in input
and this would allow current to flow from the output pin..through the resistor...through the LED and back into the input pin.
I'm sure many of you already know this did not work, instead I had to make both pins outputs and set the aforementioned output pin high, while the other "output" pin is set to low.
This allows current to flow and I get lit LEDS
Is this what tri-stating is?
Am I wrong in assuming that an input would allow current flow?
Is this the standard with all microcontrollers?
I appreciate any thoughts because I think this is a common minsconception among newbies.
Thanks,
Rick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
·
I picked up some LED matrix boards at the expo, and I'd like to drive them from the prop.
They happen to bi-color but that part doesn't really matter just yet.
they are 5x7
So I was assuming I would make 1 pin and output and set it high, and another pin in input
and this would allow current to flow from the output pin..through the resistor...through the LED and back into the input pin.
I'm sure many of you already know this did not work, instead I had to make both pins outputs and set the aforementioned output pin high, while the other "output" pin is set to low.
This allows current to flow and I get lit LEDS
Is this what tri-stating is?
Am I wrong in assuming that an input would allow current flow?
Is this the standard with all microcontrollers?
I appreciate any thoughts because I think this is a common minsconception among newbies.
Thanks,
Rick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
·
Comments
Most bicolor LED's have the two different color LED's cross-connected, so if you make pin 1 high and pin 2 low it will be red, but if you make pin 1 low and pin 2 high it will be green. Make both pins the same level, or either an input, and the LED will be off.
And yes, making a pin an input is "tri-stating," that's the third state other than high and low.· Usually it's meant that you can wire a bunch of "outputs" together and the tristate ones won't interfere with the one that is acting as an output at a given moment.
Post Edited (localroger) : 8/26/2009 12:42:10 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
As it turns out these bi-colors are more like 2 LEDs in one package..common anode.
There are 2 seperate Cathode pins for each location of the matrix..maybe I can get some cool color combos.
I will post up a vid when done.
Agent:
I'm only lighting one at a time..just fooling around, Ive noticed that when I go for several at a time they get very dim.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
·
But if I sum the rows...or columns with a transistor, then wont I loose the ability to control each LED individually?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
·
Post Edited (photomankc) : 8/26/2009 2:52:38 PM GMT
A: This shows one style of bi-color LED
B: This shows a "common cathode" matrix hookup
C: Shows a transistor driver for B
"common anode" matrix hookup
E: Shows a transistor driver for D
I believe your scenario is D, so I'll talk about that first.
You can work out the current going through an LED by calculating I = (VPIN-VFWD)/R
So, if VPIN is 3.3v, VFWD is 2.1v, and R is 100 ohms, 12mA is used per LED, or 36mA to drive 3 LED's. It can be said that·if P7 is high, and P8,P9,P10 are low, then P7 is sourcing 36mA,·P8 is sinking 12mA,·P9 is sinking 12mA, and P10 is sinking 12mA.· This is less than the 40mA that the Prop can handle, so no transistors required here.
Now if it was a 7 segment LED (8 lines, 7 segments + dp) then you can easily go up to 96mA on P7.
In this case you'd need to limit to 5mA per LED (40/8), so using V/I -·(3.3-2.1)/.005, suggests 240ohm resistor. But the LED's would be very dim.
By putting a switching PNP transistor between P7 and the LED's, (connecting·Emitter to 3.3v, and Collector to LED's)·you can increase current capacity.·Adding a transistor in this manner also inverts the current. A·2K resistor should be fine for R9. When you drive P7 *low*, about 1mA·(for 2K resistor)·flows through the Base/Emitter vs 96mA above. This is enough to turn the transistor on, and drive the LED's. Now you're good to go. Assuming the transistor has a minimum hfe of 100, then it can drive up to 100mA.
If you was dealing with a common cathode setup (B), you'd use an NPN transistor (C), and turn it on by driving P3 *high*.
The setup for A should not need any transistors, just 100ohm resistor.
Post Edited (NetHog) : 8/26/2009 3:17:27 PM GMT
I couldn't find a great example, but this link demonstrates the idea.· I'm sure there must be a similar post here at the Parallax forums...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The one above was at the expo, and I noticed that if you looked at it through a digital camera you could see the "waves" as it was refreshed. Pretty cool.
You can also do it transistor-less if you limit how many LED's you have on at a time, but you can start getting flicker and/or the brightness fades.
I've got common Anode on the collumns(7) and common Cathode on the Rows(5 x 2) the x2 is because they can be red or green.
So based on what NetHog said, I can go either way with the transistors...B or D from his diagram, its just a matter of whether I want to use 10(5x2) or 7 right? Looks like almost the same setup as Agents link, and they chose to go with the design that uses 5 instead of 7.
In the D-E diagram..wont that mean that the Prop has to sink allot of current? This is also the same way they do it in the Link Agent provided, I'm just curious.
I'm going to start bread boarding it up!
Rick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
·
If your matrix is common anode on the 7 colums, you could use PNP transistors on the top to control the current source; that meets the per pin spec.· Then you have potentially 10 cathodes to sink (5 x 2)...· It is often the case that mutliplexed displays are driven on the upper range of the led current spec so that the average brightness is similar to what you would get with a lower current that is always on.·· Nonetheless, lets use 20ma per led as an example· - that yields a worst case drain of 200ma spread amongst the 10 pins.· That should be within the Prop's ability, though I prefer to minimize the current the controller actually handles.
A common chip that is used to handle io drain loads is the ULN2803, which is an inexpensive ic containing 8 darlington arrays capable of 500ma each.· This basically offloads the current handling from the controller.
As your matrix display becomes more complex, such as the bi-color feature, you tend to require more io to control it.· Certainly the Propeller has enough for the task, but many times alternative methods such as clocked shift registers or dedicated ic matrix drivers are used to simplify design.
Anyway, here is another bi-color matrix example project based on the Arduino, but should provide some more food for thought.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Rick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
·
You may want to Google something like 'scrolling led schematic' for some design ideas.· The first hit looks easy enough.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Good point. I was only considering the common connection current not the I/O pins on the individual lines.
So I opened one of these up and its clear why:
These LEDs are super tiny, they were pulled from some display that probably did not use a POV method.
I am just using the reflective holder and light dispersing lens to make a similar board using brighter LEDs.
You can see in the last pic that the last to collumns are actually on..but not very bright.
Rick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
I have seen mutlplexed displays where the forward current is much higher than the rated spec; 40ma or more would not be entirely uncommon.· Because the power is spread out over time with the refresh period, the led can handle it.· Though that would probably require some form of switching outside of the Prop because it would exceed the current capacity.
Also make sure you are taking into account the forward voltage when calculating the current.· And it may not make much difference, but green is typically ~2V and red is ~ 1.5V.· And just to clarify the resistors should be on the individual rows, not the common anode.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (Agent420) : 8/27/2009 3:36:35 PM GMT
I checked the forward voltage and its 2.1~ with Green, 1.75~ with Red
I put a POV method into place with 30mA and I just dont like how dim they are, but I will keep fooling with that.
I've modified one of them with larger brighter LEDs, I still have the other 10 as is.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I agree, he is nearly there, Just one more dimension to add.
Go for it, 3D cubes are interesting and fun.
At least I think they are.
Roger
Don't forget that you will need a little pause between "on" and "off" of an LED.
http://en.wikipedia.org/wiki/LED --
Good experiment is try a delay of, say, 1ms, and start reducing it (500us, 200us, 100us, 50us...). Too long, you'll get flickering. Too short, you'll get a dim display due to capacitive effects of the LED.
In thoery, 1-10us delay should be fine.
I wrapped up what I was working on today into a project box, now its time to make some cool animations!
Youtube of it in action:
http://www.youtube.com/watch?v=N0GlE5XoZKY
Rick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
It will be more fun when I make it into a clock with an alarm ; )
Rick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club
Prop Forum Search (Via Google)
·