Chapter 10 of 39

Sequential Circuits: Flip-Flops, Registers & Counters

On this page

Press the "+" button on a TV remote and the channel goes from 5 to 6. Press it again and it goes to 7. The same input (a button press) gives a different result each time, because the TV remembers the current channel. None of the circuits in Combinational Circuits: Adders, Multiplexers & Decoders could do this: their outputs depend only on their present inputs.

A computer is full of things that must be remembered: the program counter, the registers, the instruction being executed, the state of the control unit. All of them are built from sequential circuits.

A sequential circuit is a circuit whose outputs depend on its current inputs and on its present state, i.e. on the history of past inputs. It is built from combinational logic plus memory elements (latches or flip-flops) connected with feedback.

             +---------------------+
inputs ----->|                     |------> outputs
             |  combinational      |
        +--->|  logic              |----+  next state
        |    +---------------------+    |
        |                               v
        |    +---------------------+
        +----|  memory elements    |<--- clock
 present     |  (flip-flops)       |
 state       +---------------------+

In this chapter we build memory from gates (the SR latch), improve it into the D latch and edge-triggered flip-flops, study SR, D, JK and T flip-flops with their characteristic and excitation tables, learn timing rules (setup, hold, maximum clock frequency), and then use flip-flops to build registers, shift registers and counters, including a full synchronous counter design. All tables, equations and counting sequences here were checked by simulation in Python.


Synchronous vs Asynchronous Sequential Circuits

  • Synchronous: state changes only at specific instants defined by a clock signal (usually its rising edge). Between edges, the combinational logic has time to settle. Almost all processors are synchronous, because timing becomes predictable.

  • Asynchronous: state can change whenever an input changes. Potentially faster, but much harder to design correctly because of races between signals.

A clock is a square wave. Its period T is the time for one cycle, and its frequency f = 1/T. A 2 GHz clock has a period of 0.5 ns.


The SR Latch: Memory from Two Gates

Connect two NOR gates so that each one's output feeds the other's input:

        +-------+
R ----->|       |
        |  NOR  |--------+-------> Q
   +--->|       |        |
   |    +-------+        |
   |                     |   (each output is fed back
   |    +-------+        |    to the other gate)
   |    |       |<-------+
   +----|  NOR  |
        |       |<------ S
        +-------+--------------> Q′

Q  = NOR(R, Q′)
Q′ = NOR(S, Q)

Simulating the loop for every input gives:

S

R

Q (next)

Meaning

0

0

Q (unchanged)

Hold: the feedback keeps whatever was stored

1

0

1

Set

0

1

0

Reset

1

1

Q = Q′ = 0

Forbidden: outputs are no longer complements, and if S and R then drop to 0 together, the final state is unpredictable

The key is the hold row. With S = R = 0 the circuit has two stable states (Q = 0 or Q = 1), and it stays in whichever one it was put in. That is one bit of memory, a bistable circuit.

A latch built from two cross-coupled NAND gates works the same way but with active-low inputs: both inputs at 1 means hold, pulling the set input to 0 sets, pulling the reset input to 0 resets, and pulling both to 0 is forbidden (both outputs become 1).

Gated Latches and the D Latch

Adding an enable (or clock) input C, with AND gates in front of S and R, lets the latch change only while C = 1. The D latch removes the forbidden state entirely by deriving both inputs from one data input: S = D, R = D′.

D latch:   C = 0  →  Q holds its value
           C = 1  →  Q = D   (the latch is "transparent": Q follows D)

Transparency is a problem. While C = 1, any change in D passes straight through to Q. In a circuit where Q feeds back through logic into D (e.g. a counter computing Q + 1), the value could race around the loop several times during one clock pulse. We need a device that samples its input at one instant only.


Flip-Flops: Edge-Triggered Memory

A latch is level-sensitive: it can change for the whole time the clock (enable) is active. A flip-flop is edge-triggered: it samples its inputs and changes state only at a clock edge (rising or falling).

A common way to build an edge-triggered D flip-flop is a master-slave pair of D latches: the master is transparent while the clock is low, the slave while it is high. At the rising edge the master closes (capturing D) and the slave opens (passing the captured value to Q). D is effectively sampled at the rising edge only.

Point

Latch

Flip-flop

Triggering

Level (while enable = 1)

Edge (at rising or falling edge)

Transparent?

Yes, while enabled

No

Size

Smaller

