Up/down counter
A slide switch and a 74HC02 steer a clock into a 74HC193, which counts up or down in binary on four LEDs. There is no microcontroller in it: the simulator solves the 14 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.
Teaching? Assign it to your class in one click.
Advanced About 40 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $6.85. On Mokxi they're free.
What you'll learn
- A binary counter and how LEDs show its value
- Up and down clock inputs on a 74HC193
- Building an OR gate from NOR gates
- Steering a clock with a switch instead of rewiring
- Difficulty: Advanced
- Time: About 40 minutes
- Parts: 16
How it works
A clock ticks once a second. The 74HC193 has two clock inputs: CPU counts up and CPD counts down. The input not in use must be held high.
The slide switch pulls one of two lines low through the 74HC02's NOR gates. They work as two OR gates: CPU is the clock OR the first line, and CPD is the clock OR the second. The low line lets the clock through, and the high line holds the other input high.
The four red LEDs show the count in binary, with Q3 on the left and Q0 on the right. The count wraps from 15 to 0 going up, and from 0 to 15 going down.
Parts list
16 parts, plus the jumper wires. They retail for about $6.85; on Mokxi they're free.
- 1 × Full-size breadboard
- 1 × Power, 5 V
- 1 × ClockIn Logic Lab Kit.
- 1 × Slide switchIn Logic Lab Kit, Spaceship Panel Kit.
- 2 × Resistor, 10k ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × 74HC02 quad NOR
- 1 × 74HC193 up/down counter
- 4 × Resistor, 330 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 4 × LED, redIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Resistor, 10k Ω (1) pin 2 | 5 V |
| Resistor, 10k Ω (2) pin 2 | 5 V |
| 74HC02 quad NOR pin VCC | 5 V |
| 74HC193 up/down counter pin PL | 5 V |
| 74HC193 up/down counter pin VCC | 5 V |
| Slide switch pin 2 | Ground |
| 74HC02 quad NOR pin 2B | Ground |
| 74HC02 quad NOR pin GND | Ground |
| 74HC02 quad NOR pin 4B | Ground |
| 74HC193 up/down counter pin GND | Ground |
| 74HC193 up/down counter pin MR | Ground |
| LED, red (1) pin C | Ground |
| LED, red (2) pin C | Ground |
| LED, red (3) pin C | Ground |
| LED, red (4) pin C | Ground |
| 74HC02 quad NOR pin 1A | Clock pin OUT |
| 74HC02 quad NOR pin 3A | Clock pin OUT |
| Resistor, 10k Ω (1) pin 1 | Slide switch pin 1 |
| 74HC02 quad NOR pin 1B | Slide switch pin 1 |
| Resistor, 10k Ω (2) pin 1 | Slide switch pin 3 |
| 74HC02 quad NOR pin 3B | Slide switch pin 3 |
| 74HC02 quad NOR pin 2A | 74HC02 quad NOR pin 1Y |
| 74HC193 up/down counter pin CPU | 74HC02 quad NOR pin 2Y |
| 74HC02 quad NOR pin 4A | 74HC02 quad NOR pin 3Y |
| 74HC193 up/down counter pin CPD | 74HC02 quad NOR pin 4Y |
| Resistor, 330 Ω (3) pin 1 | 74HC193 up/down counter pin Q1 |
| Resistor, 330 Ω (4) pin 1 | 74HC193 up/down counter pin Q0 |
| Resistor, 330 Ω (2) pin 1 | 74HC193 up/down counter pin Q2 |
| Resistor, 330 Ω (1) pin 1 | 74HC193 up/down counter pin Q3 |
| LED, red (1) pin A | Resistor, 330 Ω (1) pin 2 |
| LED, red (2) pin A | Resistor, 330 Ω (2) pin 2 |
| LED, red (3) pin A | Resistor, 330 Ω (3) pin 2 |
| LED, red (4) pin A | Resistor, 330 Ω (4) pin 2 |
The notes that come with it
There is no microcontroller in this one, so nothing is compiled: the simulator solves the circuit itself. The file in the editor is the notes that come with it.
// An up/down counter: a 74HC193, steered by a 74HC02.
//
// The four LEDs are the count in binary, Q3 on the left and Q0 on the right,
// stepping once a second.
//
// Click the slide switch to change direction. The 193 has two clock inputs,
// CPU (count up) and CPD (count down), and the one not in use must be held
// high. The 74HC02's four NOR gates make two OR gates:
//
// CPU = clock OR UP_N CPD = clock OR DOWN_N
//
// The switch pulls either UP_N or DOWN_N low. The low one lets the clock
// through to its input; the high one holds the other input high. So the
// switch picks the direction without ever touching a clock wire.
//
// Count up past 15 and it rolls over to 0; count down past 0 and it rolls
// over to 15. TCU and TCD, the carry and borrow, go low for half a clock at
// those points; wire them to a second 193's CPU and CPD for an 8-bit counter.
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The counter does not move This project
Check PL goes to 5 V and MR to ground, then check that the clock output reaches the NOR gates. - It counts the wrong way for the switch position This project
Swap which switch side feeds the two NOR gates, or just flip the switch. - It counts erratically This project
Check the unused clock input is held high. The gate wiring does this, so check CPU on 2Y and CPD on 4Y. - The circuit does not behave as expected at the set frequency. Clock
Pick a frequency slow enough to watch, such as 1 Hz, when learning. Fast clocks look like steady signals. Make sure the clock output and your circuit share a ground. - A counter or flip-flop skips steps. Clock
Check that the clock edge matches the chip, rising or falling. Slow, clean edges are best. Do not connect a mechanical switch as a clock without debouncing it. - The input reads random values in one position. Slide switch
A switch only connects or disconnects. Add a pull-up or pull-down resistor, or use INPUT_PULLUP, so the pin has a defined level when the switch is open. - The load never turns on when the switch is flipped. Slide switch
Use the center (common) leg and one outer leg. The unused outer leg goes nowhere. Check that the switch is in series with the load. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.