Driving 9 leds with only 5 logic lines - Page 1
Forum section: electronics / projects

author: manganin
author_rank: Regular Contributor
timestamp: January 14, 2023, 04:57:40 pm
content: Visiting a friend who is re-designing an old ham radio device.The display is a selector type, so only one led needs to be on at a time. 9 leds but only 5 microcontroller logic outputs available.There is no space for any additional circuitry, except resistors for the led current limiting.The outputs are simple logic, 0 or 1 only, not tri-state.With 6 outputs it would be easy in 3x3 configuration.Two engineers and more than two beers, but still nothing...Any ideas?

author: CatalinaWOW
author_rank: Super Contributor
timestamp: January 14, 2023, 05:10:46 pm
content: Rather than putting all the beer and brain cells into the logic problem I would attack the space problem.You apparently have space for nine wires and nine current limiting resistors, plus five signal lines and whatever controller is generating the five logic signals. It seems possible that there is some way to accommodate the decoding logic. One part of the solution might be to use LEDs with internal current limiting.Does the MCU have a DAC output? Replacing the five logic signal wires with an analog pair coupled with a bar graph decoder chip might be a direction to look for the solution.

author: inse
author_rank: Super Contributor
timestamp: January 14, 2023, 05:12:50 pm
content: When it’s microcontroller controlled, why is logic state ‚input‘ or ‚tri-state‘ not possible?Then you could implement ‚Charlieplexing‘.@CatalinaWOW: shift register or CD4017 would be even easier…

author: manganin
author_rank: Regular Contributor
timestamp: January 14, 2023, 05:32:43 pm
content: The number of control lines is actually limited by the free pins of an existing connector. And for the same reason there is no +5V available either.Not enough space on the display PCB for anything but the leds and 4 resistors. The very old micro doesn't support tri-state.

author: CatalinaWOW
author_rank: Super Contributor
timestamp: January 14, 2023, 05:34:29 pm
content: Quote from: inse on January 14, 2023, 05:12:50 pmAgree, depending on how much space the cabling is consuming. The real point of my post was to try to open up the design space.

author: themadhippy
author_rank: Super Contributor
timestamp: January 14, 2023, 05:41:27 pm
content: can you squeeze a CD4028 in anywhere?

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 14, 2023, 06:02:09 pm
content: Any mcu can set its pins as inputs (Hi-Z) and do this with only 4 pins (Could control up to 12 leds).

author: AndersJ
author_rank: Frequent Contributor
timestamp: January 14, 2023, 06:30:32 pm
content: Use a 4 to 16 line decoder.

author: m98
author_rank: Frequent Contributor
timestamp: January 14, 2023, 08:44:44 pm
content: Can't you just name which MCU you are using? Other than that, you could use addressable LEDs like the APA102, where timing is not so critical and you can just bitbang the communication.

author: Nusa
author_rank: Super Contributor
timestamp: January 14, 2023, 09:04:10 pm
content: Quote from: AndersJ on January 14, 2023, 06:30:32 pmOr a shift register. A 74595 will take a serial input and buffer 8 output pins. You can dead-bug it wherever you have space, or on top of something.If you truly only have one LED on at a time, you only need ONE resistor for all the LED's connected to a common rail.

author: manganin
author_rank: Regular Contributor
timestamp: January 14, 2023, 09:56:33 pm
content: Thanks for all the ideas.The radio is so beautiful inside that we want to keep it original. So all kind of dead bug modifications are out of question.There are 9 filter settings and even 9 leds on the display board, but only 5 of them in use due to the pin limitation of the filtered connector.Quote from: inse on January 14, 2023, 05:12:50 pmQuote from: m98 on January 14, 2023, 08:44:44 pmI think it is the good old Z80 or some of the clones. The person who wrote the code is still with us, the electronic designer unfortunately not.The actual restriction seems to be that the outputs have been buffered.One alternative could be to use modern low current leds and bypass the buffers, which allows to set the MCU outputs to inputs or whatever the trick is to make them high-Z. If in sockets, that would be an easy way to allow the use of the simple multiplexing scheme.

