Combinational circuits forget their inputs the moment they change. A computer must also remember data, and the basic element that stores one bit is the flip-flop. It keeps its output until a clock pulse allows it to change.

The Bistable Idea

A flip-flop is a circuit with two stable states that stores one bit. It has the outputs Q and Q', where Q' is always the opposite of Q. The inputs decide the next state, and a clock input controls when the change happens. In an edge-triggered flip-flop the state changes only at the rising or falling edge of the clock.

Definition: Flip-flop. A bistable sequential circuit that stores one bit of information and changes state only when permitted by a clock signal.

SR Flip-Flop

The SR flip-flop has a set input S and a reset input R. S = 1 with R = 0 sets Q to 1. S = 0 with R = 1 resets Q to 0. With S = R = 0 the state does not change. The combination S = R = 1 is not allowed, because both outputs would be forced to the same value and the next state would be unpredictable.

Table 2.9: Truth table of the SR flip-flop

S R Next state Q(t+1) Action
0 0 Q(t) No change
0 1 0 Reset
1 0 1 Set
1 1 Not allowed Invalid

The characteristic equation of the SR flip-flop is Q(t+1) = S + R'·Q, with the condition S·R = 0.

D Flip-Flop

The D flip-flop removes the invalid state by using a single data input D. At each clock edge the output takes the value of D, so Q(t+1) = D. It is built from an SR flip-flop with R = S'. Because it simply copies D, it is used in registers and as a one-clock delay.

Table 2.10: Comparison of SR and D flip-flops

Property SR flip-flop D flip-flop
Inputs S and R D
Invalid input S = R = 1 None
Characteristic equation Q+ = S + R'Q Q+ = D
Main use Basic memory element Registers, delays

Example 2.5: Following the state of a D flip-flop

Problem: A D flip-flop starts at Q = 0. The data inputs on four successive clock edges are 1, 1, 0, 1. Find Q after each edge.

Solution:

  1. Edge 1: D = 1, so Q becomes 1.
  2. Edge 2: D = 1, so Q stays 1.
  3. Edge 3: D = 0, so Q becomes 0.
  4. Edge 4: D = 1, so Q becomes 1.

Result: The sequence of Q is 1, 1, 0, 1. The output follows D, one clock edge later.

q = 0
for s, r in [(1, 0), (0, 0), (0, 1), (0, 0)]:
    q = 1 if s else (0 if r else q)
    print("S", s, "R", r, "Q", q)

Output

S 1 R 0 Q 1
S 0 R 0 Q 1
S 0 R 1 Q 0
S 0 R 0 Q 0

Common mistakes

  • Applying S = 1 and R = 1 to an SR flip-flop.
  • Expecting a flip-flop to change state without a clock edge.
  • Confusing Q with Q'. They always have opposite values.

Key takeaways

  • A flip-flop stores one bit and has outputs Q and Q'.
  • SR: Q+ = S + R'Q with the restriction S·R = 0.
  • D: Q+ = D, the output copies the input at the clock edge.
  • The clock decides when the state may change.

Practice questions

  1. What is the invalid input of an SR flip-flop?
  2. Write the characteristic equation of a D flip-flop.
  3. What does a flip-flop store?

Answers to the practice questions

  1. S = 1 and R = 1.
  2. Q(t+1) = D.
  3. One bit of information.

Sources

  • Official BCA syllabus Computer Architecture, course code 25BCA401DS02, Unit II