About two latches

Typical use

Some high-speed and low-power designs

Registers, counters, state machines (standard practice)

The Four Flip-Flop Types

We describe each flip-flop by its characteristic table (given inputs and present state Q, what is the next state Q+?) and its characteristic equation.

SR Flip-Flop

S

R

Q+

0

0

Q (hold)

0

1

0 (reset)

1

0

1 (set)

1

1

invalid

Characteristic equation: Q+ = S + R′Q, with the constraint SR = 0.

D (Data / Delay) Flip-Flop

Q+ = D. Whatever is on D at the clock edge is stored. It "delays" D by one clock cycle. This is the flip-flop used for registers and almost all modern designs.

JK Flip-Flop

J

K

Q+

0

0

Q (hold)

0

1

0 (reset)

1

0

1 (set)

1

1

Q′ (toggle)

Characteristic equation: Q+ = JQ′ + K′Q. The JK flip-flop is an SR flip-flop where the forbidden input is given a useful meaning: toggle.

T (Toggle) Flip-Flop

T = 0 holds, T = 1 toggles: Q+ = T ⊕ Q = TQ′ + T′Q. A T flip-flop with T = 1 divides the clock frequency by 2, which is the basis of counters. It is a JK flip-flop with J and K tied together.

Race-Around Condition

In a level-triggered JK flip-flop with J = K = 1, the output toggles as soon as the clock goes high. The new Q feeds back to the input gates, and if the clock is still high, it toggles again, and again, until the clock goes low. The final state is unpredictable. This is the race-around condition. It occurs when the clock pulse width is longer than the propagation delay of the flip-flop.

Fixes: make the pulse width shorter than the propagation delay (hard to guarantee), or, as done in practice, use a master-slave or edge-triggered JK flip-flop, so that the output changes only once per clock cycle.

Excitation Tables

For designing circuits we need the reverse question: to move from Q to a desired Q+, what inputs must we apply? x means don't care.

Q → Q+

S R

J K

D

T

0 → 0

0 x

0 x

0

0

0 → 1

1 0

1 x

1

1

1 → 0

0 1

x 1

0

1

1 → 1

x 0

x 0

1

0

Why so many x's for JK? For 0 → 1, both "set" (J=1, K=0) and "toggle" (J=1, K=1) work, so K does not matter. These don't-cares make JK designs need simpler logic than SR designs.

Converting One Flip-Flop into Another

Put logic in front of the available flip-flop so that it behaves like the required one. The answers follow from the characteristic equations:

Required

Available

Connection

D

JK

J = D, K = D′

T

JK

J = K = T

JK

D

D = JQ′ + K′Q

T

D

D = T ⊕ Q

JK

SR

S = JQ′, R = KQ (S and R are never 1 together)

Asynchronous Preset and Clear

Real flip-flops usually have preset (force Q = 1) and clear (force Q = 0) inputs that act immediately, without waiting for the clock. They are used to initialize a system at power-on (reset) and, as we will see, to cut short a ripple counter.


Timing: Setup, Hold and Maximum Clock Frequency

A flip-flop needs its input to be stable for a short window around the clock edge:

  • Setup time (tsetup): D must be stable this long before the edge.

  • Hold time (thold): D must stay stable this long after the edge.

  • Clock-to-Q delay (tcq): Q changes this long after the edge.

If these are violated, the flip-flop can enter a metastable state, hovering between 0 and 1 for an unpredictable time.

Between two flip-flops, a signal leaves the first one tcq after an edge, passes through combinational logic (tcomb), and must arrive tsetup before the next edge:

Tclock ≥ tcq + tcomb(max) + tsetup, so fmax = 1 / (tcq + tcomb(max) + tsetup).

Example 1: Maximum Clock Frequency

t_cq = 3 ns,  longest combinational path = 12 ns,  t_setup = 2 ns

T_min = 3 + 12 + 2 = 17 ns
f_max = 1 / 17 ns ≈ 58.8 MHz

Hold time gives a different condition: the shortest path must not change D too soon after the edge: tcq(min) + tcomb(min) ≥ thold. Notice that the clock period does not appear here, so a hold violation cannot be fixed by slowing the clock. This is exactly the reasoning used later in Pipelining Basics, where each pipeline stage is the logic between two registers.


Registers

An n-bit register is a group of n flip-flops sharing a common clock, storing an n-bit word.

