Introduction

A register is a bank of flip-flops sharing a clock, often with load, clear and shift controls. A counter is a register whose state sequence follows a counted order.

GATE asks for the state sequence and modulus of a given counter circuit (for example a shift register with feedback), ripple versus synchronous designs and their maximum clock rates, ring and Johnson counters with their unused states, mod-NN counters by reset or load, and shift-register contents after a number of clocks.

Prerequisites

Core concepts

Registers

  • Parallel-load register: DiD_i equals either the external input (when Load=1\textit{Load}=1) or QiQ_i (hold), selected by a 2:1 MUX in front of each flip-flop.
  • Shift register: serial-in serial-out (SISO), serial-in parallel-out (SIPO), parallel-in serial-out (PISO), universal (bidirectional with mode controls). Loading nn bits serially takes nn clocks; an nn-bit SISO register delays its input by nn clocks.
  • Shift left by one multiplies an unsigned binary integer by 2 (if no overflow out of MSB); shift right divides by 2 (floor).

Binary counters

  • Ripple (asynchronous): FF0 toggles every clock; FFii clocks from the previous FF's output. With falling-edge flip-flops, clocking from Qi−1Q_{i-1} counts up; clocking from Qi−1‾\overline{Q_{i-1}} counts down. With rising-edge flip-flops the two are swapped. Simple, but cumulative tcQt_{cQ} delays skew the bits; decoding glitches possible.
  • Synchronous: all FFs share the clock; combinational logic feeds T or JK toggles when lower bits are 1 (for up-count).

Modulus

A counter with mm distinct states in cycle has modulus mm. An nn-FF binary counter naturally has modulus 2n2^n; forcing a reset/load at a chosen code yields a smaller modulus (for example mod-6, mod-10 BCD). A mod-NN counter needs at least ⌈lg⁡N⌉\lceil \lg N \rceil flip-flops.

Ring and Johnson

  • Ring: nn FFs, one circulating hot 1; modulus nn. Needs a valid one-hot reset. It uses nn of the 2n2^n patterns, leaving 2n−n2^n - n unused; the all-zero state maps to itself, so a ring counter that loses its 1 stays at 00⋯000\cdots0.
  • Johnson (twisted ring): shift with complement of last FF fed to first; the intended cycle has modulus 2n2n. Valid states fill nn zeros with ones and then empty them. For n≥3n\ge3, the 2n−2n2^n-2n unused patterns form separate cycles, so the bare counter is not self-starting. For n=1,2n=1,2, there are no unused states. For n=4n=4, the 8 unused patterns form a second 8-state cycle unless recovery logic steers them back.
  • Each Johnson state can be decoded with one 2-input AND gate, because exactly one bit changes per step, including the wrap-around.
Asynchronous ripple versus synchronous binary counter
Figure 1. Left: 3-bit ripple counter clocking from prior Q. Right: synchronous T-FF counter with toggle enables from lower-bit ANDs.
Ring and Johnson 4-flip-flop state sequences
Figure 2. State sequences of a 4-FF ring counter (modulus 4) and a 4-FF Johnson counter (modulus 8).

How it works

Synchronous up-counter T inputs

T0=1T_0=1; Ti=Q0Q1⋯Qi−1T_i = Q_0 Q_1 \cdots Q_{i-1} for i>0i>0. Down-count uses complemented conditions: Ti=Q0′Q1′⋯Qi−1′T_i = Q_0' Q_1' \cdots Q_{i-1}'. An up/down counter with control UU uses Ti=U Q0⋯Qi−1+U′ Q0′⋯Qi−1′T_i = U\,Q_0\cdots Q_{i-1} + U'\,Q_0'\cdots Q_{i-1}'.

Ripple transients

In an up ripple counter the bits change one after another. Going from 01110111 to 10001000, Q0Q_0 falls first, which clocks Q1Q_1, and so on. The outputs pass through 01100110, 01000100 and 00000000 before reaching 10001000. A decoder on the outputs can glitch on those transient codes.

