Home
7Sequential Logic: Latches & Flip-Flops
7

Topic 7 of 13

Sequential Logic: Latches & Flip-Flops

Memory for digital circuits: clocks, latches, flip-flops and the timing rules they obey.

← → move between slides · F full screen · M slide list

Before we start

Why this matters

Why does your laptop instantly forget your unsaved essay the moment the power blinks, but remember it perfectly the millisecond before?

Because one bit of memory is really just two logic gates locked in a petty, endless argument, each one only holding its position because the other hasn't backed down yet. Cut the power and the argument — and your essay — is over. This chapter is about how a circuit can stubbornly “remember” anything at all, no sticky notes required.

Concept 1 of 6

Clocks and synchronous circuits

A sequential circuit stores state, so its output depends on inputs and history. A clock is a periodic square wave with a period T, frequency f = 1/T, rising and falling edges and a duty cycle. In a synchronous circuit all state changes are coordinated by the clock, which makes timing predictable and design easier. In an asynchronous circuit, state can change as soon as an input changes.

Concept 2 of 6

Latches

A latch is level-sensitive: its output can change while its enable is active. An SR latch is two cross-coupled NOR gates. S = 1 sets Q to 1, R = 1 resets it to 0, and S = R = 0 holds. S = R = 1 is invalid for the NOR version, because both outputs go to 0 and the result is unpredictable when the inputs are released. A gated latch adds an enable. A D latch uses one data input, D, which removes the invalid state: while enabled, Q follows D.

Interactive circuit

SR latch from two NOR gates

Click the switches to change the inputs and watch the LEDs. Use “Show truth table” when it appears.

Concept 3 of 6

Flip-flops

A flip-flop is edge-triggered: it samples its inputs only at a clock edge (rising or falling), so it changes state at one precise moment.

TypeBehaviour
DQ(next) = D
JK00 hold, 01 reset, 10 set, 11 toggle
TT = 0 hold, T = 1 toggle
SR00 hold, 01 reset, 10 set, 11 invalid

A level-triggered JK with J = K = 1 would keep toggling while the clock is high (race-around). A master-slave JK, built from two latches on opposite clock phases, avoids this.

Interactive circuit

D flip-flop

Click the switches to change the inputs and watch the LEDs. Use “Show truth table” when it appears.

Interactive circuit

JK flip-flop

Click the switches to change the inputs and watch the LEDs. Use “Show truth table” when it appears.

Interactive circuit

JK flip-flop (cont.)

Interactive circuit

Divide-by-2 (D flip-flop, Q′ to D)

Click the switches to change the inputs and watch the LEDs. Use “Show truth table” when it appears.

Concept 4 of 6

Master-slave JK flip-flop

A master-slave JK flip-flop chains two clocked SR latches so the circuit changes state only once per clock cycle, even when J = K = 1. The master latch is enabled while the clock is high and follows J and K; the slave latch is enabled while the clock is low (its clock input is the inverted clock) and simply copies whatever the master is holding. Because the master and slave are never active at the same time, the master's new output can't loop back through the slave and re-trigger itself — this is what removes the race-around problem of a plain level-triggered JK.

ClockMasterSlave / output Q
1 (high)Active — follows J, KIsolated — holds (memory)
0 (low)Isolated — holds (memory)Active — copies the master

With J = K = 1: while the clock is high, the master toggles once to its new value and then sits still for the rest of the high phase, since it cannot see its own new output until the next clock cycle. When the clock falls, the slave copies that single new value through to Q. Net result: exactly one toggle per clock cycle.

Concept 5 of 6

Characteristic and excitation tables

D: Q+ = D
JK: Q+ = J·Q′ + K′·Q
T: Q+ = T ⊕ Q
SR: Q+ = S + R′·Q (with SR = 0)
Q → Q+DTJ KS R
0 → 0000 X0 X
0 → 1111 X1 0
1 → 001X 10 1
1 → 110X 0X 0

The characteristic table gives the next state from the inputs (used for analysis). The excitation table gives the inputs needed for a wanted transition (used for design).

Concept 6 of 6

Timing

  • Setup time: data must be stable this long before the clock edge.
  • Hold time: data must stay stable this long after the edge.
  • Propagation delay: time for a gate output to respond to an input.
  • Clock-to-Q delay: time from the clock edge until Q changes.

Breaking setup or hold time can store the wrong value or leave the flip-flop in an in-between state.

Concept 6 of 6

Timing (cont.)

ClockDQsetupclk-to-Q
D changes and settles well before the rising clock edge (its setup window), so the flip-flop samples a stable value; Q itself only changes a short clk-to-Q delay after that edge, never instantly.

Truth tables

Truth tables (1 of 2)

SR latch (NOR)

SRQ next
00Q (hold)
010
101
11invalid

D flip-flop

DQ next
00
11

JK flip-flop (characteristic)

QJKQ next
0000
0010
0101
0111
1001
1010
1101
1110

Truth tables

Truth tables (2 of 2)

T flip-flop

QTQ next
000
011
101
110

Excitation table

QQ nextDTJKSR
00000X0X
01111X10
1001X101
1110X0X0

Interactive

Demo: flip-flop timing simulator

Worked example 1 of 3

Worked example 1

A JK flip-flop has Q = 1. What is Q+ for J = 0, K = 1? For J = K = 1?
Show the solution
  1. J = 0, K = 1 resets: Q+ = 0.
  2. J = K = 1 toggles: Q+ = 0 (from 1).

Worked example 2 of 3

Worked example 2

What T input takes a T flip-flop from Q = 0 to Q+ = 1?
Show the solution
  1. T = Q ⊕ Q+ = 0 ⊕ 1 = 1.

Worked example 3 of 3

Worked example 3

A clock has a period of 20 ns. What is its frequency?
Show the solution
  1. f = 1/T = 1 / 20 ns = 50 MHz.

Practice

Practice (1 of 2)

Try each one on paper first, then check your answer.

1. Explain the difference between a latch and a flip-flop.
Show the answer
A latch is level-sensitive: it follows its inputs while enabled. A flip-flop is edge-triggered: it samples inputs only at a clock edge.
2. Draw an SR latch.
Show the answer
Two NOR gates. The output of each feeds one input of the other. The free inputs are R (for Q) and S (for Q′).
3. Explain D flip-flop operation.
Show the answer
At the active clock edge, Q takes the value of D. Between edges Q holds.

Practice

Practice (2 of 2)

Try each one on paper first, then check your answer.

4. Compare JK and T flip-flops.
Show the answer
A T flip-flop is a JK with J and K tied together. T = 0 holds, T = 1 toggles.
5. Explain rising-edge triggering.
Show the answer
The flip-flop looks at its inputs only at the instant the clock goes from 0 to 1 and ignores changes at other times.
Practice in Gate Forge

Open the SR latch example, then build a D latch and a JK flip-flop and study the Timing diagram.

Open Gate ForgeGate ForgeA free circuit simulator — place and wire gates, generate truth tables and timing diagrams, and work through 90+ guided problems.

Check yourself

Quiz

Summary

Summary

  • Latches are level-sensitive. Flip-flops are edge-triggered.
  • JK: 00 hold, 01 reset, 10 set, 11 toggle. T: toggle when T = 1. D: Q+ = D.
  • Characteristic tables are for analysis, excitation tables are for design.
  • Respect setup and hold time around the clock edge.
  • f = 1/T.