author: Ian.M
author_rank: Super Contributor
timestamp: January 14, 2023, 10:16:46 pm
content: Z80 is a CPU not a MCU - it doesn't have ports. If it *is* using a Z80 rather than any of the much later MCUs that used a Z80 core, odds are either there's a Z80 PIO or similar in there, which only permits direction to be set for a whole port, not individual lines, or the output 'buffers' are actually latches, latching a byte off the data bus. All solutions that rely on tristate outputs (e.g. charlieplexing) are thus off the table.If you can sneak four small signal N-MOSFETs and three diodes in somewhere on the display side of the five pin connector, you can drive a 3x3 matrix. The MOSFETs could be dual ones and the diodes in a triple package, so you'd only need to find space for three 2mm square footprints. See attached LTspice sim.

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 14, 2023, 10:21:17 pm
content: Then I would use a serial register, like a 74595 or some more modern stuff allowing setting each pin direction.

author: Nusa
author_rank: Super Contributor
timestamp: January 14, 2023, 10:40:00 pm
content: I was about to say something similar to what Ian said...there is no GPIO on a Z80, it's all about the peripheral chips being used.Sounds like you have to choose between function and beauty here. Unless you put the effort into making the hack beautiful as well. Are any of the chips socketed? Then making a daughterboard to add more functionality may be an option.

author: Nominal Animal
author_rank: Super Contributor
timestamp: January 15, 2023, 12:48:38 am
content: SixEight LEDs is the best you can do with five signals that each is either high or low (no high-Z).You do need some additional components or logic to be able to light just one of the nine LEDs.There are twenty ordered pairs among five pins: 1-2 (B), 1-3 (C), 1-4 (D), 1-5 (E), 2-1 (F), 2-3 (H), 2-4 (I), 2-5 (J), 3-1 (K), 3-2 (L), 3-4 (N), 3-5 (O), 4-1 (P), 4-2 (Q), 4-3 (R), 4-5 (T), 5-1 (U), 5-2 (V), 5-3 (W), 5-4 (X).The five pins have 32 possible states (since each pin can only be hi/1 or lo/0, not high-Z):0 00000 ----- ----- ----- -----1 00001 BCDE- ----- ----- -----2 00010 ----F HIJ-- ----- -----3 00011 -CDE- HIJ-- ----- -----4 00100 ----- ---KL NO--- -----5 00101 B-DE- ----L NO--- -----6 00110 ----F -IJK- NO--- -----7 00111 --DE- -IJ-- NO--- -----8 01000 ----- ----- --PQR T----9 01001 BC-E- ----- ---QR T----10 01010 ----F H-J-- --P-R T----11 01011 -C-E- H-J-- ----R T----12 01100 ----- ---KL -OPQ- T----13 01101 B--E- ----L -O-Q- T----14 01110 ----F --JK- -OP-- T----15 01111 ---E- --J-- -O--- T----16 10000 ----- ----- ----- -UVWX17 10001 BCD-- ----- ----- --VWX18 10010 ----F HI--- ----- -U-WX19 10011 -CD-- HI--- ----- ---WX20 10100 ----- ---KL N---- -UV-X21 10101 B-D-- ----L N---- --V-X22 10110 ----F -I-K- N---- -U--X23 10111 --D-- -I--- N---- ----X24 11000 ----- ----- --PQR -UVW-25 11001 BC--- ----- ---QR --VW-26 11010 ----F H---- --P-R -U-W-27 11011 -C--- H---- ----R ---W-28 11100 ----- ---KL --PQ- -UV--29 11101 B---- ----L ---Q- --V--30 11110 ----F ---K- --P-- -U---31 11111 ----- ----- ----- -----There are 167960 ways to choose 9 of the 20 possible (BCDEFHIJKLNPQRTUVWX). I wrote a program to find the choice that checks them all, but none of them yields more than68 individual LEDs, as noted by Ian.M below.

author: Andy Watson
author_rank: Super Contributor
timestamp: January 15, 2023, 01:22:46 am
content: Here's an idea, but there are caveatsIt relies on the forward-voltage of the LEDs being greater than half the supply voltage. If this is not the case, there needs to be some additional voltage-dropping mechanism added - probablly in-line with the two row selects.Having just checked this with several LEDs that were to-hand, it would appear that even white LEDs glow a litte at 2.5V. It works ok if 0.6-1V can be "lost" from the supply voltage of 5V.