Speed limits

  • Ripple: if every bit must be settled before the next clock edge (for example to decode the count), T≥n tcQT \ge n\,t_{cQ} (plus any decoder delay).
  • Synchronous: T≥tcQ+tAND+tsuT \ge t_{cQ} + t_{\mathrm{AND}} + t_{su} with parallel AND gates for the TiT_i, independent of nn until fan-in limits force an AND chain.

Truncated sequence

Detect the unwanted state (for example 1010 for decade after 1001) and asynchronously clear, or synchronously load 0000 on the next clock. With an asynchronous clear the unwanted state appears briefly, for the clear-path delay, before the reset. Synchronous clear is preferred to avoid short glitch states. With synchronous load, the detector watches the last wanted state (1001), not the first unwanted one.

Analysing a counter circuit

Write each flip-flop's next state from its inputs, then step from the reset state until a state repeats; the cycle length is the modulus. Then check every unused state: if each one reaches the main cycle, the counter is self-starting; if some unused states cycle among themselves, it can lock out.

Universal shift-register mode table

A typical 4-bit universal shift register uses two mode bits s1s0s_1 s_0:

s1s0s_1 s_0Action
00Hold
01Shift right (serial into MSB)
10Shift left (serial into LSB)
11Parallel load

Draw the 4:1 MUX in front of each DiD_i with those four sources. If a figure omits a mode, recover it from the MUX wiring.

Synchronous decade counter

States 00000000 to 10011001 then back to 00000000. Toggle enables follow binary up-count until the detect of 10011001, which synchronously loads zero. Asynchronous clear on 10101010 is a common textbook alternative; it briefly produces 10101010 for a hazard window, so synchronous designs are preferred in questions that mention glitch-free decimal outputs.

Algorithms and pseudocode

Arrays are 0-indexed; <- is assignment.

Text
SYNC-UP-NEXT(Q[0..n-1])
1  T[0] <- 1
2  for i <- 1 to n-1
3      T[i] <- AND of Q[0..i-1]
4  for i <- 0 to n-1
5      Q[i] <- Q[i] XOR T[i]
6  return Q

JOHNSON-NEXT(Q[0..n-1])
1  nin <- NOT Q[n-1]
2  for i <- n-1 downto 1
3      Q[i] <- Q[i-1]
4  Q[0] <- nin
5  return Q

MODULUS-AND-SELF-START(next, s0, all_states)
1  seen <- [s0]; s <- next(s0)
2  while s not in seen: append s to seen; s <- next(s)
3  cycle <- seen from the first occurrence of s
4  for each u in all_states not in cycle
5      walk u, next(u), ... for at most |all_states| steps
6      if the walk never enters cycle then return (|cycle|, not self-starting)
7  return (|cycle|, self-starting)

The analysis visits each of the 2n2^n states at most 2n2^n times, O(4n)O(4^n) steps, trivial for exam sizes.

Mathematical explanation

Counters are cyclic FSMs. Binary counting implements +1 mod 2n+1 \bmod 2^n in the state encoding. Bit ii toggles exactly when bits 00 to i−1i-1 are all 1, which is when adding 1 carries into position ii; this is the synchronous TiT_i. It also means bit ii has period 2i+12^{i+1} clocks.

Johnson codes are 2n2n of the 2n2^n possible patterns, and successive codes differ in exactly one bit, including the step from the last back to the first. For n≥3n\ge3, unused patterns exist and cannot reach the valid cycle on their own, because the Johnson next-state map is a bijection: each pattern has exactly one predecessor, so the state graph is a set of disjoint cycles.

Worked examples

Example 1: mod-8 sequence

000,001,010,011,100,101,110,111,000,…000,001,010,011,100,101,110,111,000,\ldots

Example 2: Johnson n=3n=3

000,100,110,111,011,001,000,…000,100,110,111,011,001,000,\ldots (six states). The two unused patterns, 010010 and 101101, map to each other: 010→101→010010 \to 101 \to 010.

Example 3: mod-6 with sync clear

