Controlling many output lines from just a few GPIO lines

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Everyone

I am looking for a way to switch a large (ish) number of outputs from an AVR micro. The GPIO lines would be connected to an LED bank of around 60 LEDs and I want to be able to turn each one on and off individually.

Ignoring the current sourcing issues (for the time being) is there a standard method of switching many outputs from a limited number if GPIO lines?

Thanks for any suggestions you can give :)

FR

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A common method is to use 74HC595 shift registers in a chain. You can also use TI tpic6595 which have high current drivers built in.

There are other methods, but '595s are common.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

google for charlieplexing

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

FiniteRed wrote:
The GPIO lines would be connected to an LED bank of around 60 LEDs and I want to be able to turn each one on and off individually.

AVR -> 3 wire -> MAX7219 -> 64 LEDs

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Everyone

Thanks for all of the responses, ill do some reading up on the suggestions ^_^

FR

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

lode_leroy wrote:
google for charlieplexing
I'm a big fan of this technique, but there are limitations which restrict its suitability.
    - with N pins, contol N*(N-1) LEDs - for 60 LEDs, you'd need 9 pins
    - requires a timer interrupt to refresh even a 'static' matrix
    - each LED is driven at a duty cycle of (100/N)%
    - even with external drivers for common anode or cathode designs, each LED is limited by GPIO pin current restrictions
I nevertheless recommend you learn about it. You likely won't want to use it to control 60 LEDs, but I have found it to be suitable for 20 LEDs using 5 pins on an ATtiny85 with no external components. It's a good addition to anyone's bag of tricks.

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

...suitable for 20 LEDs using 5 pins on an ATtiny85 with no external components. It's a good addition to anyone's bag of tricks.

Joey and all--

We have an app on the drawing board with limited AVR I/O pins available, and need to have about 8 indicator LEDs. If Charlie is correct, then 4 pins give us 12 "channels"?

Would you care to share more of your x5 schematic/code flow? Or can anyone give a link to a usable x4 layout?

I've followed the charlieplexing threads over the years but have never had the situation to use it "in anger" -- until now. ;)

[edit] I want to be able to have any/all indicator LEDs lit at any given time. In your experience can you get away with one resistor per I/O line, or (with like LEDs) must you have resistor-per-LED?

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Or can anyone give a link to a usable x4 layout?

Here is one I found, there is a schematic at the end of the page
http://makezine.com/projects/cha...

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The AVR Dice PCB which was given away at Atmel seminars a few years ago has 35 LEDs being driven from a Tiny 13 in Charliplexing mode. (A0401.3.3000.A)

I have a board here and I think I may have a diagram and maybe some code? Can't remember if I have it though, maybe the Atmel site may have some info.

Edit wow almost 6 years ago! https://www.avrfreaks.net/index.p...

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
[edit] I want to be able to have any/all indicator LEDs lit at any given time.
An N-pin charlieplexing matrix has N * (N-1) LEDs, but can drive N-1 of them at a time. POV takes care of the illusion that they are all being lit at the same time.

Note that some folks write their charlieplex software to drive only 1 LED at a time. This simplifies current balancing issues as discussed below, but also limits the duty cycle to 1 / (N * (N-1)) instead of 1 / N. As above, POV affords the illusion of simultaneous drive.

theusch wrote:
In your experience can you get away with one resistor per I/O line, or (with like LEDs) must you have resistor-per-LED?
Actually, most of the charlieplex projects I've fiddled with had no resistors at all. Very bad, I know. I was basically driving the AVR way out of spec. These were just toys and demos, and I wasn't especially worried about longevity or failures. For the record however they're all still working and they've never failed, even under very extreme voltage and temperature conditions.

However, one resistor per I/O line is the norm.

There are a few different overall circuits that can be used. The minimal circuit has N pins, N resistors, and N * (N-1) LEDs. The placement of the resistors has an effect on the performance of the matrix.

Take this one:

Note that if you drive port 1 as the anode, and ports 2 and 3 as cathodes, each LED that is on (L2 and L6) is driven through 2 resistors, one on the anode and one on the cathode. Moreover, the anode and anode resistor carries the current for all driven LEDs.

Compare against:

