# Knight Rider design using Flip Flops

I need to find this for a homework as an introduction to designing with flip flops. It must use only JK, D, T or SR flip flops. All the designs I find, are made with transistors or capacitors, and that's not what I need. I don't really know how to design it myself. But I wonder if this is correct: (Using D flip flops, and a 3 bit counter, although signal is not fed back)

a  b  c    a* b* c*
0  0  0    0  0  1
0  0  1    0  1  0
0  1  0    1  0  0
0  1  1    0  1  0
1  0  0    0  0  1
1  0  1    0  1  0
1  1  0    1  0  0
1  1  1    0  1  0


I need to use some simulator. Which would you recommend? I'm totally new at this =S

EDIT: Forgot to put a youtube example from 0:32 to 0:40 mark

• Using just a 3 bit counter with the table you've shown doesn't remind me of KITT's lights... Do you need one light to go back and forth, or a group of two or three lights ganged together to go back and forth?
– Dave
Commented Jun 4, 2011 at 0:42
• @Dave only one light to go back and forth. Commented Jun 4, 2011 at 0:44
• Your truth table is independent of input a, making the bottom half redundant. Commented Jun 4, 2011 at 14:24
• What are the specified inputs, outputs, and behavior for what you're calling an SR flip-flop? If the output is defined as being ((Q#S) & !R), I think I have a reasonable solution using something around 3N latches for N lights. The three-light case may be a little easier, requiring only four JK flip-flops if they have both inverting and non-inverting outputs, btw. Commented Jun 4, 2011 at 18:27

Given the information you have provided, you will have trouble getting the help you're looking for, because you haven't presented enough evidence that you have tried to solve this problem on your own. Listing a 3 bit counter's output isn't enough, as it just shows you can count in binary. What approaches have you tried? Maybe post a circuit diagram of a failed attempt. If you can't do that, then perhaps a better place to start is to ask a different question, specifically targeting the four types of flip flops that you must use.

I'm not trying to come off as some pedantic internet poster, I just want to make sure you get the help you need while still learning the fundamentals that your course is trying to teach you.

For simulation, I can't really recommend anything off-hand since that is not my area of expertise, but I did download LogicSim and it looks useful. I tested a quick SR circuit and it did the right thing -- just make sure you don't leave anything floating.

Here's a list of other free digital logic simulators.

This is a cool assignment! Have fun with it and post up what you've come up with, and I'm sure you'll get the help you need.

• I did help answer his question about a digital logic simulator, didn't I? ;)
– Dave
Commented Jun 4, 2011 at 14:53
• I definitely agree with you. That's why I added the homework label (sorry I didn't put any more attemps). I know you people won't give a straight answer since I specify it is for a homework (in fact I believe there is some rule in the FAQ). Thanks a lot! you have been very helpful, and your attitude of giving ideas and recommendations instead of solving the problem, is what makes StackExchange a very good place to be reading. +1 (more if I could) for "get the help you need while still learning the fundamentals" Commented Jun 4, 2011 at 22:01

Arrange 16 latches in a 'ring', arrange for them to start out with one active, and then arrange 16 lights in the sequence 1, 16, 2, 15, 3, 14, 4, 13, 5, 12, 6, 11, 7, 10, 9, 8. The effect will be one light bouncing back and forth.

Otherwise, if your goal is to have eight lights going back and forth, with the two end lights being on for twice as long as the others, I'd suggest starting with a ring of 16 flip flops, and then observing that most lights are supposed to turn on and off twice in each set of sixteen transitions. If the JK flip flops have async RS inputs, use the clocked J and K inputs to handle one set of turn-on/turn-off transitions and use the async inputs to handle the other. Simulate the circuit to ensure that delays are properly accounted for.

Edit If you only want three lights, with the active light "high", and if JK flip flops have both normal and inverted outputs, you could build a simple circuit with four JK flip flops. Wire one to toggle every clock. Wire the second to toggle when the first one is off. Wire the third to toggle on once on the cycle following the second going high (you only need one of the signals from the second to do this), and the fourth to toggle on the cycle following the second going low (likewise, using the other signal from the second). The first, third, and fourth flip flops control the lights.

