LearnGates

The D flip-flop: memory that follows a clock

A D flip-flop stores one bit, but only at a precise moment: when the clock signal CLK goes from 0 to 1 (the rising edge). At that instant Q copies D. The rest of the time Q holds its value, whatever D does.

Step by step

The order matters here: the checker sets the inputs one row at a time, top to bottom, and the outputs must match each row.

Step by step: D flip-flop
StepDCLKQ
100–
2010
3110
4100
5111
6011
7001
8010

Latch or flip-flop?

A D latch is simpler: while its enable input is 1 it lets D straight through to Q, and when enable goes to 0 it holds. The problem is that while enable is 1, every change of D reaches Q. A flip-flop reacts to one instant only, which is what makes a whole processor change state in step, once per clock tick.

How it works

Put two latches in a row: a master and a slave. The master is open while CLK is 0 and follows D. The slave is open while CLK is 1 and shows what the master holds. When the clock rises, the master closes on the last value of D and the slave passes exactly that value to Q. At no moment are both open, so D can never run straight through.

The table below is a sequence: the checker changes D and CLK row by row. An “x” means the value doesn’t matter yet, because nothing has been stored.

Hints and solution

Try on your own first. Each hint gives away a little more.

  1. A D latch copies D while its enable is 1. That is not enough: Q would change whenever D does while CLK is 1.
  2. Use two latches in a row (master and slave).
  3. The master is enabled while CLK is 0, the slave while CLK is 1.