Lesson 22 +35 XP

Registers, Shift Registers, Ring & Johnson Counters

Registers, Shift Registers, Ring & Johnson Counters

A register is a group of flip-flops that stores a binary word, one flip-flop per bit, all sharing one clock. A shift register also moves its bits one position left or right on every clock. Shift registers convert between serial and parallel data, multiply and divide by 2, delay signals, and, with feedback, become the ring and Johnson counters.

1. Registers with Parallel Load

A 4-bit register is four D flip-flops with a common clock. To make it keep its value when nothing should be loaded, each D input gets a 2-to-1 multiplexer:

Di = Load · Ii + Load' · Qi

With Load = 1 the inputs Ii are stored on the next edge; with Load = 0 each flip-flop reloads its own output and the word is held. This is better than gating the clock, which causes timing problems. The registers AR, PC, DR and AC of the basic computer (Unit III) are built this way.

2. Shift Register Types

SISO, SIPO, PISO and PIPO shift registersSISO, SIPO, PISO and PIPO shift registers

TypeData inData outTypical use
SISOserialserialtime delay of n clocks
SIPOserialparallelserial-to-parallel conversion (receiving a serial line)
PISOparallelserialparallel-to-serial conversion (sending on a serial line)
PIPOparallelparallelordinary storage register

The simplest shift register is a chain of D flip-flops, each D fed by the previous Q:

4-bit shift-right register4-bit shift-right register

SolvedExample 1 · Shifting a word into a SIPO register

A 4-bit shift-right register starts at 0000. The serial input receives 1, 0, 1, 1 (in that order) on four clocks. Show the contents after each clock.

ClockSerial inQ0 Q1 Q2 Q3
00000
111000
200100
311010
411101
  1. Each clock moves every bit one place right and puts the new bit in Q0.
  2. After 4 clocks the whole word is in the register and can be read in parallel; the first bit received is in Q3.
Answer1101 after the fourth clock (read Q3 Q2 Q1 Q0 = 1011, the order sent)
SolvedExample 2 · Clocks needed for serial transfer

How many clocks does a 4-bit SISO register need to (a) take in a 4-bit word and (b) take it in and deliver all of it at the serial output? Generalise to n bits.

  1. (a) One bit enters per clock: 4 clocks. The first bit is already at the output Q3 after the fourth clock.
  2. (b) The remaining three bits need three more clocks to reach Q3: 4 + 3 = 7 clocks.
Answern clocks to load, 2n - 1 clocks until the last bit appears at the output (7 for n = 4)

3. Bidirectional and Universal Shift Registers

A bidirectional shift register can shift left or right. A universal shift register (like the 74194) can also hold and load in parallel. Each stage has a 4-to-1 multiplexer in front of its D flip-flop, controlled by two mode bits:

One stage of a universal shift registerOne stage of a universal shift register

S1 S0ModeDi gets
0 0no changeQi
0 1shift rightQi-1 (serial input for i = 0)
1 0shift leftQi+1 (serial input for i = 3)
1 1parallel loadIi
SolvedExample 3 · Shifting as arithmetic

A register holds 000101102 = 22. What do one shift left and one shift right (with 0 entering) give?

  1. Shift left: 00101100 = 44, multiplied by 2.
  2. Shift right: 00001011 = 11, divided by 2 (the bit shifted out is the remainder).
Answer44 and 11; shifting left k places multiplies by 2k, shifting right divides by 2k (for unsigned numbers)

4. Ring Counter

Connect the last output back to the first input (D0 = Q3) and preset the register to a single 1 (1000). The 1 circulates:

1000 → 0100 → 0010 → 0001 → 1000

Ring counter and Johnson counterRing counter and Johnson counter

  • n flip-flops give a mod-n counter (n states out of 2n).
  • Each state has exactly one 1, so the state is already decoded: Qi = 1 means "step i". This makes ring counters ideal as timing-signal generators (T0, T1, T2, dots in the control unit of Unit III).
  • It must be initialised: from 0000 it stays at 0000 forever.

5. Johnson (Twisted-Ring) Counter

