CSE 2317 W4 · Class 2 Flip-flops: edge-triggered memory
Sakeef Sani ↗ ↓ PDF

CSE 2317Week 4Class 2Sunday · 11:00 AM – 12:20 PM80 min

Flip-flops: edge-triggered memory

A latch listens for as long as the clock is high. A flip-flop listens for one instant: the edge. That difference is what makes counters, registers and processors possible.

S present · L lecturer notes · → next step · F full screen · P presenter window
01 Cold open 0–4 min

The counter that counts wrong

Take last class's D latch, connect Q̄ back to D, and clock it. It should toggle once per clock: a divide-by-two, the first stage of every counter.

Instead, while the clock is high the new Q̄ races round the loop to D, through the transparent latch, back to Q̄… It toggles again and again, as many times as fit in the pulse.

Think deeper

How many times does the latch toggle in one clock pulse? What does it depend on?

Argue it in pairs for two minutes. There may be more than one defensible answer.

02 Live lab 4–8 min

Live lab: latch vs flip-flop, same feedback

Flip-flops: change only at the clock edge The dashed lines mark rising clock edges. A latch follows its input for the whole time the clock is high; a flip-flop looks only at the edge.
D latch (EN = CLK)DQQ̄EN0D flip-flop (rising edge)DQQ̄0CLKQ̄ fed back to D: should toggle once per clock
Clock edges6
Latch toggles24

While CLK is high the latch is transparent: its new Q̄ reaches D after one delay and it toggles again, and again. How many times depends on the pulse width: useless as a counter.

CLKQ latchQ flip-flop
03 Concept 8–13 min

Master–slave: two latches that never open together

  • Two D latches in series. The master is enabled by CLK̄, the slave by CLK.
  • CLK = 0: master open (follows D), slave closed (holds Q). CLK = 1: master closed (holds what D was), slave open (shows it).
  • At no moment is there an open path from D to Q. The value that gets through is the one D had at the 0 → 1 edge: a positive-edge-triggered D flip-flop.
Q+=D(at the active clock edge)Q^{+} = D \quad\text{(at the active clock edge)}
DQQ̄rising edgeDQQ̄falling edge
Pro tip

Read the symbol: triangle = edge-triggered; bubble + triangle = falling edge. No triangle = a latch (level-sensitive).

04 Live lab 13–18 min

Live lab: inside the master–slave D flip-flop

Flip-flops: change only at the clock edge The dashed lines mark rising clock edges. A latch follows its input for the whole time the clock is high; a flip-flop looks only at the edge.
master · openslave · closedQ = 1DQENDQEN1CLKmaster sees CLK̄D1

Q⁺ = D (sampled at the rising edge)

CLK = 0: master follows D, slave holds. CLK = 1: master holds, slave shows it. Toggle D while CLK is high and compare the two Q rows.

CLKDmasterQ (FF)Q latch
05 Worked example 18–24 min

Worked example: same D, latch vs flip-flop

Given

CLK and D as shown. A D latch (enabled by CLK = 1) and a positive-edge D flip-flop both start with Q = 0. Delays neglected.

Find

Q of the latch and Q of the flip-flop for all 16 slots.

12345678910111213141516CLKDQ latch?Q FF?

Method: edges first, then the table (Mano: latch vs flip-flop)

Solution

Predict the answer first. Then reveal one step at a time.

06 Concept 24–29 min

SR, JK, D, T: four flip-flops, four equations

SR

00Q
010
101
11?
Q+=S+RˉQQ^{+} = S + \bar{R}Q

JK

00Q
010
101
11Q̄
Q+=JQˉ+KˉQQ^{+} = J\bar{Q} + \bar{K}Q

D

00
11
Q+=DQ^{+} = D

T

0Q
1Q̄
Q+=T⊕QQ^{+} = T \oplus Q

Characteristic tables (inputs → next state). The JK fixes SR's forbidden row by making it toggle; the T is a JK with J = K = T; the D is the simplest and the one used inside almost every chip.

Pro tip

The JK toggle row is only safe because the flip-flop is edge-triggered. A JK latch with J = K = 1 races around exactly like the opening demo.

07 Live lab 29–33 min

Live lab: JK and T

Flip-flops: change only at the clock edge The dashed lines mark rising clock edges. A latch follows its input for the whole time the clock is high; a flip-flop looks only at the edge.
JKJ1K1CLKQQ̄10JK flip-flop · positive edge
JKQ next
00Qhold
010reset
101set
11Q̄toggle

Q⁺ = J·Q̄ + K̄·Q

CLKJKQ
08 Worked example 33–38 min

Worked example: a JK timing diagram

Given

A positive-edge JK flip-flop, initially Q = 0. J and K change only while CLK is low (well away from the edges).

Find

Q for all 16 slots.

12345678910111213141516CLKJKQ?

Method: read (J, K) at each rising edge only

Solution

Predict the answer first. Then reveal one step at a time.

09 Your turn 38–43 min

Your turn · 1: two T flip-flops make a counter

04:00
1 Exam CQ

Two negative-edge T flip-flops, both with T = 1, start at 0. CLK (10 MHz) drives the first; the first's output Q0 is the clock of the second.

12345678910111213141516CLK