Here there are the same number of resistors (1 per I/O line), but only the cathodes of each LED are connected to one. The anodes are directly connected to an I/O line. While all driven LEDs still share the current delivered to their anodes by a single I/O line, that current doesn't flow through a resistor. This has the advantage that, provided you've selected LEDs and resistors that keep currents within the drive capabilities of each I/O pin, the brightness of each driven LED will be (more or less) the same regardless of whether the I/O pin driving the LEDs' anodes is driving 1, 2, 3, or N-1 LEDs. The disadvantage is (potentially) greater complexity in laying out the circuit, depending on the physical placement of the LEDs (matrix, single row, etc).

There are other approaches, like this one:

This has the same advantages w.r.t. drive current, but requires 1 resistor per LED. Layout may be somewhat easier.

Ideally, you select resistors such that the current going through N-1 LEDs is less than the drive strength of 1 I/O line. If you need higher current, you can add transistors to drive the anodes (see the EDN article linked below).

It should be possible to use transistors for both anode and cathodes, so that I/O lines only need to supply enough current to drive the transistor bases. I haven't bothered to work it out. Seems to defeat the purpose of charlieplexing. If I need to add 10 transistors to drive 20 LEDs, seems it would make sense to just use a dedicated LED driver chip like a MAX7219.

Here are some good places to start reading:

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I want to be able to have any/all indicator LEDs lit at any given time. In your experience can you get away with one resistor per I/O line, or (with like LEDs) must you have resistor-per-LED?

Anyone have experience with that?

There is another dice app that I found with Google. Resistor per LED, but needed I'd think as many combinations light more than one LED for that combination.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, JJ. You posted when I was composing. ;)

This is gonna be fun, actually. As we want 8 indicator LEDs there are four combinations left over with four wires and charlieplexing. We want to add one pushbutton switch and use no more wires. So we are sketching out the current paths when the switch is pressed on one of the "unused" combinations.

[Normally we do industrial controllers in modest volumes so the primary design criterion is to be "solid", no surprises, and the last few pennies (or even dollars) don't matter. This one is a consumer device design with wires to this little indicator/pushbutton board. So saving a wire is important.]

Thanks, all.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
This is gonna be fun, actually. As we want 8 indicator LEDs there are four combinations left over with four wires and charlieplexing. We want to add one pushbutton switch and use no more wires. So we are sketching out the current paths when the switch is pressed on one of the "unused" combinations.

[Normally we do industrial controllers in modest volumes so the primary design criterion is to be "solid", no surprises, and the last few pennies (or even dollars) don't matter. This one is a consumer device design with wires to this little indicator/pushbutton board. So saving a wire is important.]

That is interesting...

Charlieplexing can definitely be used for input as well. The second link in my last post includes a brief discussion, and even a cute animation to show the current paths. The Wikipedia entry on charlieplexing also touches on it.

I've not ever considered combining LEDs and switches into one array, but I can't see any reason why you couldn't. Certainly, you'd want to chose output and input nodes to ease coding, but I don't know what the optimal arrangement would be for a given number of output v.s. input nodes. Since scanning the input nodes is done one cathode (i.e. one node) at a time, there should be no concern of ghosting in the output nodes during the scan.

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Since scanning the input nodes is done one cathode (i.e. one node) at a time, there should be no concern of ghosting in the output nodes during the scan.


As there is one unused section of the 4-I/O charlieplexing setup, I intend to use internal pullup instead of a hard output to pull the switch high when strobing it so I don't think there will be much if any phantom LED lighting. As it is a logical on/off switch (or start/stop if you prefer) some minor artifacts may not be a big deal.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
As there is one unused section of the 4-I/O charlieplexing setup, I intend to use internal pullup instead of a hard output to pull the switch high when strobing it so I don't think there will be much if any phantom LED lighting. As it is a logical on/off switch (or start/stop if you prefer) some minor artifacts may not be a big deal.
I think that's the only arrangement that will work, as it's the only one that provides both an input to test and a voltage across the input node. It also limits current through the switch/diode pair.

Note that a node can serve double duty. If you replace the standard diode in the input node with an LED, then you can have a two-stage scanning phase where you first poll the switch with the anode set for input-with-pullup, followed by an output stage with the anode set for output-high. That node would light whenever the switch was closed, acting as a switch indicator. Obviously you don't need to resort to this since you have 3 empty nodes as it is.

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]