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.
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.
Live lab: latch vs flip-flop, same feedback
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.
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.
Read the symbol: triangle = edge-triggered; bubble + triangle = falling edge. No triangle = a latch (level-sensitive).
Live lab: inside the master–slave D flip-flop
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.
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.
Method: edges first, then the table (Mano: latch vs flip-flop)
Solution
Predict the answer first. Then reveal one step at a time.
SR, JK, D, T: four flip-flops, four equations
SR
| 00 | Q |
| 01 | 0 |
| 10 | 1 |
| 11 | ? |
JK
| 00 | Q |
| 01 | 0 |
| 10 | 1 |
| 11 | Q̄ |
D
| 0 | 0 |
| 1 | 1 |
T
| 0 | Q |
| 1 | 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.
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.
Live lab: JK and T
| J | K | Q next | |
|---|---|---|---|
| 0 | 0 | Q | hold |
| 0 | 1 | 0 | reset |
| 1 | 0 | 1 | set |
| 1 | 1 | Q̄ | toggle |
Q⁺ = J·Q̄ + K̄·Q
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.
Method: read (J, K) at each rising edge only
Solution
Predict the answer first. Then reveal one step at a time.
Your turn · 1: two T flip-flops make a counter
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.
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.
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.
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.
Your turn · 2: convert
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.
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.
| 74LS74-class D FF (approx.) | |
|---|---|
| tsu | 20 ns |
| th | 5 ns |
| tpcq (max) | 25–40 ns |
| fmax (toggling) | ≈ 25–33 MHz |
Break setup or hold and the flip-flop is back on the hilltop of last class: metastable.
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.
Live lab: enter the forbidden window
Critical thinking · the button that crashes one board in a million
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.
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.
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.
Pop quiz
Question 1 / 5
A positive-edge-triggered D flip-flop changes its output…
Three things to remember
A flip-flop samples at the clock edge (master–slave: two latches never open together). A latch is transparent for the whole level.
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.
Timing: Tclk ≥ tpcq + tlogic + tsu; tccq + tcd ≥ th. Asynchronous inputs: two-flip-flop synchroniser.
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.