author: Ian.M
author_rank: Super Contributor
timestamp: January 15, 2023, 01:52:54 am
content: Quote from: Nominal Animal on January 15, 2023, 12:48:38 amYou are mistaken. Its trivial to light one of eight LEDs from five output only pins, only two resistors and no other active components. See attached sim "5 pin 8 LEDs.asc".Unfortunately I cant think of any good way to extend it to add a 9th LED without more output pins.However if you accept a few uA leakage current through some of the supposedly off LEDs, and can settle for blue or white LEDs with 3V Vf (and Vf >> Vcc/2 is *ESSENTIAL*), here's a solution that can handle *TEN* LEDs, one on at a time, with only five resistors, and no other active parts. It does rely on the CMOS outputs drooping a bit under load to give it a bit more margin, and isn't energy efficient. See attached sim "5 pin 10 LEDs.asc".

author: CatalinaWOW
author_rank: Super Contributor
timestamp: January 15, 2023, 02:57:29 am
content: So now you have a trade to make. Beauty and originality vs function vs effort. If you can only select and activate 8 of the 9 existing filters you are still 4 ahead of the original design. Or if you want to really put a lot of effort into it, de-solder the Z80 or whatever it is and replace it with a daughterboard on a forty pin frame. You can put a lot on that form factor these days, and then pot it to look like the original part. If you are really dastardly you can even copy the original markings. To make this work you might also have to make similar daughtercards for any PIOs and buffers involved. It will take some real skull sweat to make it work with the existing interconnect wires and requires re-writing the software, but it seems likely that it could be done.

author: Nominal Animal
author_rank: Super Contributor
timestamp: January 15, 2023, 04:31:06 am
content: Quote from: Ian.M on January 15, 2023, 01:52:54 amSo I was; thanks for catching my error.You see, your 8-led arrangement is simplyD1 = B, D2 = H, D3 = N, D4 = T, D5 = F, D6 = L, D7 = R, D8 = X:which yields the following possible states (fourth column lists the single-LED states):0 00000 --------1 00001 B------- D12 00010 -FH-----3 00011 --H----- D24 00100 ---LN---5 00101 B--LN---6 00110 -F--N---7 00111 ----N--- D38 01000 -----RT-9 01001 B----RT-10 01010 -FH--RT-11 01011 --H--RT-12 01100 ---L--T-13 01101 B--L--T-14 01110 -F----T-15 01111 ------T- D416 10000 -------X D817 10001 B------X18 10010 -FH----X19 10011 --H----X20 10100 ---LN--X21 10101 B--LN--X22 10110 -F--N--X23 10111 ----N--X24 11000 -----R-- D725 11001 B----R--26 11010 -FH--R--27 11011 --H--R--28 11100 ---L---- D629 11101 B--L----30 11110 -F------ D531 11111 --------(Interestingly, the valid binary states of the five signal lines corresponding to a single LED being lit with that scheme are 0b00001, 0b00011, 0b00111, 0b01111, 0b11110, 0b11100, 0b11000, and 0b10000.)It is obvious that the erroriswas in my program that checked the combinations. Here is the fixed C program, that outputs the possible LED wirings that allows at least 8 LEDs.Code:#include <stdlib.h>#include <stdint.h>#include <stdio.h>static const uint32_t codemap = {0x00000, 0x0000F, 0x000F0, 0x000EE, 0x00F00, 0x00E0D, 0x00DD0, 0x00CCC,0x0F000, 0x0E00B, 0x0D0B0, 0x0C0AA, 0x0BB00, 0x0AA09, 0x09990, 0x08888,0xF0000, 0xE0007, 0xD0070, 0xC0066, 0xB0700, 0xA0605, 0x90550, 0x80444,0x77000, 0x66003, 0x55030, 0x44022, 0x33300, 0x22201, 0x11110, 0x00000,};static const struct {const uint32_t mask;const char name;} order = {{ .name = "1-2", .mask = 1<<0 }, { .name = "2-1", .mask = 1<<4 },{ .name = "1-3", .mask = 1<<1 }, { .name = "3-1", .mask = 1<<8 },{ .name = "1-4", .mask = 1<<2 }, { .name = "4-1", .mask = 1<<12 },{ .name = "1-5", .mask = 1<<3 }, { .name = "5-1", .mask = 1<<16 },{ .name = "2-3", .mask = 1<<5 }, { .name = "3-2", .mask = 1<<9 },{ .name = "2-4", .mask = 1<<6 }, { .name = "4-2", .mask = 1<<13 },{ .name = "2-5", .mask = 1<<7 }, { .name = "5-2", .mask = 1<<17 },{ .name = "3-4", .mask = 1<<10 }, { .name = "4-3", .mask = 1<<14 },{ .name = "3-5", .mask = 1<<11 }, { .name = "5-3", .mask = 1<<18 },{ .name = "4-5", .mask = 1<<15 }, { .name = "5-4", .mask = 1<<19 },};int main(void){for (unsigned int keep = 0; keep < 1<<20; keep++) {unsigned int leds = __builtin_popcount(keep);if (leds < 6)continue;uint32_t solo_mask = 0;unsigned int solo_count = 0;for (unsigned int i = 0; i < 32; i++) {uint32_t mask = codemap & keep;if (__builtin_popcount(mask) == 1 && !(solo_mask & mask)) {solo_mask |= mask;solo_count++;}}if (solo_count >= 8) {printf("%u ", solo_count);for (unsigned int i = 0; i < 20; i++)if (solo_mask & order.mask)printf(" %s", order.name);printf("\n");}}return EXIT_SUCCESS;}Thecodemap[]array encodes the same information as in myreply #14, with bit 0 corresponding to LED connected to 1-2, bit 4 to 2-1, and so on, up to bit 19 corresponding to LED connected to 5-4. Theorder[]array names them in the preferred output order.keepis the bit mask corresponding to the set of LEDs used.It only finds (the permutations of) Ian.M's scheme for 8 LEDs. (To list the solutions for fewer LEDs, edit(solo_count >= 8)test to suit.)

