Shop OBEX P1 Docs P2 Docs Learn Events
Best way to multiplex 7-segment — Parallax Forums

Best way to multiplex 7-segment

ClintClint Posts: 95
edited 2010-07-07 05:36 in Propeller 1
I have a four digit, 7-segment common anode LED display. Each segment draws 10mA. I want to multiplex it with the Propeller using the fewest possible I/O and no external circuitry (except for resistors) if possible.

Normally I would have 7 outputs dedicated to the 7 segments and four outputs dedicated to each digit's common anode. But if I multiplex it this way, there would be 70mA through the anode outputs, which excedes the Propellers 40mA output rating.

Is there a better way to wire this and manage the current of the display?

Thanks for any help.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-07-04 16:55
    As you've noticed, you can't do this without external switching transistors for the common anode connections to handle the extra current. There's no way to wire this in order to make it work without the transistors. You could reduce the LED current to about 5mA and run everything directly off the Propeller. Usually 5mA provides plenty of light. That would be a maximum of 35mA through the digit I/O pins.

    You're only looking at 4 PNP transistors and their base resistors. If you're considering SMT, this won't take much room.

    Post Edited (Mike Green) : 7/4/2010 5:03:46 PM GMT
  • HarleyHarley Posts: 997
    edited 2010-07-04 17:03
    I've done such a design, except it used six 7-segment, plus decimal point, LEDs. Used a transistor or fet to select the digit; used 6-bits of one PIC port for that, used another 8-bit port for the cathodes directly connected to the LEDs. This was done pre-Prop.

    Scanned them around 80 Hz with an interrupt routine which also scanned for a key down in a 28 switch keypad (arranged 4 x 7; 00..0F for the hex keys and 10..1B for the remaining keys. Required 10 or 20 valid 'key down' events without a key up event to declare a valid key push. Worked slick for the keypads, and no flicker on the LEDs. And adequate brightness for seeing the LEDs. Only one segment is on at a time. The dp-segments were used to indicate certain modes of operation (labeled below the LED dp segment
    Clint said...
    I have a four digit, 7-segment common anode LED display. Each segment draws 10mA. I want to multiplex it with the Propeller using the fewest possible I/O and no external circuitry (except for resistors) if possible.

    Normally I would have 7 outputs dedicated to the 7 segments and four outputs dedicated to each digit's common anode. But if I multiplex it this way, there would be 70mA through the anode outputs, which excedes the Propellers 40mA output rating.

    Is there a better way to wire this and manage the current of the display?

    Thanks
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
  • ClintClint Posts: 95
    edited 2010-07-04 17:52
    The 5mA option sounds like something to try. Right now I'm using an SX chip talking to a Maxim ICM7212 which is supposed to output a static 8mA for each segment. I want to transition to a Propeller because I really like Parallax support and documentation, but to justify the added cost of the Prop, I am hoping to eliminate the rather expensive Maxim chip. I'm not sure how the brightness is going to compare going from 8mA static to 5mA multiplexed, but it will be simple enough to test once my Propeller education kit arrives.

    If I have to go to a transister array, that doesn't break the bank, but it means a little more soldering I'd like to avoid.

    I'd love to hear other ideas. This may be a dumb one, but what if I connect two output pins to one common anode? I'm guessing there's no guarantee the two outputs would get half current each.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-07-04 18:05
    The problem with connecting 2 output pins is that it's hard to make both of them switch on the same way at the same time. For a nanosecond or two, you may have a short circuit between 3.3V and 0V and a big noise spike on the Propeller's supply line. They're MOSFET output stages and those share current nicely like any other MOSFET transistors in parallel. The problem is that there are slightly different delays across the chip for the various I/O pins and their associated logic, so the width of that short circuit spike depends on which I/O pins you're using. You could put current limiting resistors in the common anode leads to each I/O pin, but then the LED brightness would depend on how many segments are on.

    The easiest solution is to use a transistor array and a resistor array for the base resistors. You could use an MOSFET (P-channel) array and save on the resistors, but I don't know of a P-channel 3.3V logic-level array.

    Post Edited (Mike Green) : 7/4/2010 6:13:02 PM GMT
  • tonyp12tonyp12 Posts: 1,951
    edited 2010-07-04 19:19
    Common anode, each led digit module·share a common power-in line.
    4*7= 28 led cathodes to sink to ground.

    Are you willing to use 28pins on the prop?
    In that case:
    In software just make sure that no more than
    4pins·are selected as Output with a 0 at any time.
    So do only 1 segment for each digit, only A first next B....

    loop:
    Turn all pins to input.
    innerloop: (do it 4 times)
    If (letter+innerloop) segement should be on in each digit.
    Turn responding·pin from input to output with a 0.
    end innerloop

    Wait a microsecond.
    Inc letter
    Go to loop


    You would get a 14% duty cycle.
    No need to use resistors in the final product.
    But while you write the software in would be helpfull
    in case it get stuck and leave a LED segment on for to long.

    Using less pins, special·NPN Transistor charlingplexing could be
    Let me draw something up.

    Here is regular charliplexing I did with 8% duty cycle.
    http://www.youtube.com/watch?v=8apRaZQbv5w


    Post Edited (tonyp12) : 7/4/2010 7:30:34 PM GMT
  • tonyp12tonyp12 Posts: 1,951
    edited 2010-07-04 20:24
    Using only 8 pins with npn-charliplexing.
    no tested, but should work.
    You would still have to make sure no more than 4 led's are on at anytime.

    Turn pin 1 to output with a 1·(select first segment)
    Turn pin 2 to input (set A-segment off)
    Turn pin 3 to output with a 0 (set B-Segment On lit)


    Below will·NOT work, as in this example the·digit A segment (pin2) is also connected to digit 2 NPN·transistor
    So it would also turn on·digit 2

    7segplex.jpg


    Post Edited (tonyp12) : 7/5/2010 1:36:16 PM GMT
  • ClintClint Posts: 95
    edited 2010-07-04 22:00
    I have never heard of "charlieplexing". I guess I need to read up on it!

    *EDIT* Wow thank you for the response! This concept looks promising. I'll investigate further.

    Post Edited (Clint) : 7/4/2010 10:07:50 PM GMT
  • nohabnohab Posts: 96
    edited 2010-07-05 13:35
    Charlieplexing is very interesting for discrete LEDs, however, having 7 LEDs arranged in a LED display with common anode (or cathode) makes Charlieplexing a little bit difficult...
  • kwinnkwinn Posts: 8,697
    edited 2010-07-05 14:42
    Using 2 pins per digit anode could be done by adding a small current balancing resistor between the pins and the digit anodes.
  • Invent-O-DocInvent-O-Doc Posts: 768
    edited 2010-07-05 15:20
    @Clint,
    If you are using an SX chip, those are great for directly driving multiple 7 segment displays. There is even a sample application of a serial driven 4 digit 7 segment display in the SX/B examples on the parallax website and in the IDE. It is one of my primary uses for the SX. You end up using only one pin on the prop. I bought a maxim driver and never used it because the SX works pretty well and handles the current. I'm sure it won't be as easy on the propeller due to tighter current limitations, though mike green's approach of four NPNs is a good one too.

    Do let us know what approach you decide to take!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Talbot
    New Market, MD, USA
  • HollyMinkowskiHollyMinkowski Posts: 1,398
    edited 2010-07-05 16:04
    Just a thought that occurred to me.

    Would it be possible to use a cheap .23
    317T with a couple of resistors to set it
    to the proper drive V for the LEDs and then
    eliminate all the LED resistors and just switch
    the LEDs with cheap npn transistors controlled
    by the props pins...directly from the output V
    of the regulator ???

    Usually there is 5v on any board that you
    could feed the 317T with. This regulator
    could drive a lot of LEDs I would think.
    You could adjust brightness by varying
    the regulators output V. You could even use a
    pot to alter between barely on and full brightness.

    If you had a lot of LEDs then it would be nice
    to just eliminate all those resistors.

    I love charlieplexing...there is just something
    cool about driving so many LEDs with just
    a few pins. it's elegant.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-07-05 16:05
    Note: I was talking about PNP switching transistors for the common anode pins with the emitter to Vdd, the collector to the common anode, and the base (through an appropriate resistor - 2.7K would work fine) to the Prop I/O pin. You'd make the I/O pin low to turn it on.

    The current limiting resistors for the LEDs would be in the leads to the Prop I/O pins for the segment cathodes. 200 Ohms looks like it would work at 3.3V with most red LEDs.. That's 3.3V - 0.3V {for the saturated switching transistor} - 0.3V {for the segment driver I/O pin} - 1.7V {for the LED itself (if red)} = 1V. By Ohm's Law, with a 5mA LED current, that gives 200 Ohms for the current limiting resistor.· For 10mA, they'd be 100 Ohms.

    Post Edited (Mike Green) : 7/5/2010 5:48:28 PM GMT
  • ClintClint Posts: 95
    edited 2010-07-05 17:25
    @Invent-o-doc: The SX EOL along with the need for more I/O in my upcoming product have pushed me toward the Prop. The Parallax community is my top reason for staying! Originally I wanted to use the SX to drive my display, but the timing didn't work very well. I needed to use the interrupt to monitor a high resolution encoder. If I added multiplexing into the interupt, I lost the timing I needed and missed encoder counts. If I did multiplexing in the main program I got bad flicker because I needed time to perform other calucations. The best solution I came up with was sending info to the Maxim driver and letting it handle the display. That has worked great so far. With the Prop I think I can dedicate a cog to the encoder, a cog to the display, and still have other cogs to dedicate to other tasks. I'm hopeful the timing will work out better this round.

    So far the solution I like the most, if it will work, is to run the segments at lower current. That would only require current limiting resistors, which I can get in a DIP array. Second choice is transistors for the common anodes. Until my prop arrives and I start playing with it, I'm not really sure what direction I'll take but I really appreciate all the discussion and info.
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-07-05 19:42
    How about using a serial in parallel out shiftregister like the 74-595?

    There are already objects in the obex for driving them

    best regards

    Stefan
  • pjvpjv Posts: 1,903
    edited 2010-07-05 22:45
    Clint;

    Firstly, charlieplexing works great..... for discrete leds. And then only if you require but a few to appear ON at the same time. In fact only one IS on at a time, and the multiplexing ratios get absurd very quickly as the need for more "simultaneous" leds goes up, unless you can do groupings where certain combinations can never happen.

    If you wish to use an SX, then the 4 digit display can be driven (multiplexed) directly from the I/O pins.... no transistors needed. Furthermore adding software to combine in your encoder is a piece of cake, and you will NOT get any flickering. But you must operate the interrupt with a scheduler rather than directly on the routines, and I can show you how to do that by looking at my contest entry from years ago. Multi-threading RTOS for the SX.

    Cheers,

    Peter (pjv)
  • RinksCustomsRinksCustoms Posts: 531
    edited 2010-07-06 03:35
    mike green as usual has a very correct and practical thought with the 5mA/segment suggestion..

    charlieplexing·i believe·can be done with two common anode & two common cathode displays.. ill SIM it in the am.. gonna let this one simmer on the burner overnight.. interesting idea indeed . . . i love good electronic·mental riddles..



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Quicker answers in the #propeller chat channel on freenode.net. Don't know squat about IRC? Download Pigin! So easy a caveman could do it...
    http://folding.stanford.edu/ - Donating some CPU/GPU downtime just might lead to a cure for cancer! My team stats.

    Post Edited (RinksCustoms) : 7/6/2010 3:17:04 PM GMT
  • RinksCustomsRinksCustoms Posts: 531
    edited 2010-07-06 15:16
    Here's the solution with minimal pins & minimal external parts/cost..idea.gif

    You'll need:
    • 2 common anode 7 seg disp
    • 2 commom cathode 7 seg disp
    • 7 330 ohm resistors
    • 9 I/O's (one I/O for every 2 additional displays)
    see picture for connections. How to make it work: you have your arbitrary bit patterns preset·for a seven segment display in lookdown/up's to be output on pins 0..7, it depends on which digit you are writing to but lets say were putting a "3" on the least significant digit, so·your bit pattern would be ("a" being MSB and "g" being LSB in blue) 0X 1111001. The MSB here represents the display B pin to the prop (red) wich we set to output Low. The green X in this example represents the display A connection, which is set to input. To put the "3" on U4 you simply invert the whole bit pattern and keep the "X" pin an input. You would switch the 0X to X0 bits to select the U1/U3 displays. The 330 ohm resistors/dip pack are for current limiting the segments to 5mA. Im a bit rusty on coding spin so ill spare some ridicule and embarassment by not coding an example right now. This is the bare minimum solution to what your trying to do.

    {{
    M. Rinkle 07/06/2010 14:15 EST
    these are a few bit pattern examples for charlieplexed 7-segmented displays on the propeller
    *Note- the propeller pins are tri-state 1/0/X(input)
            ┌┬────────────── Display control bits - cascading more displays is as easy as adding more bits/pins
                           on the MSB end.. ex. adding MSB "9" will yield two more displays. Bit patterns remain
                             unchanged for the add'l displays annodes/cathodes
                             **NOTE** take measures to ensure only one Display is selected in your loop @ once****
    
            ┣┼────────────── Selects which 7 segment display is "on" on this pin H/L/X(input = neither display)
            │┣────────────── Selects which 7 segment display is "on" on this pin H/L/X(input = neither display)
            ││       ┌┌┌┌┌┌┌ Bit pattern for 7 segment display - needs to be inverted depending on which display
    PIN# (9)87       6543210 is common (anode/cathoode)
            0X      %1111111 - "8" on U1 ┐
            1X      %0000000 - "8" on U2 │
                                         ├─ note how when a different common is selected everything is inverted 
            X0      %1111111 - "8" on U3 │  except the X which is the other displays that arent selected.             
            X1      %0000000 - "8" on U4 ┘                   
                                                             
            X1      %1001100 - "4" on U4 ┐
            X0      %1111001 - "3" on U3 │
                                         ├─ note that depending on the display selected the bit patterns may need
            1X      %0010010 - "2" on U2 │  to be inverted for the display to work
            0X      %0110000 - "1" on U1 ┘
            XX =    %dont matter - all displays off
     
    If more than 4 displays are required, for every extra I/O you get 2 more 7-segment displays. Using 330Ω current
    limiting resistors, and since only one 7-segment display is scanned @ once runing this scheme it doesn't matter
    how many displays are cascode from the 7 bit pattern outputs, total current consumtion will never exceed 1 display
    and all segments lit @ once (for 330Ω resistors, Imax >36mA on the Display A/B select I/O's)
    }}
    


    Hope this helps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Quicker answers in the #propeller chat channel on freenode.net. Don't know squat about IRC? Download Pigin! So easy a caveman could do it...
    http://folding.stanford.edu/ - Donating some CPU/GPU downtime just might lead to a cure for cancer! My team stats.

    Post Edited (RinksCustoms) : 7/6/2010 6:26:02 PM GMT
    739 x 451 - 36K
  • nohabnohab Posts: 96
    edited 2010-07-07 05:36
    This looks like a smart solution !
    (Provided that·Clint can change two of his common anode displays to common cathode)

    5mA would normally be enough, here it is combined with 25% duty cycle.....but it should be worth trying.

    Post Edited (nohab) : 7/7/2010 5:43:15 AM GMT
Sign In or Register to comment.