JK flip-flop counter
Two JK flip-flops in a 74HC112 toggle on each falling clock edge and count 0 to 3 in binary on two LEDs. There is no microcontroller in it: the simulator solves the 6 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.
Intermediate About 15 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $5.80. On Mokxi they're free.
What you'll learn
- JK flip-flops and toggling with J and K high
- Negative-edge triggering
- Chaining flip-flops to divide a clock by two
- Counting in binary with LEDs
- Difficulty: Intermediate
- Time: About 15 minutes
- Parts: 8
How it works
A 74HC112 holds two JK flip-flops. Both have J and K tied high, so each one toggles, flipping its output, on every active clock edge. This chip reacts when its clock falls from high to low.
The clock feeds the first flip-flop. Its output Q drives an LED and also feeds the clock of the second flip-flop. The first one toggles on every clock fall, so it runs at half the clock speed. The second toggles each time the first goes from 1 to 0.
Read the two red LEDs together as a binary number: 0, 1, 2, 3, then back to 0. The set and reset pins are all tied to 5 V, so they stay inactive.
Parts list
8 parts, plus the jumper wires. They retail for about $5.80; on Mokxi they're free.
- 1 × Full-size breadboard
- 1 × Power, 5 V
- 1 × ClockIn Logic Lab Kit.
- 1 × 74HC112 dual JK flip-flop
- 2 × Resistor, 330 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 2 × 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 |
|---|---|
| 74HC112 dual JK flip-flop pin 1K | 5 V |
| 74HC112 dual JK flip-flop pin 1J | 5 V |
| 74HC112 dual JK flip-flop pin 1SD | 5 V |
| 74HC112 dual JK flip-flop pin 2SD | 5 V |
| 74HC112 dual JK flip-flop pin 2J | 5 V |
| 74HC112 dual JK flip-flop pin 2K | 5 V |
| 74HC112 dual JK flip-flop pin 2RD | 5 V |
| 74HC112 dual JK flip-flop pin 1RD | 5 V |
| 74HC112 dual JK flip-flop pin VCC | 5 V |
| 74HC112 dual JK flip-flop pin GND | Ground |
| LED, red (1) pin C | Ground |
| LED, red (2) pin C | Ground |
| 74HC112 dual JK flip-flop pin 1CP | Clock pin OUT |
| 74HC112 dual JK flip-flop pin 2CP | 74HC112 dual JK flip-flop pin 1Q |
| Resistor, 330 Ω (1) pin 1 | 74HC112 dual JK flip-flop pin 1Q |
| Resistor, 330 Ω (2) pin 1 | 74HC112 dual JK flip-flop pin 2Q |
| LED, red (1) pin A | Resistor, 330 Ω (1) pin 2 |
| LED, red (2) pin A | Resistor, 330 Ω (2) 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.
// A 2-bit counter from two JK flip-flops (a 74HC112).
//
// J = K = 1 makes a JK flip-flop toggle on every active clock edge. The
// 74HC112 is negative-edge triggered: it moves when its clock falls from
// high to low.
//
// clock -> FF1 (the 1s LED) -> FF2 (the 2s LED)
//
// FF1 toggles on every falling clock edge, so it runs at half the clock.
// Its Q is FF2's clock, so FF2 toggles every time FF1 goes from 1 to 0:
// the two LEDs count 0, 1, 2, 3 and round again.
//
// Try it: move J or K of the second flip-flop (pins 11 and 12) to ground.
// J = 0, K = 1 clears it on every edge; J = 1, K = 0 sets it; both 0 hold.
// Pins 4 and 10 (SD) and 15 and 14 (RD) are the asynchronous set and reset,
// active low: ground one and the flip-flop jumps without waiting for a clock.
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The LEDs do not count. This project
Check that the clock output goes to 1CP and that 1Q goes to 2CP. - An LED sticks on or off. This project
The set and reset pins (1SD, 2SD, 1RD, 2RD) must be tied to 5 V. Grounding one forces its flip-flop. - The count order looks backward. This project
The first LED is the 1s bit and the second is the 2s bit. - 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 flip-flop outputs random states at power up. 74HC112 dual JK flip-flop
Set and reset (SET and CLR) are active low. Tie them high when unused, or pulse one low once to define the starting state. - It toggles at the wrong moment. 74HC112 dual JK flip-flop
The clock triggers on the falling edge. Tie J and K high to toggle each clock. Add a 0.1 uF decoupling capacitor near the supply pins. - 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.