Loading lessons...
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:
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 registers
| Type | Data in | Data out | Typical use |
|---|---|---|---|
| SISO | serial | serial | time delay of n clocks |
| SIPO | serial | parallel | serial-to-parallel conversion (receiving a serial line) |
| PISO | parallel | serial | parallel-to-serial conversion (sending on a serial line) |
| PIPO | parallel | parallel | ordinary storage register |
The simplest shift register is a chain of D flip-flops, each D fed by the previous Q:
4-bit shift-right 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.
| Clock | Serial in | Q0 Q1 Q2 Q3 |
|---|---|---|
| 0 | 0000 | |
| 1 | 1 | 1000 |
| 2 | 0 | 0100 |
| 3 | 1 | 1010 |
| 4 | 1 | 1101 |
- Each clock moves every bit one place right and puts the new bit in Q0.
- After 4 clocks the whole word is in the register and can be read in parallel; the first bit received is in Q3.
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.
- (a) One bit enters per clock: 4 clocks. The first bit is already at the output Q3 after the fourth clock.
- (b) The remaining three bits need three more clocks to reach Q3: 4 + 3 = 7 clocks.
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 register
| S1 S0 | Mode | Di gets |
|---|---|---|
| 0 0 | no change | Qi |
| 0 1 | shift right | Qi-1 (serial input for i = 0) |
| 1 0 | shift left | Qi+1 (serial input for i = 3) |
| 1 1 | parallel load | Ii |
A register holds 000101102 = 22. What do one shift left and one shift right (with 0 entering) give?
- Shift left: 00101100 = 44, multiplied by 2.
- Shift right: 00001011 = 11, divided by 2 (the bit shifted out is the remainder).
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:
Ring 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:
| Clock | Q0 Q1 Q2 Q3 | Decoding gate |
|---|---|---|
| 0 | 0000 | Q0' Q3' |
| 1 | 1000 | Q0 Q1' |
| 2 | 1100 | Q1 Q2' |
| 3 | 1110 | Q2 Q3' |
| 4 | 1111 | Q0 Q3 |
| 5 | 0111 | Q0' Q1 |
| 6 | 0011 | Q1' Q2 |
| 7 | 0001 | Q2' Q3 |
Johnson 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.
A control unit needs 10 non-overlapping timing signals. Compare a ring counter, a Johnson counter, and a binary counter with a decoder.
| Method | Flip-flops | Decoding |
|---|---|---|
| Ring counter | 10 | none |
| Johnson counter | 5 (mod-10) | 10 two-input AND gates |
| Binary counter + decoder | 4 (mod-10 counter) | 4-to-16 decoder (uses 10 outputs) |
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.
A 3-bit shift-right register has D0 = Q1 oplus Q2 and starts at 100. List the states.
- 100: D0 = 0 oplus 0 = 0 → 010.
- 010: D0 = 1 oplus 0 = 1 → 101.
- 101: D0 = 0 oplus 1 = 1 → 110.
- 110: D0 = 1 oplus 0 = 1 → 111.
- 111: D0 = 1 oplus 1 = 0 → 011.
- 011: D0 = 1 oplus 1 = 0 → 001.
- 001: D0 = 0 oplus 1 = 1 → 100, back to the start.
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.
// 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
endmoduleThe first five lines exercise the four modes of the universal register; the table reproduces the ring and Johnson sequences:
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 0000Key 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.
📝 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)