Shop OBEX P1 Docs P2 Docs Learn Events
Pins as inputs/outputs .. sinking and sourcing current — Parallax Forums

Pins as inputs/outputs .. sinking and sourcing current

CassLanCassLan Posts: 586
edited 2009-08-27 20:51 in Propeller 1
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 turn.gif


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

  • localrogerlocalroger Posts: 3,452
    edited 2009-08-26 12:36
    No, inputs do not draw or supply current. You need to set both pins to output, and one high and the other low; then current will flow between them. Don't forget a limiting resistor; prop pins can source or sink about 30 mA average over time, more than that will blow your prop.· If you're scanning a matrix you can do more than that in pulses but you have to keep the average down to about 30 mA.

    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
  • Agent420Agent420 Posts: 439
    edited 2009-08-26 12:46
    controllers like the Prop typically do not drive an led matrix directly, because the common row (or column depending on design) will need to handle the summed current of all the lit leds that are on that row, and this can exceed the io pin capacity - in the Prop the io pins are specd at 40ma.·· If you are only lighting one or two at a time you may be ok, but more often the common row (or column) lines control a transistor to handle the load.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • CassLanCassLan Posts: 586
    edited 2009-08-26 12:59
    Thanks for the clarification!

    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)

    ·
  • CassLanCassLan Posts: 586
    edited 2009-08-26 13:36
    Agent,
    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)

    ·
  • photomankcphotomankc Posts: 943
    edited 2009-08-26 14:46
    I think the transistor just sinks/sources the current from all the LEDs that have been turned on via the outputs of the prop. Similar to a keypad scan. You turn on the transistor with the row control pins to activate that row and then you turn on the pins on the prop for the individual LEDs (columns) you want to light up on that row. All the column common connections are wired together down the whole display, while each row is wired only to the common connection for that row.

    Post Edited (photomankc) : 8/26/2009 2:52:38 PM GMT
  • NetHogNetHog Posts: 104
    edited 2009-08-26 15:07
    Ok, added some diagrams to work with (quickly did this in paint as I didn't have my cad program to hand)

    A: This shows one style of bi-color LED
    B: This shows a "common cathode" matrix hookup
    C: Shows a transistor driver for B
    D: "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
    600 x 300 - 4K
  • Agent420Agent420 Posts: 439
    edited 2009-08-26 15:07
    CassLan said...
    Agent,
    But if I sum the rows...or columns with a transistor, then wont I loose the ability to control each LED individually?

    Typically, led matrix displays are scanned so you are only driving 1 row at a time.· You scan through the rows at a high frequency, which results in a pov (persistence of vision) effect where all the rows seem to be lit simultaneously.

    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...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • SRLMSRLM Posts: 5,045
    edited 2009-08-26 15:14
    http://forums.parallax.com/showthread.php?p=770357

    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.
  • NetHogNetHog Posts: 104
    edited 2009-08-26 15:17
    Good link Agent.

    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.
  • CassLanCassLan Posts: 586
    edited 2009-08-27 12:25
    Thanks all for the links and ideas.

    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)

    ·
  • photomankcphotomankc Posts: 943
    edited 2009-08-27 12:51
    No, in the D diagram the prop would be sourcing the current to the LEDs directly. If you insert E into it then the prop is only sourcing the base-current required to turn on the transistor fully under the load imposed by the LEDs. The transistor is providing the current to the LEDs.
  • Agent420Agent420 Posts: 439
    edited 2009-08-27 13:17
    There are two aspects to current you have to consider; both the current per pin (40ma) or max per port or chip (I think 300ma for the Prop).· Using transistor drivers to control a common column or row helps meet the per pin spec, but you also have to ensure that the sum of·individual control pins do not exceed the chip or port rating.·

    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.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • CassLanCassLan Posts: 586
    edited 2009-08-27 13:22
    The Goal is to have 10 of these working at once, I have a bunch of 4021s 4094s and experience working with them, I'll have to check the sheet to see if they can sink/source enough.

    Rick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    NYC Area Prop Club

    Prop Forum Search (Via Google)

    ·
  • Agent420Agent420 Posts: 439
    edited 2009-08-27 13:36
    I don't think the 4094's will be up to the task.

    You may want to Google something like 'scrolling led schematic' for some design ideas.· The first hit looks easy enough.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • photomankcphotomankc Posts: 943
    edited 2009-08-27 14:38
    Agent420 said...
    There are two aspects to current you have to consider; both the current per pin (40ma) or max per port or chip (I think 300ma for the Prop). Using transistor drivers to control a common column or row helps meet the per pin spec, but you also have to ensure that the sum of individual control pins do not exceed the chip or port rating.


    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)...

    Good point. I was only considering the common connection current not the I/O pins on the individual lines.
  • CassLanCassLan Posts: 586
    edited 2009-08-27 15:12
    I was doing the POV method and even at 20mA they were just too dim.

    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)
  • Agent420Agent420 Posts: 439
    edited 2009-08-27 15:25
    Idk... the majority of matrix displays are multiplexed; the fact there are common anodes rather than individual connections to each led would seem to agree with that.

    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
  • CassLanCassLan Posts: 586
    edited 2009-08-27 16:00
    I hear what your saying, I'm just thinking that it could have been a solution that either Always had green/red on, this would make providing the proper current easier, or a solution that would provide the proper varying current needed for a row depending on how many LEDs where lit at that time.

    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)
  • Agent420Agent420 Posts: 439
    edited 2009-08-27 16:12
    By the looks of it, you aren't far behind building an led cube (something I've always wanted to do) ;-)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Roger LeeRoger Lee Posts: 339
    edited 2009-08-27 17:04
    Agent420 said...
    you aren't far behind building an led cube

    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
  • NetHogNetHog Posts: 104
    edited 2009-08-27 17:08
    I did a 3x3x3 LED cube quite a while ago (using the SX). Need to do a bigger cube sometime [noparse]:)[/noparse]
  • NetHogNetHog Posts: 104
    edited 2009-08-27 17:44
    POV Brightness:

    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.
  • CassLanCassLan Posts: 586
    edited 2009-08-27 20:06
    Thanks for all the help guys,

    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)
    1600 x 1200 - 527K
    1600 x 1200 - 577K
    1600 x 1200 - 482K
  • NetHogNetHog Posts: 104
    edited 2009-08-27 20:10
    Cool!
  • Roger LeeRoger Lee Posts: 339
    edited 2009-08-27 20:19
    nice, but has it been any fun at all. [noparse]:)[/noparse]
  • CassLanCassLan Posts: 586
    edited 2009-08-27 20:51
    Of course it has Roger!

    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)

    ·
Sign In or Register to comment.