Count 0..50..5; when state is 5, next load 0. Natural 3-FF codes use 000..101; 110 and 111 unused (lock detection may force reset). With an asynchronous clear instead, the detector is Q2Q1‾\overline{Q_2 Q_1} driving an active-low clear: state 110 appears for the clear delay and then becomes 000.

Example 4: ripple delay

If each FF has tcQ=5 nst_{cQ}=5\,\mathrm{ns}, a 4-bit ripple needs up to 20 ns20\,\mathrm{ns} after the clock before all bits settle, so the clock must not exceed 50 MHz50\,\mathrm{MHz} if the count is decoded every cycle. A synchronous 4-bit counter with tcQ=5t_{cQ} = 5, a 2 ns AND and tsu=3t_{su} = 3 ns runs at 1/10 ns=100 MHz1/10\,\mathrm{ns} = 100\,\mathrm{MHz}.

Example 5: a shift register with feedback

Three D flip-flops form a shift register Q2←Q1Q_2 \leftarrow Q_1, Q1←Q0Q_1 \leftarrow Q_0, with Q0←Q1+Q2‾Q_0 \leftarrow \overline{Q_1 + Q_2}. From 000000 (written Q2Q1Q0Q_2Q_1Q_0) the states are 000→001→011→110→100→000000 \to 001 \to 011 \to 110 \to 100 \to 000: modulus 5. The unused states 010010, 101101 and 111111 go 010→100010 \to 100, 101→010101 \to 010 and 111→110111 \to 110, all into the main cycle, so the counter is self-starting.

Example 6: shift-register contents

A 4-bit shift-right register holds 10111011 (MSB on the left) with serial input 0. After two clocks it holds 00100010; after four clocks, 00000000. Feeding the serial output back to the input instead (a rotate) returns 10111011 after four clocks.

Example 7: Johnson n=4n = 4 lock-out

The valid cycle is 0000,1000,1100,1110,1111,0111,0011,00010000, 1000, 1100, 1110, 1111, 0111, 0011, 0001. Starting from the unused 01000100: 0100→1010→1101→0110→1011→0101→0010→1001→01000100 \to 1010 \to 1101 \to 0110 \to 1011 \to 0101 \to 0010 \to 1001 \to 0100, a second cycle of 8 that never meets the valid one.

Important properties and observations

  • Frequency at FFii of a binary counter is fclk/2i+1f_{\mathrm{clk}}/2^{i+1}.
  • BCD decade counter: modulus 10; outputs weight 8421.
  • Universal shift register control words select hold, shift L/R, or parallel load.
  • Unused-state counts: ring 2n−n2^n - n, Johnson 2n−2n2^n - 2n; a 4-bit ring leaves 12, a 4-bit Johnson leaves 8.
  • A Johnson counter with nn FFs divides the clock by 2n2n at any single output.

Common misconceptions.

  • "Ring counter modulus is 2n2n." That is Johnson; ring is nn.
  • "Ripple is always slower to the MSB only." Intermediate decoding also glitches.
  • "Unused states cannot occur." Power-up can enter them; design recovery.
  • "Johnson counters are self-correcting for every size." For n at least 3, unused states form separate cycles and the plain design locks out. For n=1 or 2, all states belong to the intended cycle.
  • "Clocking each stage from QQ always counts up." That depends on the active edge.

GATE examination perspective

  • MODULUS. Count distinct cyclic states, not number of FFs alone.
  • NEXT STATE. Given a figure, compute the following state; step until a state repeats.
  • SELF-STARTING. Trace every unused state.
  • RING VS JOHNSON. nn vs 2n2n; unused 2n−n2^n - n vs 2n−2n2^n - 2n.
  • RIPPLE VS SYNC. n tcQn\,t_{cQ} versus tcQ+tAND+tsut_{cQ} + t_{\mathrm{AND}} + t_{su}; transient codes in ripple counters.
  • EDGE AND DIRECTION. Falling-edge FFs clocked by QQ count up.

Summary

Sources

  1. M. Morris Mano, M. D. Ciletti, Digital Design, 5th ed., Pearson, 2013: Chapter 6, Sections 6.1 to 6.5 (registers, shift registers, ripple counters, synchronous counters, other counters).

Next steps