Close

The 7 segment decoder, done wrong.

rue-mohrRue Mohr wrote 11/01/2023 at 19:56 • 6 min read • Like

Hi,

  I'm Rue Mohr, you might know me from such places as the internet, the information superhighway, or the world wide web.

Today I'd like to tell you about an adventure in optimization of a 7 segment decoder.

(7 segment display with the highly debated hook applied to the digit "7", OOOoooo)

For <lots of> decades people have fought with designing display decoders to take 4 bit BCD and generate 7 segment digits with it. Its not easy, there is a lot of decoding and re-coding involved.

(solution by the worlds greatest logic engineers, immortalized in the 7447 logic chip)

Granted, today we can just use an FPGA, CPLD, PAL, or 48MHz RISCV to perform this 4 bit to 7 segment decoding for us, but, is there a cheaper way?

(Could a way be found to take a few diodes and transistors and produce the coveted 7 segment patterns?)

My proposal was to ditch the BCD input. The particular application I have targeted for this (ok, yes, its a CLOCK...) does not NEED to be sending BCD to the displays. I do want the codes to be 4 bit to reduce wire count (otherwise, just sending the 7 segment patterns directly to the displays is easy enough)

(Super evil BCD bad boooooo, Hissss...)

Is there a 4 bit pattern that could more easily be converted to a 7 segment font than BCD? I decided to put a bounty* on the solution....

Now this puzzle has a few dimensions, there are 2 ways to make a 1, 6, 7, and 9 on a 7 segment display, that means there are 16 different 'fonts' that can be used. Also the choice of which 10 of the 16 4 bit codes to use is completely open.