If you have RS flip flops whose behavior is defined to be Q:=(Q#S)&!R, it's possible to do a fully-synchronous version with any number of lights, using about about 2-3 times as many flip-flops as lights. To start with, use a chain of N-1 RS flip flops where the first one has its R set and each of the others has its R connected to the previous Q. Follow this by another similar chain.

Wire the S input of the first flop flop in the first chain to the Q of the last flip flop in the second chain, the second of the first chain to the second-to-last of the second, etc. up to the last in the first chain being hit by the first in the second chain. Wire the S inputs of all the flip flops in the second chain (including the last one) to the Q of the last one. The net visual effect, if one were to wire lights to the first N flip flops, should be that they turn on in order and then turn off in reverse order.

If the flip flops can drive an LED on the high or low side, one could wire LEDs between the each flip flop in the first chain and the next flop flop, so that it would only light when a flip flop was on and its successor was off. Also wire an LED to the first flip flop so it will light whenever that flip flop is off.

If the flop flop outputs cannot be used in that fashion, or one otherwise needs one-hot outputs to drive the LEDs directly, one could use RS flip flops between adjacent pairs of latches to achieve the desired result.

Note that the circuit as described has some "wonky" states, but any state should within 1.5N cycles resolve to a "normal" state. I think the worst-case scenario would be starting with the flip flop just past the middle of the upper and lower halves "on" and the rest "off". Can you see what would happen then?

Incidentally, the real KITT light gear had multiple lights on simultaneously. Can you see how that would be achieved pretty easily? What would you need to do if you wanted to be even more like the show and make it so that the 'leading' light in the pattern was brighter than the rest? For four lights, assume "=" is bright and "-" is less bright:

.-#.
..-#
...#
..#-
.#-.
#-..
#...
-#..


Getting multiple brightness levels would require either adding resistors or PWM'ing the output. Can you see any good logic approaches for that?

The above approach involving coaxing a string of flops to go through the sequence:

0000
1000
1100
1110
1111
1111
1110
1100
1000
0000


is a good one, but it turns out there's a way to do it with only one extra flop. So the above sequence could be generated using five JK flip-flops. The exact implementation is a challenge for the reader, but I'll offer a couple of hints:

1. Divide the flip flops into odd and even positions, and clock them alternately (use the Q and /Q outputs of the "extra" flip flop to generate the clocks for the odd and even groups).
2. Each flop should only be affected by its own state and that of its neighbors (if any).
3. The proper circuit design doesn't require any reset logic; even if it starts in a wonky state it will stabilize to a "normal" one as if by magic. It also, amazingly enough, doesn't even require extra circuit elements for the ends.

I'll leave the actual circuit design as an exercise for the reader, but it really is amazingly elegant. Wiring LEDs between adjacent flops, if permitted, would enable one to handle N lights with only N flip flops. Cool, eh?

Spoiler: The circuit design is HERE. Play around with it. No matter what the initial state of the outputs, the state of the circuit will fall into a proper blinking state. Note also that the top J and bottom K input may be used to stop the circuit at either end of its blink pattern.

• @supercat good idea with the 16 light trick!
– Dave
Commented Jun 4, 2011 at 14:53
• @Dave: Thanks. Next the challenge is to do it without any combined synchronous/asynchronous devices. That seems a bit harder. I have an idea for a fully synchronous design, but can't figure out how to initialize a synchronous one-hot ring. Any ideas? Commented Jun 4, 2011 at 15:13
• @supercat not yet. I've scrapped all of my attempts before even getting going, because I end up using logic that isn't allowed. I've only done basic stuff with flip flops, so this is a bit challenging. It's a cool assignment, but thank goodness it's not mine. :)
– Dave
Commented Jun 4, 2011 at 15:52
• @supercat isn't the new improved answer not as faithful to KITT as the previous light sequence? The new answer looks like a progressbar that goes from 0-100% and 100%-0 again.
– Dave
Commented Jun 5, 2011 at 14:05
• @Dave: If you're using six JK flip-flops, of which five are in the last chain, wire a string of six LEDs in series, with one end of the string tied to VDD via 220-ohm resistor and the other tied to VSS via 220-ohm resistor. Tie each intermediate spot in the string to the output of a JK flip flop via 220-ohm resistor. Actually, only half the resistors are needed, but the design is simplest conceptually with all of them. Commented Jun 5, 2011 at 15:42

Since you have a chain of lights, how about a chain of flops?

Incidentally, when the light reaches the end, should it switch directions, or jump back to the start?

• It's KITT! It has to bounce back and forth. :)
– Dave
Commented Jun 4, 2011 at 1:50
• @Dave - maybe. Makes one obvious implementation a lot harder... can think of one way to do it, but it's ugly. The lack of overt combinatorial logic parts makes me think maybe unidirectional was intended, though there are parts in the collection which can achieve a delayed combinatorial effect. Commented Jun 4, 2011 at 2:02
• good point. I think when he mentioned the binary counter, I figured he could use one and then simply reverse the counter to go the other direction. But perhaps he can't even use one of those!
– Dave
Commented Jun 4, 2011 at 3:58
• @Dave, yes it's unclear about the counter, but even with it he will need combinatorial logic (or a ROM) to decode to one-hot output. Register delayed combinatorial functions can be created with the flops in inventory, but it's going to be inefficient, so I think a one-hot sequencer makes more sense than a binary one. Though such a delayed combinatorial function is the best idea I've had so far for getting from an efficiently implemented unidirectional ring to the appearance of a bidirectional line... Commented Jun 4, 2011 at 5:05

Ok, this is my attempt to do it without a counter, using a shift register instead. Works ok, but the light goes off when reaches again the beginning; I know why that happens, but I don't know how to solve it. I need the input to be injected only one time, and I thought that was when it was all equal to cero. Is there a way to make the first state 1 0 0 0?? I'm allowed to be using combinatorial logic, I'm sorry I didn't specify that. Thanks a lot to those who have answered and thanks in advance for further help! =D

Here is the simulation and the program to be able to open it as recommended by @Dave

• Note: the switch is supposed to be a ground, If I leave the pin alone, it is taken as a 1 Commented Jun 4, 2011 at 21:53
• so you're allowed to use logic gates in your design, not purely flip flops?
– Dave
Commented Jun 4, 2011 at 23:32