author: Nominal Animal
author_rank: Super Contributor
timestamp: January 15, 2023, 10:33:08 am
content: If you could derive a sixth voltage using first two signals, near the LEDs, so that1 26L L L/hi-ZL H L/hi-ZH L HH H L/hi-Z(a MOSFET, perhaps?), then I believe you could use all nine LEDs:None at (L)LLLLL = 0D1 only at (L)LLHLL = 4 (2-3)D2 only at (L)LHLLL = 8 (2-4)D3 only at (H)LHHHL = 14 (5-6)D4 only at (L)LHHHH = 15 (5-1)D5 only at (L)HLLLL = 16 (2-5)D6 only at (H)HLHHL = 22 (4-6)D7 only at (L)HLHHH = 23 (4-1)D8 only at (H)HHLHL = 26 (3-6)D9 only at (L)HHLHH = 27 (3-1)I didn't check how you'd wire the resistors, though.A solution also exists forp6 = p1 AND p2(the above beingp6 = (NOT p1) AND p2).

author: Ian.M
author_rank: Super Contributor
timestamp: January 15, 2023, 12:27:51 pm
content: Here's my active 10 LED circuit, derived from the passive version "5 pin 10 LEDs.asc" above. It adds five dual series Schottky diodes to derive + and - rails from the signals, which it also averages through 100K resistors to get gate drive for a non-inverting discrete MOSFET buffer (which could be replaced with a single gate Schmidt buffer).It also removes the restriction on LED color as their common is now actively driven so the unwanted forward voltage that could have caused a faint glow in four of the off state LEDs is now reduced to under 400mV resulting in fractional uA leakage currents.However due to the high component count it would be just plain *DUMB* to use this circuit vs the nine LED "5 pin 3x3 matrix.asc" I posted in reply #11 above, or vs 'm98's suggestion of APA102 addressable LEDs, or vs the several suggestions to use a shift register (or a SPI LED driver), which would eliminate all the extra parts except one IC and possibly one resistor. If its essential to use one-hot/one-cold encoding (e.g. due to lack of program memory to bit-bang SPI-like protocols), the common line could be driven by a 74HC280 9 bit parity generator, powered via its input pins!

author: robert.rozee
author_rank: Frequent Contributor
timestamp: January 15, 2023, 01:57:42 pm
content: do i need to explain?cheers,rob :-)

author: manganin
author_rank: Regular Contributor
timestamp: January 15, 2023, 06:33:29 pm
content: Quote from: robert.rozee on January 15, 2023, 01:57:42 pmI think we have a winner. No need to modify the digital board.Of course we can argue if there are 5 or 6 controls lines, but the display connector has a ground pin, so it doesn't matter.