A plain register of D flip-flops loads new data on every clock edge. Usually we want to load only sometimes, so a load control is added with a 2-to-1 MUX in front of each D input: Di = Load·Ii + Load′·Qi. When Load = 0 the flip-flop reloads its own value (holds). (Gating the clock itself to hold is avoided in simple designs because it can cause timing problems.)

Shift Registers

In a shift register each flip-flop's output feeds the next flip-flop's input, so on each clock edge the whole word moves one position. They are classified by how data enters and leaves:

Type

Input

Output

Typical use

SISO

Serial

Serial

Delay line

SIPO

Serial

Parallel

Receiving serial data (UART, SPI receivers)

PISO

Parallel

Serial

Transmitting a byte bit by bit

PIPO

Parallel

Parallel

Ordinary storage register

Example 2: Loading 1011 into a 4-bit SISO Register

Data enters Q0 and moves Q0 → Q1 → Q2 → Q3 (serial output). Bits are entered in the order 1, 0, 1, 1, starting from 0000:

Clock   Serial in   Q0  Q1  Q2  Q3 (out)
start       -        0   0   0   0
  1         1        1   0   0   0
  2         0        0   1   0   0
  3         1        1   0   1   0
  4         1        1   1   0   1     ← first bit entered has reached the output

After 4 clocks the register holds the word (read Q3 Q2 Q1 Q0 = 1011, in the order entered), and the first bit is already at the serial output. To shift all four bits out serially, 3 more clocks are needed.

For an n-bit SISO register: loading takes n clock pulses; the first bit appears at the output after n clocks, and reading out all n bits serially needs n − 1 more, i.e. 2n − 1 clocks in total from the first bit entering to the last bit appearing at the output.

Shifting is also arithmetic: shifting a binary number left by one position multiplies it by 2, shifting right divides by 2 (for signed numbers, an arithmetic right shift copies the sign bit). A universal shift register such as the 74194 combines hold, shift left, shift right and parallel load, chosen by two mode inputs (S1 S0 = 00 hold, 01 shift right, 10 shift left, 11 parallel load).


Counters

A counter is a sequential circuit that goes through a fixed sequence of states on successive clock pulses. A counter with N distinct states is a mod-N counter and needs at least ⌈log2N⌉ flip-flops.

Asynchronous (Ripple) Counter

Connect T flip-flops with T = 1 (toggle on every triggering edge). The external clock drives only the first flip-flop; each later flip-flop is clocked by the previous flip-flop's output. With negative-edge-triggered flip-flops (each flip-flop toggles when the one before it goes 1 → 0), this counts up:

CLK → [FF0] Q0 → [FF1] Q1 → [FF2] Q2 → [FF3] Q3

Q3 Q2 Q1 Q0:  0000 → 0001 → 0010 → 0011 → ... → 1111 → 0000   (mod 16)

Q0 toggles every clock: frequency f/2
Q1 toggles every 2nd:   f/4
Q2:                     f/8
Q3:                     f/16

Each stage halves the frequency, so a ripple counter is also a frequency divider.

The drawback: changes ripple through the stages one after another. Going from 0111 to 1000, Q0 changes first, then Q1, then Q2, then Q3, each after one flip-flop delay. Meanwhile the counter shows wrong intermediate values (0110, 0100, 0000) for a short time. The total settling time is n × tpd.

Example 3: Speed of a Ripple Counter

4-bit ripple counter, flip-flop delay t_pd = 10 ns

Worst-case settling time = 4 × 10 = 40 ns
If the count must be stable (and read) before the next clock edge:
f_max = 1 / 40 ns = 25 MHz

Mod-N Ripple Counter (Example: Decade Counter)

To count 0 to 9 (mod 10) with a 4-bit ripple counter, detect the first unwanted state, 10 (1010), and use it to clear all flip-flops asynchronously. Since 1010 is the first state with Q3 = 1 and Q1 = 1, a NAND of Q3 and Q1 driving the active-low clear inputs is enough.

Count: 0, 1, 2, ..., 9, (10 appears for a few ns, then clears) → 0, 1, ...

State 1010 does exist briefly, causing a glitch. Synchronous designs avoid this.

Synchronous Counter

All flip-flops share the same clock, and combinational logic decides which ones toggle. For a binary up counter, bit i toggles when all lower bits are 1:

T0 = 1
T1 = Q0
T2 = Q1·Q0
T3 = Q2·Q1·Q0

