Counters and Seven-Segment Displays: the short answer
A counter is a chain of flip-flops that adds one to its stored number on every clock pulse. A 4-bit binary counter counts 0 to 15 and then rolls over to 0. Example: Each digit is a fixed pattern of seven bits. Decoder chips like the CD4511 store these patterns so you do not have to.
- Level
- Beginner
- Time
- About 6 min
- Topic
- Digital logic
Build a counter from a clock signal and show its count on a seven-segment display using decoder and counter chips.
Before this: Logic Gates and Truth Tables, Flip-Flops, Debouncing and Counters
A counter is a chain of flip-flops that adds one to its stored number on every clock pulse. A 4-bit binary counter counts 0 to 15 and then rolls over to 0. A decade counter counts 0 to 9 and then rolls over, which is what you want for showing digits. The clock can come from a 555 timer, a push button (with debouncing) or a microcontroller pin.
A seven-segment display has seven LED bars labelled a to g plus a decimal point. In a common-cathode display all the cathodes join to ground and each segment lights when its anode is driven high through a resistor; in a common-anode display it is the other way round. Showing the digit 7 means lighting segments a, b and c. Each segment needs its own current-limiting resistor (about 330 Ω to 1 kΩ at 5 V).
Two classic CMOS chips make this easy without any code. The CD4026 is a decade counter with built-in seven-segment outputs: feed it clock pulses and it drives a common-cathode display directly. The CD4511 takes a 4-bit binary-coded decimal (BCD) number and decodes it into segment signals, so it pairs with a counter such as the 74HC390 or with a microcontroller. Cascading is simple: the carry-out of one decade counter clocks the next, giving units, tens and hundreds.
One segment at a time
A seven-segment digit is seven LEDs, plus a decimal point, arranged so that different combinations show 0 to 9. In a common-cathode display all the cathodes are joined to ground and you drive each segment high to light it; in a common-anode display the anodes go to the supply and you pull segments low. Check which type you have before wiring, or every segment will be backwards.
Each segment needs its own resistor of a few hundred ohms, or one per digit if only one segment is lit at a time, and each pin supplies only a few milliamps.
Several digits with few pins
A decoder chip such as the 7447 or 4511 turns four bits into the right segments. For more digits, multiplex: connect the same segments to all digits, and switch on one digit at a time, faster than the eye can notice, around a hundred times per second or more. With a shift register or a driver chip such as the MAX7219, a few pins control many digits.
In multiplexing, each digit is lit for only part of the time, so use a slightly lower resistor, but stay within the current limit of the chip and the LEDs.
Counting
A counter chip or a microcontroller increments a number and a lookup table converts each digit to a segment pattern. Buttons need debouncing, and leading zeros can be blanked. A counter that exceeds the number of digits should show an overflow, not a wrong number.
- Mixing up common-cathode and common-anode and getting inverted patterns.
- Leaving out the resistors on the segments.
- Multiplexing too slowly and seeing flicker.
Which segments light for each digit?
- The segments are a (top), b (top right), c (bottom right), d (bottom), e (bottom left), f (top left), g (middle).
- 1 = b, c. 4 = b, c, f, g. 7 = a, b, c.
- 8 lights all seven segments; 0 lights all except g.
- On a common-cathode display, a lit segment needs its pin driven HIGH through its resistor.
Result. Each digit is a fixed pattern of seven bits. Decoder chips like the CD4511 store these patterns so you do not have to.
Build a 555 astable at about 1 Hz feeding a CD4026 that drives a common-cathode seven-segment display through 470 Ω resistors. Then add a second CD4026 clocked by the first one's carry-out to count to 99.
3 quick questions
A decade counter is at 9. What happens on the next clock pulse?
On a common-cathode display, how do you light a segment?
What does a CD4511 do?