(* the bounty was nothing, so there wasn't an overwhelming set of answers)

There were a number of answer that came back, one of them seemed unbelievably simple. (Don't get me wrong, I'd been working on a solution myself, but I'm REALLY BAD at this type of puzzle) 

The above equations resolve into only a little bit of circuitry. That became even less when @minusYCore pointed out an optimization I'd missed on the G segment.

Now, I can't prove this is the simplest decoder that can be made for 4 bit to 7 segment, but Its in the right order of magnitude. Part of what makes this tiny is the direct bit-to-segment relation of e and f.

(Only a few components to implement the logic worked out by @amohr)

At this point, the circuit had already been simulated by a few people, and, with quirks, confirmed to kinda work.

But I build them anyhow :]

(The decoder circuit is the top board)

Two small breadboards, the top one for the decoder, and the bottom one for the 4 bit input driver. Everything checked out. The next obvious step is to make a PCB that fits on the back of a 7 segment display, which, seems plausible...

(The "Train wreck" stage of designing a PCB)

Hours of kicad later.. (you don't really notice if go by) a PCB emerged. 

So, the PCB has been ordered, the results will come later. In the meantime its been a great adventure. It even has hack codes (the 6 unused codes cause the logic to do 'other' segment patterns)


I would also like to give mention to work done by (twitter) @poulsfriend, @oric_iss, @likimmo.

 This was another answer, it does resolve down to a bit more circuitry. (but its really close)

But... Why not use a Greenpack? CPLD? FPGA? or RISCV microcontroller?

THIS circuit, is cheaper, its 8 resistors (which you need anyway) and a total of less than 20c in discrete components. (at shipped, hobby volume prices)

It has not been proven to me yet, that you can actually GET (with shipping) a 10c microcontroller FOR 10c. (yes, I know there have been a lot of articles written about this) You tell me the source, and I'll tell you the price they give me (yes, unit price with shipping included)

 Rue M.

Like

Discussions

James Newton wrote 04/03/2024 at 04:02 point

This is cool. I love this sort of thing. You know you can drive up to 12 LEDs with 4 IO pins and nothing more than resistors? Of course, that's only 1 of those 12 at a time, so for multiple segments, you do have to deliver a sequence

http://www.massmind.org/Techref/io/led/12w4pins.htm

  Are you sure? yes | no

Rue Mohr wrote 11/19/2023 at 19:26 point

There is no reply link to some of the comments... Trying to find a way to specifically answer, not finding it. I'm not quite sure where to go with the counter questions, my project is just a programmed value, so it doesn't matter what values they are. binary makes a pretty nifty counter as its just a bunch of /2 stages.

  Are you sure? yes | no

Tim wrote 11/04/2023 at 17:40 point

>It has not been proven to me yet, that you can actually GET (with shipping) a 10c microcontroller FOR 10c. (yes, I know there have been a lot of articles written about this) You tell me the source, and I'll tell you the price they give me (yes, unit price with shipping included)

So the main thing is that you want free shipping then? LCSC will ship for free when you order while a JLCPCB order is in production. Maybe that's the trick...

  Are you sure? yes | no

Rue Mohr wrote 11/05/2023 at 04:11 point

LCSC looks good, but I make things in upper counts of like 9. In that volume, I have not found controllers that actually come out to less than about $2 ea.

I would like to do another round of investigating on this (its been a few years)

  Are you sure? yes | no

Ken Yap wrote 11/05/2023 at 05:03 point

I bought a handful of SOIC-20 STM8s for about 20¢ each but that was pre-pandemic though.

  Are you sure? yes | no

Tim wrote 11/05/2023 at 07:36 point

Well, you can still buy most of the devices from my article, if you are interested in <0.10 devices: https://cpldcpu.wordpress.com/2019/08/12/the-terrible-3-cent-mcu/

There is a nice OSS-Toolchain for Padauk: https://free-pdk.github.io

Unless you really want to go for 8 bit, I would suggest to check out: CH32V003 (RISC-V) and Puya PY32F00X (Cortex M0). They come at ~$0.15-20 in single pieces and $0.08-0.15 in high volume.


  Are you sure? yes | no

leo60228 wrote 11/06/2023 at 22:50 point

I thought LCSC got rid of that deal years ago? If they didn't it would've saved me like $50 over the past few years....

  Are you sure? yes | no

Tim wrote 11/07/2023 at 06:46 point

I just used it last week. You cannot combine PCB and components in the same shipping. But if you have an ongoing order at JLCPCB, you will be offered a $0 shipping option when checking out at LCSC when ordering from the same account.

It's not really advertised anywhere, so it seems to be something that was "grandfathered". Maybe it also only applies to old accounts?

  Are you sure? yes | no

Tim wrote 11/04/2023 at 17:35 point

Nice! Now, what is the simplest BCD to XYZW encoder? :)

  Are you sure? yes | no

Rue Mohr wrote 11/05/2023 at 04:09 point

hah! lets analyze why, and if, you NEED to actually be using BCD on your project. :)

  Are you sure? yes | no

Tim wrote 11/05/2023 at 07:44 point

Ok, let's pose a new challenge then: What is the simplest circuit for a decimal up-counter?

I would guess one could use a 5-stage johnson counter and some logic?

(I went through a similar exercise for this electronic die: https://hackaday.io/project/183938-circuit-golf-electronic-dice-edition/log/203107-005-dice3904-8-minimal-transistor-based-dice)

  Are you sure? yes | no

Sam Ettinger wrote 11/04/2023 at 17:21 point

I can't believe it, I just opened HaD.io to show someone an old 7-seg project of mine, and this is the first thing I see! I am so excited to work on this too!!

  Are you sure? yes | no

Rue Mohr wrote 11/05/2023 at 04:20 point

hahah I read the comment and was like "I'v heard your name before" I'm really bad at names and people generally have to be pretty famous for me to have heard of them ;] When I saw your profile I see why I know of you.

I'm glad I'm not the only one who thought to charlieplex a 7 segment :) Glad to bump into you again!

  Are you sure? yes | no

Ken Yap wrote 11/04/2023 at 00:36 point

Cool, nice to know there are people still interested in solving combinatorial logic puzzles.

  Are you sure? yes | no

Rue Mohr wrote 11/05/2023 at 04:12 point

This is amazing and will open the world to a new era of led 7 segment displays. Tell the world!!! ;]

  Are you sure? yes | no

Ken Yap wrote 11/05/2023 at 04:38 point

How would you get the WXYZ though? Something worth looking into is whether you could minimise the decoding from a 4- bit LFSR counter sequence.

  Are you sure? yes | no