Hardware‎ > ‎Writeups‎ > ‎

Decade Counter with 7-Segment Decoder

Back in the day, I purchased a Sparkfun Beginner Parts Kit, which comes with a 7-segment LED.  Recently, I ordered a few more 7-segment LEDs and a few BCD-to-7-segment decoders -- 74HC4543's, to be precise.  When these all arrived, I learned a few Very Important Lessons:
  1. The 1" 7-segment LED from Sparkfun is not the same as the 7mm LEDs I got from Sparkfun.  The former is a breadboard hog, while the latter are so small I'll need to build breakout boards for them.  
  2. 7-segment LEDs come in common anode and common cathode versions.  By luck of the draw, I ended up with all common anode versions.
  3. 7-segment decoders come in LED and LCD varieties.  There are different versions of the LED drivers for common cathode and common anode 7-segment LEDs.  I, of course, ordered the LCD version.
Looking at the datasheets, it seems that the LCD version (the 74HC4543) might have been the best choice.  According to the datasheet, the outputs are rated at +/- 25mA.  I think that means I can use the '4543 on either common anode or common cathode 7-segment LEDs.  Certainly it worked well on my common anode 7-segment.

Decoder with Switches

I started out with something simple.  Four switches and the decoder:

R1 and R2 each allow 16mA into their respective anodes.  Even if we only have one LED lit from a given anode, we won't exceed the 25mA limit from the '4543.

A few things I learned while building this circuit:
  1. Setting a pin high is as simple as connecting it directly to VCC.  Similarly, forcing it low is as simple as connecting it to GND.
  2. The CA 7-segment LED needs to sink current on the A-G pins in order to light the corresponding segment.  The CC 7-segment LED, on the other hand, wants to source current.  With the PH(ase) pin on the '4543 held low, it'll source current.  With PH high, the chip will sink it.  PH must be high for the decoder to work correctly with this CA 7-segment LED.
  3. Datasheets sometimes lie.  The one linked from the Sparkfun page lies, as described in the comments on that page.  The common anodes are on pins 3 and 8, with the segments spread across the remaining pins.

Decoder with Button-Driven Counter

I happened to have a Dual-Decade Counter (74HC390N) lying around, so let's make the display count:

The breadboard image above includes an extra LED on the switch, put in for some now-forgotten reason.  The LED and associated current-limiting resistor do not appear in the schematic.

Counting with the '390 is something of an adventure.  There are two decade counters in the '390.  Each counter is composed of a divide-by-2 section and a divide-by-5 section.  To get it to count to 10, you use the divide-by-2 section as the clock for the divide-by-5 section.  That's why pin 3 (QA) is connected to pin 4 (B) on IC2A.

This is the first circuit where I've had to remember to use a pull-down resistor.  When S1 is open, we need to ensure that IC2A pin A (the divide-by-2 clock) is low.  To do that, we pull that pin low using R3.  When S1 is depressed, R3 is ignored, and IC2A pin A is driven high.

Unfortunately, the switch poses a problem, as you can see in this video:

The problem is that pressing the switch doesn't cause an immediate transition from low to high. Instead, the transition is a noisy one, and leaves the poor counter seeing multiple transitions between low and high.  That's why the counter sometimes jumps when the button is pressed.

Decoder with Debounced Button-Driven Counter

In order to fix the problem we were seeing above, where the counter was jumping by several values with each button press, we need to debounce the switch.  Debouncing is described in much more detail here.  We're going to use the RC debouncing circuit described on page two of that article.  Here's the circuit with the debouncer:

It works much better now.  Each press of the button yields one increment by the counter.  The only disadvantage of the debounced switch is that a sufficiently-rapid series of button presses will now be interpreted as bouncing, and thus as a single press.  I could presumably tune the debouncing circuit a bit more, reducing the margin for error to make it able to respond to button presses.

This circuit departs from the one described in the debouncing article in one respect -- I use two Schmitt-triggered inverters rather than one.  The counter triggers on an up edge.  With the circuit as described in the article, the clock wave would be low when the button was pressed, and high, when it was released.  As a result, the counter would increment only when the button was released.  A second inverter fixes this problem.  The second inverter didn't have to be a Schmitt-triggered inverter.  I was using a 74HC14N, though, which is a hex Schmitt-triggered inverter.  As such, I had Schmitt-triggered inverters to spare, and could use one of the extras as the second inverter in the circuit.

Why didn't I analyzing the debouncing more carefully?  I could've, but I wanted to make it count by itself even more.

Decoder with Timer-Driven Counter

I confess that I went into this circuit without a real understanding of how the 555 timer works, and I'll leave it with almost the same level of ignorance.  I now know how to make a 555 timer generate a square wave -- to act as an astable multivibrator.  I don't know why it works that way, but I know how to calculate the values to get a particular wave.  In this case, I wanted a cycle time of about a second, so I used a 10μF capacitor and two 56KΩ resistors.

I also added a reset button for the counter.

Here's a video of the timer-driven counter:


This was my first real foray into the world of TTL logic.  I think it was a success.  I learned how to use 7-segment decoders, how to interface them with 7-segment LEDs, and the various forms of same.  I also learned how to use counters and debouncers, and dipped my toe into the world of 555 timers.  This will all be a great help when it comes time to start in on the microprocessor.