Draw Q0 and Q1. What do Q1Q0 do as a 2-bit number? What are their frequencies?

Work it out first.
Press Solve when the class has an answer.

10 Worked example 43–48 min

Worked example: a JK flip-flop from a D flip-flop

Given

A positive-edge D flip-flop (Q⁺ = D) and any gates you need.

Find

Logic that makes it behave as a JK flip-flop.

JQ̄K̄QDQQ̄CLK

Method: feed D with the target's characteristic equation (Mano, flip-flop conversion)

Solution

Predict the answer first. Then reveal one step at a time.

11 Your turn 48–51 min

Your turn · 2: convert

03:00
2 Exam CQ

Using any gates, convert: (a) a D flip-flop into a T flip-flop; (b) a JK into a D; (c) a JK into a T.

Work it out first.
Press Solve when the class has an answer.

12 Concept 51–55 min

Timing rules: setup, hold, clock-to-Q

  • Setup time tsu: D must be stable this long before the edge.
  • Hold time th: D must stay stable this long after the edge.
  • Clock-to-Q tpcq (max) / tccq (min): how long after the edge Q changes.
setup: Tclk≥tpcq+tpd, logic+tsuhold: tccq+tcd, logic≥th\text{setup: } T_{clk} \ge t_{pcq} + t_{pd,\,logic} + t_{su}\qquad \text{hold: } t_{ccq} + t_{cd,\,logic} \ge t_h
74LS74-class D FF (approx.)
tsu20 ns
th5 ns
tpcq (max)25–40 ns
fmax (toggling)≈ 25–33 MHz
Gotcha

Break setup or hold and the flip-flop is back on the hilltop of last class: metastable.

13 Worked example 55–59 min

Worked example: how fast can it run?

Given

Flip-flop A drives two gates in series, which drive flip-flop B (same clock). Flip-flops: tpcq = 25 ns, tccq = 3 ns, tsu = 20 ns, th = 5 ns. Gates: tpd = 15 ns max, tcd = 3 ns min; the shortest path has one gate.

Find

The maximum clock frequency, and whether the hold time is met.

Method: setup and hold constraints (two-flip-flop path)

Solution

Predict the answer first. Then reveal one step at a time.

14 Live lab 59–64 min

Live lab: enter the forbidden window

Setup and hold: the forbidden window Slide the moment D changes. Outside the shaded window the flip-flop is predictable. Inside it, the output hangs halfway, for longer the closer you get to the balance point.
tsuthCLKDQ-4 ns-2 ns0 ns2 ns4 ns6 ns8 ns10 nsnext edge: 2nd flip-flop samples Q
Flip-flop 1captured the NEW value (1)
2nd flip-flop (synchroniser)clean
15 Think deeper 64–68 min

Critical thinking · the button that crashes one board in a million

★ Critical thinking

A button, a sensor or another chip's signal is asynchronous: it can change at any moment, including inside the setup–hold window.

Take τ = 0.2 ns, T0 = 0.1 ns, fclk = 100 MHz and an input that changes 10⁶ times a second. Estimate the mean time between failures if the logic reads the flip-flop (a) 1 ns after the edge, (b) after a second flip-flop, ≈ 8 ns later.

Work it out first.
Press Solve when the class has an answer.

16 Real world 68–72 min

Real world: counting heartbeats

A heart-rate meter: an R-peak detector (comparator on the ECG) produces one pulse per beat, ≈ 80 ms wide. A counter of flip-flops counts the pulses during a gate window; the processor reads the count.

  • Edge-triggered, so each beat counts once however long the pulse lasts. A latch-based counter would race through several states during each 80 ms pulse.
  • Synchronised: the heartbeat has nothing to do with the 1 MHz clock, so the pulse first passes a two-flip-flop synchroniser, then an edge detector (Q₁ · Q̄₂) makes a one-clock-wide count enable.
BME corner

Bedside monitors, Holter recorders and smartwatches all do this, in hardware or firmware. A miscounted beat is not a cosmetic bug: arrhythmia detection depends on exact R–R intervals.

17 Pop quiz 72–76 min

Pop quiz

Score 0

Question 1 / 5

A positive-edge-triggered D flip-flop changes its output…

18 Recap 76–80 min

Three things to remember

01

A flip-flop samples at the clock edge (master–slave: two latches never open together). A latch is transparent for the whole level.

02

Q⁺: SR = S + R̄Q, JK = JQ̄ + K̄Q, D = D, T = T ⊕ Q. Convert by feeding the source's inputs from the target's equation.

03

Timing: Tclk ≥ tpcq + tlogic + tsu; tccq + tcd ≥ th. Asynchronous inputs: two-flip-flop synchroniser.

HW Before next class

Flip-flops: tpcq = 12 ns, tccq = 4 ns, tsu = 6 ns, th = 3 ns. Between two of them: a longest path of 3 gates (8 ns each, max) and a shortest path of 1 gate (2 ns min).

(a) fmax? (b) Is hold met? (c) Is hold met for a direct flip-flop-to-flip-flop wire (a shift register)?

Class Test 1: next class (Week 5, Class 1), 20 minutes, Weeks 1–4. Assignment 1 is due at the start of the same class.

Work it out first.
Press Solve when the class has an answer.