Exercise 1.3: Counters
In Exercise 1.2, you learned how to use an IC chip to display numbers on a 7-segment display. Now, we will expand our setup to use our 7-segment display as a counter going from 0 to 9!
The exercises in this course build on each other with increasing levels of difficulty. Take a moment to make sure you have understood everything so far, and refer to the Resources page if you need any help!
INSERT VIDEO OF COUNTER INCREMENTING AS SOMEONE PUSHES THE BUTTON HERE
1) CD4026B
The IC chip we have used so far is the DM74LS48N. However, that chip's functionality is limited to displaying the decimal number that corresponds to a given binary input.
What if we want our setup to count, rather than displaying one number at a time? For this, we will need to use the CD4026B.
CD4026B
Last time, we gave you the pinout of the DM74LS48N chip for you to connect on your breadboard. A crucial step in working with hardware is reading datasheets, so this time, we will teach you to read one on your own!
Take a look at the CD4026B's datasheet.
It seems like a lot, but generally the first few pages of a datasheet will have all of the information you need for basic circuits. For now, we will focus on two main areas of a datasheet.
1. Functionality Overview
As soon as you open the datasheet, you should see a big paragraph of text. This paragraph describes the functionality of the IC chip in English, letting users understand how the IC chip works in theory.
2. Pinout
If you look lower down on the first page, or occasionally somewhere on the first few pages, you should see a pinout diagram of the IC chip that shows what signals the IC chip expects as inputs and what signals it will provide as outputs for proper functionality. To find the pinout diagram, look for a rectangular shape with labeled pins like the one below.
Now that we know how to find the CD4026B chip's pinout, let's go through the connections one at a time and understand what each of them means.
Input Pins: These are pins that allow us to give the IC chip information for it to function. Most ICs will have some input pins that are only needed for advanced functions, and can otherwise be left unconnected.
- VSS: This is a notation that pinout diagrams use for ground, which you are already familiar with. This pin should be connected to our GND rail.
- VDD: This is a notation that pinout diagrams use for the positive terminal. Generally, you should check the datasheet to see what voltage the component is expecting. For this IC, our 5V is fine.
- Clock: This is a common signal for many IC chips. Without a clock, how would the IC know how fast it should change to the next number? The counter increments every time the clock pin recieves a HIGH pulse, meaning our input signal goes from LOW to HIGH. Ignore this pin for now. We will come back to it later in the exercise.
- Clock inhibit: If this pin is connected to 5V, it will freeze the current number on the screen and block the clock signal. Ignore this pin.
- Display enable in: In order for anything to show up on our display, we must enable the display. We do this by connecting this pin to 5V. If this pin was connected to GND, our 7-segment would be empty, even though the chip may still be counting internally.
- Reset: If this pin is connected to 5V, it will reset the counter to 0. Ignore this pin for now. We will come back to it in this module's project.
Output Pins: These are pins that provide information from the IC chip which we can connect to other components. Not all of the output pins may be necessary for every project. We know that they are output pins by understanding the purpose of the chip (providing A-G segments) as well as looking for pins that end in "out".
- A-G: These pins correspond to the A-G segments of the 7-segment LED like we talked about in Exercise 1.2. Each individual pin will go HIGH (5V) whenever that segment should be on to display a specific number, and the pin will be LOW (0V) otherwise.
- Display enable out: This pin copies the value that is at display enable in. This is often used when we have multiple 7-segment LEDs that we are using together, and we want their displays to toggle between on and off in a complex manner at the same time. Ignore this pin.
- Carry out: This pin will go HIGH when the counter reaches 9, and will return to LOW when it rolls back to 0. This functionality can be used to tell another counter when it should increment. Ignore this pin for now. We will come back to it in this module's project.
- Ungated "C" segment out: This pin will correspond to the C segment of the 7-segment LED, but it ignores whether the display is enabled or not. This functionality can be useful for more advanced circuits. Ignore this pin.
2) Displaying Zero
Let's begin by getting the 7-segment LED to display zero.1. With your power OFF, remove your DM74LS48N chip, the DIP switch, and any extra jumper wires.
2. Connect your CD4026B across the center gap of the breadboard, and connect each of the pins as described in the instructions above. If an instruction says to ignore this pin, leave it unconnected.
3. Turn your power ON. At this point, you should see a zero appear on the 7-segment display!
If your 7-segment LED does not light, or does not look like a zero:
- Check your power connections.
- Check each of the IC connections using the multimeter.
- Check that you are connecting each A-G IC pin to the correct pins of the 7-segment LED.
- Make sure you have a 220Ω resistor connected from the GND of the 7-segment LED to your ground rail.
- If your circuit is still not working, try to mentally and physically walk through the circuit. Remember that your path should be a connected loop from the 5V power source -> components -> GND of power source.
3) Counting
Now, it's time to make our circuit count! Our first step is to understand how the display increments in the first place, and then to implement it in hardware.
Clock
The clock functionality is unique in that we need there to be a changing value (from LOW to HIGH) for the IC to register that it needs to increment the value on the display. These are known as pulses.
We can think of the clock as a square wave, where the value alternates between HIGH and LOW.
In module 2, you will look at different types of clocks, such as crystal oscillators, that allow for consistent square waves at a constant rate. For now, we want to control when our display increments, so our goal is just to make transitions occur between LOW and HIGH on the clock pin. We will do this with a button!
Button
A button is a simple component that lets a person control a circuit by pressing it. When the button is pressed, it temporarily connects two points in the circuit, allowing current to flow. When the button is released, the connection is broken, preventing current from flowing.
On the button, we see there are four legs, with two legs of the button on one side and two legs of the button on the other side. Each set of legs that is on the same side is always internally connected.
When the button is pressed, the two sets of pins become internally connected, allowing current to flow between the yellow and pink sides.
1. With your power OFF, connect your button across the center gap of the breadboard. Make sure that the "yellow-colored" legs and "pink-colored" legs from the diagram earlier are on opposite sides of the center gap.
2. Connect one of the legs from one side of the button to 5V, and one of the legs from the other side to the clock pin of the CD4026B.
3. Turn your power ON. At this point, you should see a zero appear on the 7-segment display, and you should be able to increment your counter every time you click the button!
If your 7-segment LED does not increment:
- Check your button's orientation.
- Check what you connected each leg of the button to.
Note: You may see that your counter occasionally skips numbers even though you click the button only once. This behavior is normal, and is known as something called bouncing. We will work to understand and adjust this behavior in module 2!
Final Submission
In this module's project, you'll put together everything you've learned to build a cascading decade counter that lets you count from 0-99.