A 74HC595 shift register sitting on a Lithuanian 20 euro cents coin.

What is a shift register

The official explanation

Well, if you happen to read this page, you are probably wondering what a shift register is. Wikipedia manages to explain it as follows:

“a shift register is a cascade of flip flops, sharing the same clock, in which the output of each flip-flop is connected to the ‘data’ input of the next flip-flop in the chain, resulting in a circuit that shifts by one position the ‘bit array‘ stored in it, ‘shifting in’ the data present at its input and ‘shifting out’ the last bit in the array, at each transition of the clock input”

Now if this makes you blink a few times and then phase out into your private safe space, I fully understand. Even though the description is correct, us mere lesser gods in the scientific world will probably not understand much of this.

But, what is it then?

Well, in it’s simplest form and i will limit the explanation to this type of use so I will not bore you to tears, you can see a shift register as a collection of switches that you can (p)re-program and then flick all at the same time. To be more precise, a shift register allows you to give it a stream of bits using a shared clock (so that the register knows which bit in the sequence you are giving it now) and then after you are done, it will use these stored bits to put switches in the state representing the bits (1’s and 0’s, for on and off respectively).

A 74HC595 shift register sitting on a Lithuanian 20 euro cents coin.
A 74HC595 shift register sitting on a Lithuanian 20 euro cents coin.

So, let us just assume we are dealing with an 8 bit shift register. The most common type of this is the 74HC595, produced by many many IC producers, but all of them more or less the same so for small projects a cheap one made by an unknown Chinese manufacturer will do just fine. So since this is an 8 bit shift register, we know that this thing has 8 switches that we can all flick at the same time in the state we want them to be in.

For example let’s imagine that I have 8 switches in a row, and I want to flick them all in a pre-determined state at the same time. The switches are all powered, which means that if you flick a switch on, it will give you electricity (please, i’m trying to keep this simple). So if you put in a bit sequence such as ‘01100010’, then you can be sure that the second, third and seventh output pin on the shift register will turn ‘on’ at the same time, while the others will be turned ‘off’.

Wait, you said something about a clock.

Yes, in order to ‘program’ the shift register, you need to give it a sequence of 1’s and 0’s. The way to do this is by putting voltage on the serial input leg (1) or putting no voltage on the serial input leg (0). We call this pulling high or low. High being putting voltage on there (1), Low being putting no voltage on there (0). The input pin senses this difference and the shift register will interpret accordingly.

This works fine if your input is always 10101010. But what if you have two or more Highs or two or more Lows after each other. For example 10111010. For the shift register there is no telling whether this is just 6 bits, 7 bits or 8 bits, since it can not determine a difference between 1 and 1. There just isn’t any.

So to work out whether you intended to say ‘Oooooonnneeee’ or ‘one one one’ you need to agree on how long a single bit will take you to say. And this is where the clock comes in! The clock is essentially nothing more than a series of pulses coming from the device that is using the shift register.

So let’s for simplicity put it like this:

_--_--_--_--_--_--_--_--   <-- Clock signal
  1  0  1  1  1  0  1  0   <-- bit stream of 8 bits in High/Low

As you can see here the clock signal is a block wave. If you would hook that up to an oscilloscope you would see an actual block wave and the shift register uses this wave to ‘properly read’ the incoming bit stream and differ between the bits. Every time a new bit is supposed to be expected, the clock signal goes low and then high again.

Okay okay, I get it, but WHY?

Well, the reason for this is pretty simple: To save on output pins on your controller. Imagine that you have an Arduino UNO and you want to control 8 LED’s independently of each other. Sure, you could use 8 digital pins out of the 13 that you have available. No problem with that! But you lose 8 pins out of 13. What if you want to control a few stepper motors and 8 LED’s. You run out of pins really fast. And what if you want to control 16 LED’s? Exactly. That is not possible with just an Arduino. But the shift register makes this possible by allowing you to simply communicate to the shift register which pins you want to be on and off by using just 3 pins on your arduino. 1 for data, 1 for the clock and 1 to control the ‘trigger’.

But one shift register can only control 8 LED’s. What if you need 16 you might wonder? Well, these shift registers can be ‘serialized’ which means that you can use 2 of them together. For each one you add you only need 1 separate pin. This means 4 shift registers can be controlled by 6 pins on your Arduino, but those 4 shift registers together can control 32 LED’s! So controlling 32 LED’s independently from your controller while only using 6 pins instead of 32! Now that is profit! And of course it does not have to be LED’s, it can be anything, from relays to LED’s to other IC’s, SOC’s, devices and whatever more.

I hope you found this explanation useful. If there is an error in here or you have a question or just want to tell me how much of a jerk I am, please feel free to leave a note!

Happy soldering!

Leave a Reply

Your email address will not be published. Required fields are marked *