Electrical Engineering › Section U · Sequential logic › Topic U.3

Shift registers

Line up a row of flip-flops so that each passes its bit to the next on every clock edge, and you can store a number, delay a signal, or turn a stream of bits on one wire into a parallel word. That is a shift register.

Storing and shifting bits

A D flip-flop stores one bit: whatever is on D at the clock edge appears on Q and stays there. A register is a group of flip-flops sharing a clock, and its storage capacity is its number of bits. In a shift register, each flip-flop's Q output feeds the D input of the next. At every clock edge all the bits move one place along together, the first stage takes in a new bit, and the bit in the last stage is passed out. Because all the flip-flops are edge-triggered, each one captures its neighbour's old value before that neighbour changes, so the bits step along cleanly, one stage per clock.

Four ways in and out

Data can enter and leave either one bit at a time (serial) or all at once (parallel), giving four types. Serial in, serial out (SISO) delays a bit stream. Serial in, parallel out (SIPO) converts a stream into a word; the 74HC164 is an 8-bit example, and the 74HC595 adds an output register so the outputs change only when told. Parallel in, serial out (PISO) does the reverse, with a SHIFT/\(\overline{\text{LOAD}}\) control choosing between loading all inputs at once and shifting; the 74HC165 is an 8-bit example, and its load acts as soon as the control goes LOW, without waiting for a clock edge. Parallel in, parallel out (PIPO) is simply a storage register.

Worked example: loading a serial register

A 4-bit SIPO register with stages \(Q_0\) to \(Q_3\) starts cleared. Data enters at \(Q_0\) and shifts towards \(Q_3\), and the bits 1, 0, 1, 1 arrive in that order, one per clock. Writing the contents as \(Q_0Q_1Q_2Q_3\): 1. After clock 1: 1000. 2. After clock 2: 0100. 3. After clock 3: 1010. 4. After clock 4: 1101. 5. Check: the first bit to arrive has travelled to \(Q_3\) and the last sits in \(Q_0\), so reading \(Q_3\) to \(Q_0\) gives 1011, the bits in the order they were sent. The parallel word is ready after 4 clocks. A SISO register would need 4 more clocks to shift the same bits back out.

Bidirectional and universal registers

A bidirectional shift register can shift towards either end. A control input steers each stage's D input, through a small multiplexer, to its left-hand or right-hand neighbour. Shifting a binary number one place towards its most significant end doubles it, and one place the other way halves it, dropping the remainder. A universal register adds parallel load. The 74HC194 is a 4-bit universal shift register with two mode inputs \(S_1S_0\): 00 holds the data, 01 shifts right, 10 shifts left and 11 loads all four inputs in parallel. It also has an active-LOW clear and separate serial inputs for each direction.

Shift register counters

Feed the last stage's output back to the first and the register cycles through a fixed set of states instead of passing data through. A ring counter feeds \(Q_3\) straight back to \(D_0\). It must first be preset with a single 1, which then circulates: 1000, 0100, 0010, 0001, then 1000 again. An n-bit ring counter has n states, and each state is shown directly by one output being HIGH, with no decoding. A Johnson counter feeds back the complement, \(\overline{Q_3}\), instead. It has \(2n\) states, twice as many as a ring counter from the same flip-flops, and starts from all 0s, which a simple clear provides. Started in a stray code such as 0100, it would loop through 8 unwanted states instead.

Worked example: a 4-bit Johnson counter

Start a 4-bit Johnson counter, written \(Q_0Q_1Q_2Q_3\), at 0000 and clock it. At each edge the new \(Q_0\) is \(\overline{Q_3}\) and the other bits shift along. 1. 0000 becomes 1000, since \(\overline{Q_3} = 1\). 2. Then 1100, 1110 and 1111: 1s fill from the left. 3. Now \(Q_3 = 1\), so 0s fill in: 0111, 0011, 0001. 4. The next edge returns to 0000. 5. Check: that is 8 states, \(2n\) for \(n = 4\). Each state can be picked out by a single 2-input AND gate. For example, 1100 is the only state with \(Q_1 = 1\) and \(Q_2 = 0\), so it is decoded by \(Q_1\overline{Q_2}\).

Time delay

A SISO register delays a signal by a whole number of clock periods: a bit that enters the first of n stages appears at the last stage's output after n clock edges, so the delay is \(t_d = nT_{clk}\), where \(T_{clk}\) is the clock period. An 8-bit register clocked at 2 MHz, with a period of 0.5 µs, delays its input by \(8 \times 0.5\,\mu\text{s} = 4\,\mu\text{s}\). Changing the clock frequency tunes the delay, which makes shift registers useful for aligning signals that travel along paths of different lengths.

Serial-to-parallel conversion and the UART

Inside a computer, data moves in parallel words, but many links carry bits one after another on a single wire to save pins and cable. A UART, universal asynchronous receiver-transmitter, sits at each end of such a link. Its transmitter loads a byte into a PISO register and shifts it out with a start bit before and a stop bit after. The receiver spots the start bit, shifts the incoming bits into a SIPO register at the agreed rate, and hands the completed byte to the processor. Keyboard encoders work in a similar way, scanning the keys with a ring counter and storing the code of a pressed key in a register.

Symbols and troubleshooting

IEEE dependency-notation symbols draw a register as a control block with a row of identical stages below it. Labels such as C1 for the clock, an arrow for the shift direction and M for mode inputs show which inputs control which stages, so a reader can tell the function without a separate diagram. To troubleshoot a register, exercise it: apply a known pattern, such as all 1s or a single 1, clock it a known number of times and compare each output with the expected value. A stage that never changes, or one that copies the wrong neighbour, points to a stuck output, an open connection or a missing clock at that stage.

Common mistakes to avoid

First, reading a serially loaded word in the wrong order: the first bit sent ends up in the last stage. Second, forgetting that an n-bit SISO register needs n clocks to fill and n more to empty. Third, starting a ring counter without its preset: all 0s circulate as all 0s forever. Fourth, confusing the two counters: a ring counter has n states, a Johnson counter \(2n\). Fifth, using a latch-based register: transparent latches would let a bit race through several stages in one clock.

Key takeaways

A shift register is a chain of D flip-flops that moves its bits one stage per clock. The four types are SISO, SIPO, PISO and PIPO. Bidirectional registers shift either way, and universal registers such as the 74HC194 also load in parallel. Feedback makes counters: a ring counter has n states and needs a preset; a Johnson counter has \(2n\) states and decodes each with a 2-input gate. A SISO register delays a signal by \(nT_{clk}\). SIPO and PISO registers convert between serial and parallel data, as in a UART.

Flashcards

Flashcard

Shift register

Chain of flip-flops; Q of each feeds D of the next

Bits move one stage per clock.

Test your understanding

Question 1 of 5

Bits 0, 1, 1 enter a cleared 4-bit shift register at Q₀ in that order, one per clock, shifting towards Q₃. What is Q₀Q₁Q₂Q₃ after the third clock?

Question 2 of 5

How many distinct states does a 5-bit Johnson counter have?

Question 3 of 5

A 4-bit ring counter is powered up with all stages at 0 and no preset. What happens when it is clocked?

Question 4 of 5

A 16-stage SISO shift register is clocked at 4 MHz. What delay does it give?

Question 5 of 5

A 74HC194 universal shift register has its mode inputs S₁S₀ set to 11. What does the next clock edge do?

← Previous topicNext topic →