Sub topic 14
Registers, Shift Registers, Ring and Johnson Counters
Prerequisites and working model
This chapter assumes that you know binary representation, Boolean operations, and the behavior of edge-triggered flip-flops. A register is a group of flip-flops that stores a multi-bit value. An \(n\)-bit register stores \(n\) bits and changes its stored value on a clock edge.
A register can load all bits at once, called parallel loading, or move bits one position per clock, called shifting. A shift register may accept serial input and produce serial output, parallel output, or both.
Shift-register operations
Consider a four-bit register \(Q[3:0]\). On each rising clock edge, it can perform one of these operations:
| Operation | New contents |
|---|---|
| Hold | \(Q_{\text{next}} = Q\) |
| Parallel load | \(Q_{\text{next}} = D\) |
| Shift right | \(Q_{\text{next}} = \{serial\_in, Q[3:1]\}\) |
| Shift left | \(Q_{\text{next}} = \{Q[2:0], serial\_in\}\) |
The order of concatenation matters. In Verilog, {a, b} places a in the more significant positions.
module shift_register #(
parameter WIDTH = 4
) (
input clk,
input rst,
input load,
input shift_enable,
input serial_in,
input [WIDTH-1:0] parallel_in,
output reg [WIDTH-1:0] q,
output serial_out
);
always @(posedge clk) begin
if (rst)
q <= {WIDTH{1'b0}};
else if (load)
q <= parallel_in;
else if (shift_enable)
q <= {serial_in, q[WIDTH-1:1]};
end
assign serial_out = q[0];
endmoduleFor a fixed-width register, shifting by one position is equivalent to multiplying an unsigned binary value by 2 for a left shift, or dividing by 2 while discarding the remainder for a right shift. The serial bit entering the register prevents information loss only if the discarded bit is captured elsewhere.
Ring counters
A ring counter is a shift register whose last output is connected to its first input. A common four-bit sequence is:
\[ 1000 \rightarrow 0100 \rightarrow 0010 \rightarrow 0001 \rightarrow 1000 \]
Only one flip-flop is set at a time, so this is a one-hot counter. With \(n\) flip-flops, a properly initialized ring counter has \(n\) states.
A ring counter requires a valid initial state. If reset produces 0000, the feedback keeps every bit at zero. A recovery circuit can detect this invalid state and insert a 1.
Johnson counters
A Johnson counter, also called a twisted-ring counter, feeds the inverted last bit back to the first input. A four-bit counter follows a sequence such as:
\[ 0000 \rightarrow 1000 \rightarrow 1100 \rightarrow 1110 \rightarrow 1111 \]
It then clears bits one by one:
\[ 0111 \rightarrow 0011 \rightarrow 0001 \rightarrow 0000 \]
An \(n\)-bit Johnson counter has \(2n\) valid states, twice as many as a ring counter with the same number of flip-flops. Its states are easy to decode because each state contains one contiguous group of ones and zeros.
Design checks
For an \(n\)-bit ring counter, expect \(n\) states. For an \(n\)-bit Johnson counter, expect \(2n\) states. Verify the sequence from the actual shift direction and feedback connection. Many errors come from reversing the bit order or assuming that q[0] is the first stage without tracing the concatenation.
Exercise
A five-bit Johnson counter starts at 00000. How many distinct states does it have, and what is the state after five rising clock edges if the inverted most significant bit enters the least significant position?
Show answer
It has 10 states. The sequence is 00000, 00001, 00011, 00111, 01111, 11111, so after five edges the state is 11111.