Flip-Flops
Why Study Flip-Flops?
The Basic Information Storage Circuit
A Single Stage Flip-Flop
Making The Circuit Useful
D Flip-Flops
You are at:  Elements - Logic Circuits - Flip-Flops
Return to Table of Contents
Why Study Flip-Flops?

        There are some circuits that are not quite as straight forward as the gate circuits we have discussed in earlier lessons.  However, you still need to learn about circuits that can store and remember information.  They're the kind of circuits that are used in computers to store program information - RAM memory.

    In this lesson we'll look at the background for those kinds of memory circuits.  Our goal is the following.

Given a flip-flop circuit,
Determine how the circuit will behave for a sequence of inputs.
  Be able to use a flip-flop to store a single bit.

Basic Circuit

        Here's a basic circuit that involves just two NAND gates.  There are two inputs to this circuit, X and Y.  Can you generate a truth table for this circuit?

        Let's address that issue of the truth table.  Here is a truth table for you to fill in.  (Print this web page if you want to work on it.)
X
Y
P
Q
0
0
 
 
0
1
 
 
1
0
 
 
1
1
 
 

        Let's review what you know about this circuit.  We can focus on what happens when X= 0, and Y = 0, the first entry in the truth table above.

        Now, let's address the second entry in the truth table.  In that situation, X = 0, and Y = 1.         Now, let's address the second entry in the truth table.  In that situation, X = 0, and Y = 1.         Next, let's address the third entry in the truth table.  In that situation, X = 1, and Y = 0.         Finally, we have the case where X = 1 and Y = 1.         There is one way to proceed.  We could just assume that P = 1, for example.  Let's try that.         This is interesting, but we need to note the following.         What if we made the opposite assumption?  Let's assume P = 0.         Now, we can't have it both ways.  This truth table summarizes what we have found.
 
X
Y
P
Q
0
0
1
1
0
1
1
0
1
0
0
1
1
1
 0
1
1
0

        There's something decidedly peculiar here.  The output has to be one or the other of these two cases.  Which is it?

        But, there's a related question.

        Now, let's imagine that we do the following.
        We can reverse the initial inputs.
        Some observations:         Here's a simulation of the basic flip-flop.  Check out the truth table for the circuit and be sure that you understand how it works.  There will be a question or two after the simulation.
Simulation

        Here is a simulation of a basic flip-flop circuit build using NAND gates.  Experiment with this circuit, checking out the truth table, and be sure to focus on the situation where two different states can exits.  In the simulation, you can change the state of each switch by clicking on the adjacent buttons.


Moving Toward A One-Bit Memory Element - Making the Flip-Flop Useful

        We're going to add some circuitry to our flip-flop to make it more usable.  Here is another simulation with a bit more circuitry.  We'll work toward understanding that circuitry shortly.


Simulation

        Here is a simulation of a more complex flip-flop.  In this flip-flop, do the following.


        If we look at the simulation above, we see that the circuit takes a data input bit and transfers it to the output when the clock goes through a cycle - from 0 to 1 and back to zero.  After the clock pulse becomes zero, then the output is held - i.e. remembered - until another clock pulse comes along and reads the value of A then into the circuit.


Exercise

        Try it again to be sure that you understand it.  Make the data input a 1 and store it, then make the data input a 0 and store it.



        Well, so far we have a one-stage memory storage device.  Next, we're going to duplicate this single stage and have it drive a second stage.  There's a good reason for that.  In this circuit we might end up trying to change the output at the same time we are trying to read the output.  That would never do, so we're going to devise a circuit that will hold the output constant in a second stage while we put the input into the first stage.  However, if we draw all of the components we won't be able to show the whole thing.  So, we going to encapsulate the entire circuit above with just the data input, the clock input and the top output showing.  Note, we only need to have one output available since the two outputs of the flip-flop are always complements.

        You should also be aware that engineers really like to be able to use higher order abstractions for devices.  The logic gates (NAND gates in the flip-flop) are really composed of transistors, and the flip-flops are really composed of gates.  But, you can't always work at the transistor level when you are constructing circuits with gates, and you, similarly, can't always work at the gate level when you are constructing circuits with flip-flops.

Now, working with the simpler representataion, experiment with it to be sure that you understand how it works, and in particular be sure that you can see that this device stores a single bit.


Exercise

Now, at this level of abstraction, we can check out the operation of the single stage flip-flop.  Run this simulation and notice how the output changes on the leading edge of the clock pulse, C.

        There's a problem with this memory element.  If this element is embedded in a system in which you want to read new information into the memory element at the same time as you are reading information from the element, those two things are happening at the same time.  A more desirable situation would be to have a circuit in which the output was guaranteed to stay constant while the input is being loaded.  A two-stage memory element is used for that.  Here is a simulation.  In this simulation, note the following.


Exercise



The D Flip-Flop - A One-Bit Memory Element

        The combination of two flip-flops constitutes a D-type flip-flop.  That's D because the output of the flip-flop is delayed by the time of one clock pulse.  Check it out.  Set a value for the data and pulse the clock ON and OFF.  You'll find a copy of the data appearing at the output on the trailing edge of the clock pulse.  Now, if we consider the combination of two flip-flops (in the simulation above) as a unit, we have a D flip-flop.  It's called a D flip-flop because it delays the signal.  The signal appears at the output of the circuit delayed by the time of one clock pulse.  Here's another simulation to demonstrate that.  The "blue box" (We don't always use the traditional "black box".) is the D flip-flop.


Simulation - D (Delay) Flip-Flop

        In this simulation, the data input appears at the output of the circuit one clock cycle later.  You can cycle the clock "manually".



The Toggle (T) Flip-Flop

        A D flip-flop can be converted to a toggle (T) flip-flop by connecting the output to the input, inverting the output as it is fed back.  That's shown in the simulation below.  Again, you can put a clock pulse into the circuit.


Simulation - T (Toggle)  Flip-Flop

        In this simulation, the D flip-flop is transformed into a toggle flip-flop using inverted feedback around the D flip-flop.


Question

Q1   If you go through four clock cycles (i.e. the clock goes from zero to one and back to zero - that's one cycle), how many cycles does the output of the toggle flip-flop go through?


        The toggle flip-flop is a frequency divider when you use it as it was used in the simulation above.  If the clock runs 100 times a second, the output of the toggle will be a pulse that runs 50 times a second, so the frequency of the toggle output is half of the frequency of the toggle input.

        Now, consider a "What if?" question.  Here's the question.  What if you take two toggle flip-flops and put the output of one into the input of the other.  The next simulation will let you explore that.


Simulation

        Here is the simulation for two T (Toggle) flip-flops with the output of the first one being the input to the second one.


Questions

        Using the simulation above with two T flip-flops, determine the answers to the following questions.  In answering these question, interpret the LED indicators on the flip-flops as a two-bit digital number.  The most significant bit (MSB) is the one on the right.  The LSB is the one on the leftClick here to get the simulator in a separate window.

Q2   When the simulation loads, what number is pre-loaded into the system?

Q3   After one clock cycle (clock becomes one, then becomes zero again, i.e. two mouse clicks), what number is present?


        Flip-flops are interesting circuits, and it is important that you understand them.  The best way to get to really know them is to use them in the lab.  You may have done that before you took this lesson depending on your instructor.  However, the lab is worthwhile whenever you do it.  There is a link below in the link to Logic Laboratories.
Problems

Links to Other Lessons on Digital Logic Send your comments on these lessons.