Overview
Readings Brown & Vranesic §7.1–7.3, 7.4.2, 7.5, 7.8 · weeks 7–8
Everything up to now has been combinational, meaning the output only depends on the inputs right now. A sequential circuit also depends on what happened before, because it stores a bit. This chapter covers the two basic storage elements, latches (level-sensitive) and flip-flops (edge-triggered), in the S-R, D, J-K and T varieties, plus the asynchronous preset and clear inputs. It ends with registers, which are just several flip-flops sharing one clock, and the shift register.
Notes
Latches vs flip-flops
Both are bistable, meaning they have two stable states (storing a 0 or a 1) and stay in one until told to change. Both get this from feedback, where each gate’s output is wired back into the input of the other gate.
The difference is when they’re allowed to change. This is the one distinction I’d make sure you have down before anything else in this chapter:
| Device | Changes state… | Sensitive to |
|---|---|---|
| Latch | any time its inputs (and enable) say so | the level of the enable |
| Flip-flop | only at a clock edge | the edge (transition) of the clock |
The outputs are always and , which are normally complements of each other. SET means ; RESET (clear) means .
The S-R latch
Active-HIGH S-R latch: two cross-coupled NOR gates.
Figure 7.1: An active-HIGH S-R latch made of cross-coupled NOR gates.
| Mode | ||||
|---|---|---|---|---|
| 0 | 0 | No change (holds the stored bit) | ||
| 1 | 0 | 1 | 0 | Set |
| 0 | 1 | 0 | 1 | Reset |
| 1 | 1 | 0 | 0 | Invalid () |
Why it holds: with , each NOR acts as an inverter of the other gate’s output, so keeps feeding back and the other way around. Whichever state it’s in reinforces itself.
Why is invalid: both NOR outputs are forced to 0, so and aren’t complements anymore. Even worse, if both inputs then go back to 0 at the same time, the latch ends up in an unpredictable state.
Example 7.1: S-R latch
An active-HIGH S-R latch starts RESET (). Find for this input sequence.
| Interval | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| 1 | 0 | 0 | 0 | 1 | 0 | |
| 0 | 0 | 1 | 0 | 0 | 0 | |
| ? | ? | ? | ? | ? | ? |
Show answerHide answer
| Interval | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| 1 | 0 | 0 | 0 | 1 | 0 | |
| 0 | 0 | 1 | 0 | 0 | 0 | |
| 1 | 1 | 0 | 0 | 1 | 1 |
- Interval 1: set. Interval 2: hold (stays 1). Interval 3: reset. Interval 4: hold (stays 0). Interval 5: set. Interval 6: hold.
Active-LOW - latch: two cross-coupled NAND gates. Same idea, but the inputs are active-LOW. A 0 sets or resets it, holds, and is invalid (both outputs go to 1).
| Mode | |||
|---|---|---|---|
| 1 | 1 | No change | |
| 0 | 1 | 1 | Set |
| 1 | 0 | 0 | Reset |
| 0 | 0 | 1 (and ) | Invalid |
Example 7.2: Active-LOW latch
A NAND - latch starts SET (). Find for .
| 1 | 1 | 1 | 0 | 1 | |
|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 1 | |
| ? | ? | ? | ? | ? |
Show answerHide answer
| 1 | 1 | 1 | 0 | 1 | |
|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 1 | |
| 1 | 0 | 0 | 1 | 1 |
- : hold. : is LOW, so reset. : hold. : is LOW, so set. : hold.
Try it: click time slots of and to change them. The latch starts RESET, and red marks the invalid state.
Gated latches
A gated latch adds an enable input (, sometimes ). The latch only responds to its other inputs while is HIGH. It’s level-sensitive, so for the whole time the output follows the inputs.
Gated S-R latch. Two AND (or NAND) gates pass and through only when :
- : no change, whatever and do.
- : behaves like a normal S-R latch ( is still invalid).
Example 7.3: Gated S-R latch
A gated S-R latch starts RESET. Find .
| Interval | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | |
| 1 | 1 | 0 | 0 | 0 | 1 | 0 | |
| 0 | 0 | 0 | 1 | 0 | 0 | 0 | |
| ? | ? | ? | ? | ? | ? | ? |
Show answerHide answer
| Interval | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | |
| 1 | 1 | 0 | 0 | 0 | 1 | 0 | |
| 0 | 0 | 0 | 1 | 0 | 0 | 0 | |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 |
- Interval 1: but , so nothing happens.
- Interval 2: , → set.
- Interval 4: , → reset.
- Interval 6: again, but , so it stays 0. Interval 7: but → hold.
Gated D latch. This gets rid of the invalid state by having just one data input , with and inside:
| Mode | |||
|---|---|---|---|
| 0 | X | No change | |
| 1 | 0 | 0 | Reset |
| 1 | 1 | 1 | Set |
In short: while , follows . When goes to 0, holds the last value of .
Example 7.4: Gated D latch
A gated D latch starts RESET. Find .
| Interval | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | |
| 1 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | |
| ? | ? | ? | ? | ? | ? | ? | ? |
Show answerHide answer
| Interval | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | |
| 1 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | |
| 1 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
While , copies (intervals 1–2 and 5–6). While , keeps whatever was when fell, no matter what does after that.
Try it: switch between the gated S-R and D latch, and edit the inputs. The shaded columns are where is HIGH, and those are the only places can change.
Edge-triggered flip-flops
A flip-flop only changes state at one instant, the triggering edge of the clock (, or control input ). Everywhere else, its inputs are ignored.
- Positive edge-triggered: changes on the rising edge (0 → 1). The symbol has no bubble on .
- Negative edge-triggered: changes on the falling edge (1 → 0). The symbol has a bubble on .
- The small triangle at the input (the dynamic input indicator) is how you tell a flip-flop from a latch on a schematic.
The data inputs (, or and ) are called synchronous inputs because their effect is synchronized with the clock.
D flip-flop
On the triggering edge, takes the value of . Between edges, can change freely without affecting , except for a very short window right around the edge where it has to be stable.
| Mode | |||
|---|---|---|---|
| 1 | ↑ | 1 | Set (stores 1) |
| 0 | ↑ | 0 | Reset (stores 0) |
So follows at the clock edge, and holds that value until the next edge.
Example 7.5: D flip-flop
A positive edge-triggered D flip-flop starts RESET. The value of at each of five rising clock edges is . Find after each edge.
| Rising edge | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| at the edge | 1 | 1 | 0 | 1 | 0 |
| after | ? | ? | ? | ? | ? |
Show answerHide answer
| Rising edge | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| at the edge | 1 | 1 | 0 | 1 | 0 |
| after | 1 | 1 | 0 | 1 | 0 |
is always the opposite: . Changes in between edges have no effect.
Example 7.6: Latch vs flip-flop on the same inputs
Ties together Examples 7.4 and 7.5
and a control signal are fed to both a gated D latch (control = ) and a positive edge-triggered D flip-flop (control = ). Both start RESET. The control goes HIGH during interval 2 and stays HIGH through interval 4, and goes across intervals 1–5. Compare .
Show answerHide answer
| Interval | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Control | 0 | 1 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 | |
| (D latch) | 0 | 1 | 0 | 1 | 1 |
| (D flip-flop) | 0 | 1 | 1 | 1 | 1 |
- The latch is transparent the whole time the control is HIGH, so it copies every change of in intervals 2–4 and then holds the last value (1).
- The flip-flop only looks at at the single rising edge (the start of interval 2), where , and ignores everything else.
Master-slave D flip-flop
One way to build an edge-triggered flip-flop is from two gated D latches in a row, with the clock inverted for the second one (Brown & Vranesic Figure 7.10):
- The master latch is enabled while . Its output follows the whole time the clock is HIGH.
- The slave latch is enabled while . It copies to the output .
The two are never transparent at the same time, which is the trick:
- Clock HIGH: the master tracks , and the slave holds, so doesn’t change.
- Clock goes 1 → 0: the master freezes on whatever was at that instant, and the slave passes that value to .
- Clock LOW: can’t change, so the slave can change at most once per clock cycle.
From outside, the circuit changes state only at the negative (falling) edge of the clock. However many times changes during a cycle, only shows the value had at the falling edge. Its symbol has the triangle with a bubble on the clock input.
Example 7.7: Master-slave D flip-flop
A master-slave D flip-flop starts with . Each clock cycle is split into a HIGH half and a LOW half, and is given at the start and end of each HIGH half. Find and .
| Clock cycle | 1 | 2 | 3 |
|---|---|---|---|
| during the HIGH half | |||
| at the falling edge | 1 | 1 | 0 |
| after the falling edge | ? | ? | ? |
Show answerHide answer
| Clock cycle | 1 | 2 | 3 |
|---|---|---|---|
| during the HIGH half | |||
| at the falling edge | 1 | 1 | 0 |
| after the falling edge | 1 | 1 | 0 |
- While the clock is HIGH, follows every change of , but doesn’t move.
- At each falling edge the slave copies , so only ever shows the value had at that instant. The extra changes of in cycle 2 never reach .
J-K flip-flop
It’s like an S-R flip-flop ( = set, = reset), except is useful instead of invalid, because it toggles the output.
| after the edge | Mode | |||
|---|---|---|---|---|
| 0 | 0 | ↑ | No change | |
| 0 | 1 | ↑ | 0 | Reset |
| 1 | 0 | ↑ | 1 | Set |
| 1 | 1 | ↑ | Toggle |
Example 7.8: J-K flip-flop
A positive edge-triggered J-K flip-flop starts RESET. Find after each edge.
| Rising edge | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 | 1 | |
| 0 | 0 | 1 | 1 | 1 | 1 | |
| Mode | set | hold | toggle | toggle | reset | toggle |
| after | ? | ? | ? | ? | ? | ? |
Show answerHide answer
| Rising edge | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 | 1 | |
| 0 | 0 | 1 | 1 | 1 | 1 | |
| Mode | set | hold | toggle | toggle | reset | toggle |
| after | 1 | 1 | 0 | 1 | 0 | 1 |
Try it: switch between the D and J-K flip-flops. The clock is fixed, and the dashed lines mark its rising edges, which are the only instants can change.
Asynchronous preset and clear
Most flip-flop chips also have asynchronous inputs that act right away, no matter what the clock is doing:
- Preset (, or direct set ): forces .
- Clear (, or direct reset ): forces .
They’re usually active-LOW (bubbles on the symbol):
| Effect | ||
|---|---|---|
| 1 | 1 | Normal clocked operation |
| 0 | 1 | right away |
| 1 | 0 | right away |
| 0 | 0 | Not used (invalid) |
For normal synchronous operation, keep both HIGH. They’re mostly used to put the flip-flop in a known state at power-up.
Example 7.9: Asynchronous preset and clear
A positive edge-triggered D flip-flop with active-LOW and starts with , and the whole time. Find .
| Interval | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| Rising edge at start? | no | yes | no | yes | no | yes |
| 1 | 1 | 1 | 1 | 0 | 1 | |
| 0 | 0 | 1 | 1 | 1 | 0 | |
| ? | ? | ? | ? | ? | ? |
Show answerHide answer
| Interval | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| Rising edge at start? | no | yes | no | yes | no | yes |
| 1 | 1 | 1 | 1 | 0 | 1 | |
| 0 | 0 | 1 | 1 | 1 | 0 | |
| 0 | 0 | 0 | 1 | 1 | 0 |
- Intervals 1–2: is LOW, so is held at 0 even though there’s an edge with in interval 2.
- Interval 4: both inputs are HIGH, so the edge clocks in .
- Interval 5: LOW forces (it already is).
- Interval 6: LOW forces right away, overriding the clock edge.
Try it: pull or LOW and watch change right away instead of at the next edge.
T flip-flop
A D flip-flop can be made to act like a different kind of storage element by putting a little logic in front of . Feeding back through a 2-to-1 multiplexer controlled by (Brown & Vranesic Figure 7.16) gives
- : , so the next edge stores the same value. Hold.
- : , so the next edge flips the output. Toggle.
| Mode | ||
|---|---|---|
| 0 | No change | |
| 1 | Toggle |
is the state before the edge and is the state right after it. A J-K flip-flop with does the same thing.
Example 7.10: T flip-flop
A positive edge-triggered T flip-flop starts RESET. The value of at six rising edges is . Find after each edge.
| Rising edge | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 | 1 | |
| Mode | toggle | hold | toggle | toggle | hold | toggle |
| after | ? | ? | ? | ? | ? | ? |
Show answerHide answer
| Rising edge | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 | 1 | |
| Mode | toggle | hold | toggle | toggle | hold | toggle |
| after | 1 | 1 | 0 | 1 | 1 | 0 |
With held at 1, the output would toggle on every edge, giving a square wave at half the clock frequency. That’s the basic idea behind counters.
Configurable flip-flops
For some circuits one flip-flop type gives a cheaper implementation than another. General-purpose chips like PLDs (see Ch 3) often have configurable flip-flops that can be set up as D, T, or another type.
Registers
A flip-flop holds one bit. A register is a group of flip-flops side by side that holds a multi-bit value (a number, an address, an instruction): 4 flip-flops make a 4-bit register, 8 make an 8-bit register, and so on. All of them share the same clock, so every bit updates on the same edge and the group acts as one unit.
Example 7.11: Sizing a register
How many flip-flops are needed to store (a) a hex digit, (b) a value from 0 to 1000, and (c) one ASCII character (7 bits)? How many clock edges does it take to load an 8-bit value into an 8-bit shift register?
Show answerHide answer
- (a) One hex digit is bits, so flip-flops.
- (b) , so flip-flops.
- (c) flip-flops.
- A shift register accepts one bit per edge, so loading bits serially takes edges. A plain register loads all bits on a single edge, since each flip-flop has its own input.
That trade-off, one wire and many clocks against many wires and one clock, is the difference between serial and parallel transfer.
Shift registers
A shift register can move its contents one bit position on each clock edge. In a 4-bit right-shift register (Figure 7.2), each D flip-flop’s feeds the next one’s :
Figure 7.2: A 4-bit shift register. On each rising edge, .
- Data comes in serially, one bit per clock cycle, on .
- At every rising edge, each flip-flop takes the old value of the one to its left.
- After 4 edges, the first bit that went in comes out at .
Example 7.12: Shift register
A 4-bit right-shift register starts at . The bits on before six rising edges are . Find the contents after each edge.
Show answerHide answer
| After edge | |||||
|---|---|---|---|---|---|
| start | – | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 | 0 | 0 |
| 2 | 1 | 1 | 1 | 0 | 0 |
| 3 | 0 | 0 | 1 | 1 | 0 |
| 4 | 1 | 1 | 0 | 1 | 1 |
| 5 | 0 | 0 | 1 | 0 | 1 |
| 6 | 0 | 0 | 0 | 1 | 0 |
Each row is the row above shifted one place right, with the new bit entering at . The first bit in (1, at edge 1) reaches at edge 4.
A shift register needs edge-triggered (or master-slave) flip-flops. With gated latches, while the clock is HIGH every latch is transparent, so a change on would race through several stages in one cycle instead of moving one place.
Key formulas
S-R latch (active-HIGH)
Gated D latch
D flip-flop
- : the output right after the clock edge
- : the data input just before the edge
J-K flip-flop
- : the output before the edge
- : set input; : reset input. toggles.
Check: gives (hold), gives (toggle).
T flip-flop
- : the output before the edge
- : toggle input. holds, toggles.
Shift register (right shift, stages)
- : output of stage ()
Common mistakes
- Treating a gated latch like a flip-flop. A latch follows its inputs for the whole time is HIGH, not just at the edge.
- Forgetting that the NAND latch is active-LOW. sets it, and is the hold state.
- Using on an S-R latch. It’s invalid, and the J-K flip-flop is the version where is allowed (toggle).
- Letting change between clock edges on a flip-flop. Only the edge (and the asynchronous inputs) can change it.
- Reading after the edge instead of just before it.
- Waiting for a clock edge to apply or . They’re asynchronous, so they act right away.
- Thinking a master-slave flip-flop changes on the rising edge. The master loads while the clock is HIGH, but only changes at the falling edge.
- Writing for in the T flip-flop circuit. It’s ; is the hold case ().
- Building a shift register out of gated latches. While the clock is HIGH the bit would race through more than one stage.