author: Ian.M
author_rank: Super Contributor
timestamp: January 15, 2023, 07:46:47 pm
content: If you don't tell us about details like an available ground pin, expect crappy or no solutions!I expect that if the drivers are bipolar TTL or old CMOS with high output resistance you are going to be disappointed with the results of Robert's circuit as VOLof the drivers is unlikely to be low enough when sinking the LED current, to get acceptable brightness discrimination between the On LED in either of the first two columns, and the supposedly Off LED in the same row of the third column.If so, here's a simplified version of the 3x3 matrix I posted earlier, that uses two N-MOSFETs to switch Gnd to the third column when the outputs driving the other two columns are both high. One dual MOSFET can do the job in a 2mm square footprint (+ three current limiting resistors for the rows).

author: robert.rozee
author_rank: Frequent Contributor
timestamp: January 15, 2023, 10:57:10 pm
content: Quote from: Ian.M on January 15, 2023, 07:46:47 pmif VOLis an issue, either:1. add a second diode in series with D10, or,2. buffer data4 and data5 lines with a driver transistor (BC107) on each at the mainboard end and in software invert the signals.btw, if there is any noticeable brightness difference between D1-D6 and D7-D9 (slightly dimmer) adding a piece of frosted tape as a diffuser to D1 to D6 is a simple solution. and if D7 to D9 slightly glow when they should be off, add 3x high value resistors across them - 10k to 100k should suffice. this is just to ensure D10 maintains a 0.6v drop. a single resistor from the top of D10 to +5v would also work. but i doubt this will be needed.cheers,rob :-)

author: Ian.M
author_rank: Super Contributor
timestamp: January 16, 2023, 02:13:31 am
content: Your idea is quite clever, and in its basic form has elegant simplicity. It can certainly be made to work, and will probably work better with low Vf LEDs as the third column extra diode drop will be a greater proportion of the LED Vf.However by the time you've added all those extra parts to guarantee it will work well with bipolar TTL driving it, you might as well either swap in 74HCT drivers to get reasonably strong rail-to-rail outputs, or as I did in the sim "5 pin & gnd 3x3 matrix.asc" above, simply gate the third column to ground when the first two column drives are high, using MOSFETs for minimal voltage drop. If the third column's VOLis then too low, it may be brighter, but that can be fixed with a single resistor in series with the upper MOSFET drain, to approximately match the VOLof the logic driving the other two columns.

author: robert.rozee
author_rank: Frequent Contributor
timestamp: January 16, 2023, 02:27:41 am
content: Quote from: Ian.M on January 16, 2023, 02:13:31 ammy understanding is that the original equipment has 5x LEDs fitted, with space for 4 more... or are all 9 already fitted? either way, a good approach would be to fit modern high-brightness LEDs in all 9 places. these can produce good illumination with well under 1mA. in one application i ended up using 10k series resistors from 3v3 to drive some blue SMD LEDs, so an IFdown at the 100uA level. even then, the LEDs were close to being too bright.manganin: is the plan to replace the display PCB, or simply rework the existing one?Ian.M: space permitting, i like your 2 MOSFET designcheers,rob :-)

author: manganin
author_rank: Regular Contributor
timestamp: January 17, 2023, 02:01:05 pm
content: Quote from: Ian.M on January 14, 2023, 10:16:46 pmI didn't even remember that the Z80 system comes in multiple chips... The 'buffer' that I mentioned refers to actual logic inverters placed after the Z80-PIO to isolate the power hungry 1980s leds. Also blocking the tri-state use.Quote from: robert.rozee on January 16, 2023, 02:27:41 amAll nine leds are already there. And the traces from the connector to the leds nicely go through some extra pads (in a pin header layout) which allows cross connections without ruining the PCB.The (modern) green leds that I have give good illumination from as low as 0.2mA and there is no remarkable visual effect in the 0.2 to 0.5mA range. The change in the led current with and without the diode will be meaningless.The led turn-on voltage seems to be quite sharp, so a single diode drop should keep the rest of the leds dark.Even the old leds could work just fine, I will try that first.

author: Ian.M
author_rank: Super Contributor
timestamp: January 17, 2023, 05:56:02 pm
content: If you've got both traces to each LED (or they are already a 3x3 matrix) at the unused header footprint, then yes that sounds viable. Keeping the current low will minimise the VOLconcerns, green LEDs have a low enough Vf that the extra Vf from a silicon diode has a good chances of giving acceptable off state leakage current, and as only one LED will be on at a time minor brightness mismatch wont be noticeable. The other benefit is you should have everything you need in stock.However if you do run into issues, you could easily 'dead bug' a small dual MOSFET next to the header footprint. Apart from one short wire on the MOSFET itself to link the pair drain to source, its only two extra connections vs patching in a diode.