Feed back the complement of the last output (D0 = Q3') and start at 0000. A wave of 1s fills the register, then a wave of 0s:

ClockQ0 Q1 Q2 Q3Decoding gate
00000Q0' Q3'
11000Q0 Q1'
21100Q1 Q2'
31110Q2 Q3'
41111Q0 Q3
50111Q0' Q1
60011Q1' Q2
70001Q2' Q3

Johnson counter waveformsJohnson counter waveforms

  • n flip-flops give a mod-2n counter, twice as many states as a ring counter.
  • Every state is decoded by a single 2-input AND gate on two adjacent bits.
  • Only one bit changes per clock (like Gray code), so the decoded outputs are glitch-free.
  • The other 2n - 2n states are unused. A noise pulse can push the counter into an unused cycle (for n = 4: 0100 → 1010 → 1101 → 0110 → ...), and it would cycle there for ever. Practical designs therefore add a reset, or a small correcting gate in one feedback path that steers every unused state back into the main cycle.
SolvedExample 4 · Ring vs Johnson for 10 timing states

A control unit needs 10 non-overlapping timing signals. Compare a ring counter, a Johnson counter, and a binary counter with a decoder.

MethodFlip-flopsDecoding
Ring counter10none
Johnson counter5 (mod-10)10 two-input AND gates
Binary counter + decoder4 (mod-10 counter)4-to-16 decoder (uses 10 outputs)
Answerring = most flip-flops, no gates; Johnson = half the flip-flops, simple 2-input gates; binary = fewest flip-flops, biggest decoder

6. Linear Feedback Shift Register (LFSR)

If the feedback is the XOR of some outputs, the register steps through a long pseudo-random sequence. This is used for test-pattern generation, scrambling and CRC checks.

SolvedExample 5 · A 3-bit LFSR

A 3-bit shift-right register has D0 = Q1 oplus Q2 and starts at 100. List the states.

  1. 100: D0 = 0 oplus 0 = 0 → 010.
  2. 010: D0 = 1 oplus 0 = 1 → 101.
  3. 101: D0 = 0 oplus 1 = 1 → 110.
  4. 110: D0 = 1 oplus 0 = 1 → 111.
  5. 111: D0 = 1 oplus 1 = 0 → 011.
  6. 011: D0 = 1 oplus 1 = 0 → 001.
  7. 001: D0 = 0 oplus 1 = 1 → 100, back to the start.
Answer7 states (all except 000): a maximal-length sequence of 23 - 1; 000 must be avoided because it locks up

7. Shift Registers and Ring Counters in Verilog

The vectors are declared [0:3] so that printing shows Q0 first, matching the tables. Shifting is just concatenation: {sir, q[0:2]} shifts right, {q[1:3], sil} shifts left.

VERILOG
// Universal shift register (like the 74194) plus ring and Johnson counters.
// Bits are declared [0:3] so that %b prints Q0 Q1 Q2 Q3 from left to right.
module univ_shift (
    input            clk,
    input            rst_n,
    input      [1:0] s,         // 00 hold, 01 shift right, 10 shift left, 11 load
    input            sir,       // serial input for shift right (enters Q0)
    input            sil,       // serial input for shift left (enters Q3)
    input      [0:3] d,
    output reg [0:3] q
);
    always @(posedge clk or negedge rst_n) begin
        if (!rst_n)
            q <= 4'b0000;
        else
            case (s)
                2'b00: q <= q;
                2'b01: q <= {sir, q[0:2]};
                2'b10: q <= {q[1:3], sil};
                2'b11: q <= d;
            endcase
    end
endmodule

module ring_johnson (
    input            clk,
    input            rst_n,
    output reg [0:3] ring,
    output reg [0:3] john
);
    always @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            ring <= 4'b1000;            // a ring counter must start with a single 1
            john <= 4'b0000;
        end else begin
            ring <= {ring[3], ring[0:2]};       // Q3 -> D0
            john <= {~john[3], john[0:2]};      // Q3' -> D0
        end
    end
endmodule

module tb;
    reg clk = 0, rst_n = 0, sir = 0, sil = 0;
    reg [1:0] s = 2'b00;
    reg [0:3] d = 4'b1011;
    wire [0:3] q, ring, john;
    integer i;

    univ_shift   u1 (.clk(clk), .rst_n(rst_n), .s(s), .sir(sir), .sil(sil), .d(d), .q(q));
    ring_johnson u2 (.clk(clk), .rst_n(rst_n), .ring(ring), .john(john));

    task step(input [1:0] mode, input r, input l, input [8*16:1] what);
        begin
            s = mode;
            sir = r;
            sil = l;
            #5 clk = 1;
            #5 clk = 0;
            $display("%0s Q0..Q3 = %b", what, q);
        end
    endtask

    initial begin
        #1 rst_n = 1;
        step(2'b11, 0, 0, "load 1011:     ");
        step(2'b01, 0, 0, "shift right, 0:");
        step(2'b01, 1, 0, "shift right, 1:");
        step(2'b10, 0, 1, "shift left, 1: ");
        step(2'b00, 0, 0, "hold:          ");
        rst_n = 0;
        #1 rst_n = 1;
        $display("clock  ring  Johnson");
        for (i = 0; i <= 8; i = i + 1) begin
            $display("  %0d    %b  %b", i, ring, john);
            #5 clk = 1;
            #5 clk = 0;
        end
    end
endmodule

The first five lines exercise the four modes of the universal register; the table reproduces the ring and Johnson sequences:

OUTPUT
load 1011:      Q0..Q3 = 1011
shift right, 0: Q0..Q3 = 0101
shift right, 1: Q0..Q3 = 1010
shift left, 1:  Q0..Q3 = 0101
hold:           Q0..Q3 = 0101
clock  ring  Johnson
  0    1000  0000
  1    0100  1000
  2    0010  1100
  3    0001  1110
  4    1000  1111
  5    0100  0111
  6    0010  0011
  7    0001  0001
  8    1000  0000
💡 Tip

Key points to remember

  • Register with load: Di = Load · Ii + Load' · Qi.
  • SISO, SIPO, PISO, PIPO; an n-bit SISO needs n clocks to fill and 2n - 1 to deliver every bit.
  • Universal shift register: 4-to-1 MUX per stage; S1S0 = 00 hold, 01 right, 10 left, 11 load.
  • Ring counter: D0 = Qn-1, mod-n, self-decoding, must be preset to one 1.
  • Johnson counter: D0 = Q'n-1, mod-2n, decoded by 2-input ANDs.
🎯 END-TERM EXAM PREP

📝 IPU End-Term Exam Corner (5-10 Marks)

  • Q1. What is a shift register? Explain SISO, SIPO, PISO and PIPO shift registers with diagrams. (10 Marks)
  • Q2. Draw and explain a 4-bit universal shift register. (10 Marks)
  • Write: four stages, each a 4-to-1 MUX feeding a D flip-flop; the mode table; serial inputs for left and right.
  • Q3. Design a 4-bit ring counter and a 4-bit Johnson counter. Give their state tables and timing diagrams. (10 Marks)
  • Q4. Give the decoding logic for each state of a 4-bit Johnson counter. (5 Marks)
  • Q5. Compare ring and Johnson counters. How many states does each give with n flip-flops? (2.5 Marks)