This weekend’s electronics project with my son was to build a 4bit counter using JK flip-flops. Before implementing the circuit in hardware, I first explained the binary system and we then designed the counter using the free Circuit Simulator which I described in a previous post. Interestingly, he was amazed by the fact that adding just one more bit doubles the size of the counter – exponential growth is not intuitive ;-). The counter circuit, which chains together the flip-flops can be seen below: 

4bit Counter Using JK Flip-Flops

One important feature of the design is that we tie both J and K to +5v which turns the JK flip-flop into a T or Toggle flip-flop. Below is the code for the circuit. Copy and import the code into Circuit Simulator to get a better feeling of how the counter works – just press the switch to activate the next “tick” of the counter. 

$ 1 5.0E-6 10.20027730826997 50 5.0 50
162 496 272 496 208 1 2.1024259 1.0 0.0 0.0
g 320 208 320 176 0
w 320 208 496 208 0
r 496 272 496 352 0 330.0
r 544 272 544 352 0 330.0
162 544 272 544 208 1 2.1024259 1.0 0.0 0.0
r 592 272 592 352 0 330.0
162 592 272 592 208 1 2.1024259 1.0 0.0 0.0
r 640 272 640 352 0 330.0
162 640 272 640 208 1 2.1024259 1.0 0.0 0.0
w 496 208 544 208 0
w 544 208 592 208 0
w 592 208 640 208 0
156 368 464 432 464 0 5.0
R 288 432 256 432 0 0 40.0 5.0 0.0 0.0 0.5
w 288 432 288 464 0
w 288 464 368 464 0
w 288 464 288 528 0
w 288 528 368 528 0
s 288 432 352 432 0 1 true
w 368 496 352 496 0
w 352 496 352 432 0
156 528 464 560 464 0 0.0
w 528 464 512 464 0
w 512 464 512 528 0
w 512 528 528 528 0
w 512 528 512 576 0
w 512 576 288 576 0
w 288 576 288 528 0
w 464 464 480 464 0
w 480 496 528 496 0
w 640 352 640 416 0
w 640 416 464 416 0
w 624 464 624 384 0
w 624 384 624 352 0
w 624 352 592 352 0
156 704 464 736 464 0 5.0
w 512 576 672 576 0
w 688 528 688 576 0
w 672 576 688 576 0
w 688 528 704 528 0
w 704 464 688 464 0
w 688 464 688 528 0
w 624 464 640 464 0
w 640 464 640 496 0
w 640 496 704 496 0
w 800 464 800 368 0
w 800 368 544 368 0
w 544 368 544 352 0
156 864 464 896 464 0 5.0
w 688 576 864 576 0
w 864 576 864 528 0
w 864 528 848 528 0
w 848 528 848 480 0
w 848 480 848 464 0
w 848 464 864 464 0
w 800 464 816 464 0
w 816 464 816 496 0
w 816 496 864 496 0
w 496 352 496 384 0
w 496 384 960 384 0
w 960 464 960 384 0
w 464 416 464 464 0
w 480 464 480 496 0

The next step was to build the circuit using real JK flip-flops. We used dual HEF 4027BP JK flip-flops from NXP Semiconductors, 4 LEDs, 4 330 ohm resistors, a 10k resistor and a push button. Please note that these flip-flops are triggered on the rising edge and therefore, we chained them together via NOT Q and used Q to power the LEDs. As we used a push button to activate the clock on the first flip-flop, we pulled the clock pin down to 0v using a 10k resistor connected to ground. One last detail is that the Set and Reset pins for each flip-flop are connected to 0v. Below is the finished result built by Luke. 

4bit Counter