Loading lessons...
Latches, Flip-Flops & Triggering
Latches, Flip-Flops & Triggering
The circuits of Unit I are combinational: their outputs depend only on the present inputs. Real systems also need memory.
A sequential circuit is combinational logic plus storage elements, so its outputs depend on the present inputs and on the stored state. This lesson builds the two kinds of 1-bit storage element: the latch (level sensitive) and the flip-flop (edge triggered).
Combinational circuit versus sequential circuit
1. Synchronous and Asynchronous Sequential Circuits
| Type | State changes | Storage elements | Example |
|---|---|---|---|
| Synchronous | only at discrete instants set by a clock | clocked flip-flops | counters, registers, CPUs |
| Asynchronous | whenever an input changes | latches or gate delays | handshake circuits, simple latches |
Almost every design in this course is synchronous: one clock signal goes to every flip-flop, and the whole circuit moves from one state to the next on each clock edge.
2. The SR Latch
A latch is two cross-coupled gates. Each gate's output feeds the other gate's input, so the pair can hold either of two stable states, Q = 1 (set) or Q = 0 (reset).
SR latch with NOR gates and S'R' latch with NAND gates
NOR SR latch (active-high inputs):
| S | R | Q (next) | Action |
|---|---|---|---|
| 0 | 0 | Q | hold (no change) |
| 0 | 1 | 0 | reset |
| 1 | 0 | 1 | set |
| 1 | 1 | 0, and Q' = 0 too | forbidden |
With S = R = 1 both NOR outputs are forced to 0, so Q and Q' are no longer complements. Worse, if S and R then return to 0 together, the next state depends on which gate is faster: a race. The design rule is therefore SR = 0.
NAND S'R' latch (active-low inputs): S' = 0 sets, R' = 0 resets, S' = R' = 1 holds, and S' = R' = 0 is forbidden (both outputs go to 1).
A NOR latch starts with Q = 0. The inputs (S, R) take the values (1, 0), (0, 0), (0, 1), (0, 0), (1, 1), (0, 0). Find Q after each step.
| Step | S | R | Q | Q' | Comment |
|---|---|---|---|---|---|
| 1 | 1 | 0 | 1 | 0 | set |
| 2 | 0 | 0 | 1 | 0 | hold (remembers the set) |
| 3 | 0 | 1 | 0 | 1 | reset |
| 4 | 0 | 0 | 0 | 1 | hold |
| 5 | 1 | 1 | 0 | 0 | forbidden: Q = Q' |
| 6 | 0 | 0 | ? | ? | race: unpredictable |
3. Gated Latches: SR and D
A gated (clocked) latch adds an enable input En (often the clock). Two steering gates pass S and R to the latch only while En = 1; when En = 0 the latch holds.
The D latch removes the forbidden input entirely: it feeds D to the set side and D' to the reset side, so S and R can never both be active.
Gated D latch built from four NAND gates and an inverter
| En | D | Q (next) |
|---|---|---|
| 0 | X | Q (hold) |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
While En = 1 the latch is transparent: Q follows D. When En falls, the last value of D is captured.
4. Triggering: Level, Edge and Pulse
The trigger is the clock condition that lets a storage element change.
| Triggering | Element changes | Symbol on the clock pin |
|---|---|---|
| Level (high or low) | during the whole active level | none (latch) |
| Positive edge | only at the 0 → 1 transition | triangle ▷ |
| Negative edge | only at the 1 → 0 transition | triangle with a bubble |
| Pulse (master-slave) | inputs taken during the pulse, output changes at its end | ▷ in older texts |
The transparency of a latch is a problem in a synchronous circuit: if a latch output feeds back to its own input through logic, the value can race round the loop several times while the clock is high. A flip-flop changes only once per clock period, at one edge.
Same D input applied to a D latch and to a positive-edge D flip-flop
In the timing diagram the short pulse on D during the first high level passes straight through the latch, but the flip-flop ignores it: it only looks at D at the dashed rising edges.
5. The Four Flip-Flops
Graphic symbols of the SR, JK, D and T flip-flops
The characteristic table gives the next state Q(t+1) from the inputs and the present state Q (written Q or Q(t)). The characteristic equation is the same information as a Boolean expression.
| Flip-flop | Characteristic table | Characteristic equation |
|---|---|---|
| SR | 00 → Q, 01 → 0, 10 → 1, 11 → invalid | Q(t+1) = S + R'Q with SR = 0 |
| JK | 00 → Q, 01 → 0, 10 → 1, 11 → Q' | Q(t+1) = JQ' + K'Q |
| D | 0 → 0, 1 → 1 | Q(t+1) = D |
| T | 0 → Q, 1 → Q' | Q(t+1) = T oplus Q = TQ' + T'Q |
The JK flip-flop is the SR flip-flop with the forbidden case put to use: J = K = 1 toggles (complements) the output. The T (toggle) flip-flop is a JK with J and K tied together. The D flip-flop simply stores its input and is the most used element in VLSI design.
Write the characteristic table of the JK flip-flop with Q as an input and simplify Q(t+1) with a K-map.
| Q | J | K | Q(t+1) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
- With the variable order Q, J, K: Q(t+1) = ∑ m(2, 3, 4, 6).
- The pair of minterms 2 and 3 is Q'J (present state 0, J = 1).
- The pair of minterms 4 and 6 is QK' (present state 1, K = 0).
A positive-edge JK flip-flop starts with Q = 0. At six successive rising edges (J, K) = (1, 0), (0, 0), (1, 1), (1, 1), (0, 1), (1, 1). Find Q after each edge.
- (1, 0) sets: Q = 1.
- (0, 0) holds: Q = 1.
- (1, 1) toggles: Q = 0.
- (1, 1) toggles: Q = 1.
- (0, 1) resets: Q = 0.
- (1, 1) toggles: Q = 1.
6. Race-Around Condition and the Master-Slave JK Flip-Flop
Build a JK latch (level triggered) by feeding Q and Q' back to the steering gates. With J = K = 1 the output toggles; but while the clock stays high, the new output feeds straight back and toggles it again, and again. The output oscillates for the whole pulse and its final value is unpredictable. This is the race-around condition. It happens when the clock pulse width tp is longer than the propagation delay tpd of the latch.
Cures:
- Make tp < tpd (hard to guarantee).
- Use an edge-triggered flip-flop.
- Use a master-slave flip-flop.
Master-slave JK flip-flop: master enabled by CLK, slave by CLK'
The master-slave JK flip-flop is two latches in series. While CLK = 1 the master follows J and K but the slave is disabled (it sees CLK' = 0), so Q cannot change and nothing can race. When CLK falls, the master freezes and the slave copies it. The output therefore changes once, at the end of the pulse.
A master-slave JK has 1s catching: if J goes to 1 briefly while the clock is high, the master catches it and it cannot be undone in the same pulse. Keep J and K stable while the clock is high, or use an edge-triggered flip-flop.
A JK latch with J = K = 1 has a propagation delay of 20 ns. The clock is high for 100 ns. How many times can the output toggle during one pulse, and how is this fixed?
- One toggle takes one propagation delay: 100 ns / 20 ns = 5 toggles.
- An odd number of toggles leaves Q complemented, an even number leaves it unchanged, so the result depends on the exact timing.
- To toggle only once, the pulse must be shorter than 20 ns, or a master-slave or edge-triggered flip-flop must be used.
7. Direct Inputs and Timing Parameters
Most flip-flops also have asynchronous (direct) inputs that act immediately, without the clock:
- Preset (PRE, often active low): forces Q = 1.
- Clear (CLR, often active low): forces Q = 0. Used to reset a whole circuit at power-up.
Three timing parameters limit how fast a flip-flop can be clocked:
- Setup time ts: the input must be stable this long before the clock edge.
- Hold time th: the input must stay stable this long after the edge.
- Propagation delay tpd: time from the edge to a valid new output.
In a synchronous circuit the signal leaves one flip-flop, passes through combinational logic, and must arrive at the next flip-flop one setup time before the next edge:
A flip-flop has tpd = 10 ns and ts = 5 ns. The longest path through the logic between two flip-flops is 15 ns. Find the maximum clock frequency.
- Tmin = 10 + 15 + 5 = 30 ns.
- fmax = 1 / (30 × 10-9) = 33.3 MHz.
8. Latches and Flip-Flops in Verilog
In Verilog the difference between a latch and a flip-flop is the sensitivity list. An always @(*) block with an if that has no else keeps its old value, which describes a latch.
always @(posedge clk) describes an edge-triggered flip-flop; adding negedge rst_n makes the clear asynchronous. Flip-flops use the non-blocking assignment <=.
// D latch, D flip-flop and JK flip-flop driven by the same signals
module d_latch (
input rst_n,
input en,
input d,
output reg q
);
always @(*) begin
if (!rst_n)
q = 1'b0;
else if (en)
q = d; // transparent while en = 1, holds otherwise
end
endmodule
module d_ff (
input clk,
input rst_n, // asynchronous active-low clear
input d,
output reg q
);
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
q <= 1'b0;
else
q <= d; // samples d only on the rising edge
end
endmodule
module jk_ff (
input clk,
input rst_n,
input j,
input k,
output reg q
);
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
q <= 1'b0;
else
case ({j, k})
2'b00: q <= q; // hold
2'b01: q <= 1'b0; // reset
2'b10: q <= 1'b1; // set
2'b11: q <= ~q; // toggle
endcase
end
endmodule
module tb;
reg clk = 0, d = 0, rst_n = 0, j = 0, k = 0;
wire ql, qf, qjk;
reg [15:0] ck_pat = 16'b0011001100110011;
reg [15:0] d_pat = 16'b0001100001111000;
reg [11:0] jk_pat = 12'b10_00_11_11_01_11;
integer i;
d_latch u1 (.rst_n(rst_n), .en(clk), .d(d), .q(ql));
d_ff u2 (.clk(clk), .rst_n(rst_n), .d(d), .q(qf));
jk_ff u3 (.clk(clk), .rst_n(rst_n), .j(j), .k(k), .q(qjk));
initial begin
#1 rst_n = 1;
$write("CLK ");
for (i = 15; i >= 0; i = i - 1) $write("%b", ck_pat[i]);
$write("\nD ");
for (i = 15; i >= 0; i = i - 1) $write("%b", d_pat[i]);
$write("\n");
// play the waveform once per signal: latch first, then flip-flop
$write("Q latch ");
for (i = 15; i >= 0; i = i - 1) begin
d = d_pat[i];
clk = ck_pat[i];
#5 $write("%b", ql);
end
$write("\nQ ff ");
clk = 0; d = 0; rst_n = 0;
#1 rst_n = 1;
for (i = 15; i >= 0; i = i - 1) begin
d = d_pat[i];
clk = ck_pat[i];
#5 $write("%b", qf);
end
$write("\n\nJK flip-flop, Q starts at 0\n");
clk = 0; rst_n = 0;
#1 rst_n = 1;
for (i = 5; i >= 0; i = i - 1) begin
{j, k} = {jk_pat[2 * i + 1], jk_pat[2 * i]};
#5 clk = 1;
#5 clk = 0;
$display("edge %0d: J=%b K=%b -> Q=%b", 6 - i, j, k, qjk);
end
end
endmoduleThe latch and flip-flop rows reproduce the timing diagram above, and the JK rows reproduce Example 3:
CLK 0011001100110011
D 0001100001111000
Q latch 0001110000111100
Q ff 0000000000111100
JK flip-flop, Q starts at 0
edge 1: J=1 K=0 -> Q=1
edge 2: J=0 K=0 -> Q=1
edge 3: J=1 K=1 -> Q=0
edge 4: J=1 K=1 -> Q=1
edge 5: J=0 K=1 -> Q=0
edge 6: J=1 K=1 -> Q=1Key points to remember
- Latch = level sensitive (transparent while enabled); flip-flop = edge triggered (samples at one edge).
- NOR SR latch: S = R = 1 forbidden; NAND S'R' latch: S' = R' = 0 forbidden.
- SR: Q+ = S + R'Q; JK: Q+ = JQ' + K'Q; D: Q+ = D; T: Q+ = T oplus Q.
- Race-around: a JK latch with J = K = 1 toggles repeatedly when tp > tpd; fixed by master-slave or edge triggering.
- fmax = 1 / (tpd + tlogic + ts).
📝 IPU End-Term Exam Corner (5-10 Marks)
- Q1. Distinguish between a latch and a flip-flop. Draw an SR latch using NOR gates and explain its operation with a truth table. (5 Marks)
- Q2. What is the race-around condition? Explain how a master-slave JK flip-flop eliminates it, with a diagram. (10 Marks)
- Write: JK latch with feedback, the condition tp > tpd, the master and slave clocked by CLK and CLK', the output changing once per pulse.
- Q3. Give the characteristic table and characteristic equation of SR, JK, D and T flip-flops. (5 Marks)
- Q4. Explain level triggering and edge triggering with timing diagrams. (5 Marks)
- Q5. Define setup time, hold time and propagation delay. Find the maximum clock frequency for tpd = 10 ns, ts = 5 ns and 15 ns of logic. (5 Marks)