All flip-flops change together, one tcq after the edge, so there are no ripple glitches, and the maximum frequency is set by one flip-flop delay plus the AND gate delay, not by n flip-flop delays.

Point

Asynchronous (ripple)

Synchronous

Clock

Only the first flip-flop gets the external clock

All flip-flops share one clock

Extra logic

None (for binary up count)

AND gates to compute toggle conditions

Delay

n × tpd, grows with n

About tcq + gate delays

Glitches

Yes, temporary wrong states

No

Max frequency

Lower

Higher

Ring and Johnson Counters

These are shift registers whose output is fed back to the input.

  • Ring counter: Q of the last flip-flop feeds the first. Initialized with a single 1 (1000), it circulates that 1: 1000 → 0100 → 0010 → 0001 → 1000. An n-bit ring counter has n states, and each state is "one-hot", so no decoder is needed to identify states. Useful for generating timing signals in a control unit.

  • Johnson (twisted-ring) counter: Q′ of the last flip-flop feeds the first. An n-bit Johnson counter has 2n states.

4-bit Johnson counter (Q0 Q1 Q2 Q3), D0 = Q3′, starting at 0000:
0000 → 1000 → 1100 → 1110 → 1111 → 0111 → 0011 → 0001 → 0000   (8 states)

Counter (n flip-flops)

Used states

Unused states

Example n = 4

Binary

2n

0

16 states

Ring

n

2n − n

4 used, 12 unused

Johnson

2n

2n − 2n

8 used, 8 unused

Unused states matter: if noise or power-up puts a ring counter into, say, 1100, it will circulate two 1s forever. Practical designs add self-correcting logic or a reset.


Designing a Synchronous Counter

This is a classic exam problem. The method works for any sequence:

  1. Draw the state table: present state → next state.

  2. Using the excitation table of the chosen flip-flop, write the required inputs for each transition.

  3. Simplify each input with a K-map, treating unused states as don't-cares.

  4. Check what happens from the unused states (is the counter self-starting?).

Example 4: Mod-5 Up Counter with JK Flip-Flops

Sequence 000 → 001 → 010 → 011 → 100 → 000. States 101, 110, 111 are unused.

Present      Next        Flip-flop inputs (from the JK excitation table)
Q2 Q1 Q0     Q2 Q1 Q0    J2 K2    J1 K1    J0 K0
 0  0  0      0  0  1     0  x     0  x     1  x
 0  0  1      0  1  0     0  x     1  x     x  1
 0  1  0      0  1  1     0  x     x  0     1  x
 0  1  1      1  0  0     1  x     x  1     x  1
 1  0  0      0  0  0     x  1     0  x     0  x
 1  0  1      -           x  x     x  x     x  x   (unused)
 1  1  0      -           x  x     x  x     x  x   (unused)
 1  1  1      -           x  x     x  x     x  x   (unused)

K-map each input (states 5, 6, 7 are don't-cares):

J2: 1 only at state 3 (011); don't-cares at 4-7     → J2 = Q1·Q0
K2: 1 at state 4; every other entry is x            → K2 = 1
J1: 1 at state 1, 0 at states 0 and 4               → J1 = Q0
K1: 1 at state 3, 0 at state 2                      → K1 = Q0
J0: 1 at states 0 and 2, 0 at state 4               → J0 = Q2′
K0: 1 at states 1 and 3, all others x               → K0 = 1

So: J2 = Q1Q0, K2 = 1; J1 = K1 = Q0; J0 = Q2′, K0 = 1.

Self-start check (apply the equations to the unused states):

101: J2=0,K2=1 → Q2=0;  J1=K1=1 → Q1 toggles 0→1;  J0=0,K0=1 → Q0=0   → 010
110: Q2 → 0;  J1=K1=0 → Q1 stays 1;  Q0 → 0                            → 010
111: Q2 → 0;  J1=K1=1 → Q1 toggles to 0;  Q0 → 0                       → 000

Every unused state enters the main cycle within one clock, so the counter is self-starting. A simulation of all eight states confirms: 0→1→2→3→4→0, and 5→2, 6→2, 7→0.

Example 5: Analysing a Given Circuit

Two D flip-flops with D1 = Q0 and D0 = Q1′, starting at Q1Q0 = 00. Find the sequence.

Q1 Q0    D1 = Q0   D0 = Q1′    next Q1 Q0
 0  0       0         1           0  1
 0  1       1         1           1  1
 1  1       1         0           1  0
 1  0       0         0           0  0    ← back to the start

The sequence is 00 → 01 → 11 → 10 → 00: a 2-bit Johnson counter, which happens to count in Gray code (only one bit changes per step).

A circuit like this, whose next state depends on the present state (and possibly inputs), is a finite state machine. If the outputs depend only on the state it is a Moore machine; if they also depend directly on the inputs it is a Mealy machine. The hardwired control unit of a processor is such a machine (see Hardwired Control Unit).


Common Mistakes

  • Calling a latch a flip-flop. Latches are level-sensitive; flip-flops are edge-triggered.

  • Using the characteristic table when designing. For design, use the excitation table (Q → Q+ gives the required inputs).

  • Forgetting the x's in the JK excitation table, which makes the logic bigger than necessary.

  • Saying a Johnson counter has n states. Ring: n states; Johnson: 2n states.

  • Computing ripple counter speed with one flip-flop delay. The worst case is n flip-flop delays.

  • Treating unused states as "never happen" without checking self-start.

  • Thinking a slower clock fixes hold violations. Setup violations depend on the clock period; hold violations do not.

  • Counting SISO shift clocks wrongly. n clocks to load n bits; 2n − 1 for the last bit to reach the output.


GATE and Interview Questions

Q1. What is the forbidden input of a NOR-based SR latch, and why?

S = R = 1. Both outputs become 0, so Q and Q′ are not complements, and if both inputs then return to 0 at the same time, the latch can end in either state (a race), so the result is unpredictable.

Q2. Write the characteristic equation of a JK flip-flop and convert it into a T flip-flop.

Q+ = JQ′ + K′Q. Tie J = K = T: Q+ = TQ′ + T′Q = T ⊕ Q, which is the T flip-flop.

Q3. What is the race-around condition and how is it avoided?

In a level-triggered JK flip-flop with J = K = 1, the output toggles repeatedly while the clock is high, if the pulse width exceeds the propagation delay. It is avoided with master-slave or edge-triggered flip-flops, which change state only once per clock cycle.

Q4. How many states do a 5-bit ring counter and a 5-bit Johnson counter have?

Ring: 5 states. Johnson: 2 × 5 = 10 states.

Q5. How many flip-flops are needed for a mod-12 counter? For a mod-100 counter?

⌈log212⌉ = 4 and ⌈log2100⌉ = 7 (26 = 64 < 100 ≤ 128 = 27).

Q6. A circuit has tcq = 2 ns, tsetup = 1 ns and a longest logic path of 7 ns between registers. What is the maximum clock frequency?

Tmin = 2 + 7 + 1 = 10 ns, so fmax = 100 MHz.

Q7. A 3-bit ripple counter uses flip-flops with 15 ns propagation delay. What is the maximum clock frequency if the output must settle before the next pulse?

Worst-case settling = 3 × 15 = 45 ns, so fmax = 1/45 ns ≈ 22.2 MHz.

Q8. Why are synchronous counters preferred over ripple counters in processors?

All flip-flops change together on the common clock, so there are no temporary wrong states (glitches) and the delay does not grow with the number of bits, allowing much higher clock rates.


Summary

  • Sequential circuits = combinational logic + memory; outputs depend on present state and inputs. Synchronous circuits change state only at clock edges.

  • The SR latch (two cross-coupled NOR or NAND gates) stores one bit; S = R = 1 is forbidden (for NOR). The D latch removes it but is transparent.

  • Flip-flops are edge-triggered. Characteristic equations: SR: Q+ = S + R′Q (SR = 0); D: Q+ = D; JK: Q+ = JQ′ + K′Q; T: Q+ = T ⊕ Q.

  • Use excitation tables to design; master-slave or edge triggering removes the race-around problem.

  • Timing: fmax = 1/(tcq + tcomb + tsetup); hold time limits the shortest path.

  • Registers store words; shift registers (SISO, SIPO, PISO, PIPO) move them bit by bit.

  • Ripple counters are simple but slow and glitchy (n × tpd); synchronous counters clock all flip-flops together. Ring: n states; Johnson: 2n states.

  • Counter design: state table → excitation table → K-maps with unused states as don't-cares → self-start check.

  • With registers and combinational blocks in hand, we can now describe how data moves inside a processor, which is the subject of the next chapter, Register Transfer & Micro-operations.