Shift Registers

74HC595 Shift registers

8-bit shift registers are a common, cheap, and simple way to to increase the number of outputs available to a microcontroller. They can be thought of more abstractly as serial to parallel converters - that is, they take a serial signal in and use it to set a number (frequently 8) of outputs. But this is, of course, at something of a tradeoff. In addition to adding cost (they aren't free, after all) and complexity (more chips which need power, code, etc.), shift registers trade time for outputs. Since data must be sent to a register serially, it takes significantly longer (though not, of course, to our achingly slow human senses) to change outputs on a shift register than a microcontroller's native IO pins. LED indicators? Sure. High speed serial data? Not a chance. 

Now that we're about to start getting into specifics, this article will deal specifically with '595' type 8-bit shift registers (such as this SN74HC595N 8-bit register; datasheet), though there are doubtless numerous other registers out there. Many of a shift register's operating principles relate fairly closely to its name. An incoming bit will determine the state of the register's 0th pin, while the register's existing data will get 'shifted' back to accommodate the new bit - the 6th pin's state becomes the 7th's, the 5'ths becomes 6th's, and so on. Data at the 'end' (7th pin, in this case) gets shifted 'out' of the chip's output (usually labeled Q7' or Data Out). So with a single chip, 'shifting in' or sending via serial a new byte will entirely overwrite the register's previous contents, which get shifted out of existence. This is the way shift registers are typically used in this context of expanding a microcontroller's outputs - each time a programmer wants to change a shift register's outputs, a new byte will be generated which contains the desired pin states and then sent to the register, allowing the details of the register's operation to be abstracted away from its utility: expanding a controller's outputs.

Multiple shift registers

But what if you need more than 5 more pins (it takes 3 to operate an 8 pin shift register)? What if you need 13, or 21, or 80? Well, remember those bits which get shifted out of existence every time something new is written to a shift register? They don't have to be wasted. You see, shift registers can be daisy chained. Daisy chaining is when lots of the same thing are plugged into each other. For example, you might have daisy chained power strips or garden hoses if none of them were long enough, or USB hubs if one didn't give you enough ports. In the same way, shift registers can be daisy chained by plugging the output of one register into the input of another (the clock, latch, and other control lines can just be connected together in parallel) so those bits which would otherwise get shifted out of existence instead get shifted into another shift register. So instead of just sending 1 byte for 1 register, you could send 10 bytes for 10 registers (or even more). Again, the downside is that sending 10 bytes of data takes 10 times longer than sending 1 byte, and a whole lot longer than writing to a digital IO pin. 

details

74HC595s have 7 inputs (including power) and 9 outputs (including data out). Of these outputs, there are 3 which must be connected to your microcontroller to operate the shift register - these are data in, clock, and latch. The other four inputs - power, ground, master clear, and output enable can be kept constant and the register will still operate. Like many serial standards, the shift register 'recognizes' the state the data pin is at every time the clock pin undergoes an edge transition (whether it is on a rising or falling edge I'm not sure, but unless you're writing custom code to control a register it shouldn't matter too much). This is called synchronous serial communications (as opposed to asynchronous serial) where there is a clock signal to delineate between bits on the data line. The latch pin gets pulled low during a write sequence so lights don't flash about during the write, then goes high again to turn all the inputs on. These registers are fast enough to handle anything sent over software serial, and probably anything your Arduino's hardware serial port can put out as well. They are fairly tolerant to high temperatures, as I've resoldered them a couple times and SMD versions exist (which must be soldered in a reflow oven). All of a chip's outputs can be put into high-impedance mode by bringing the Output Enable pin high (as it is an active low pin, meaning that Outputs are Enabled when this pin is low); this can be useful if the components connected to the chip need to be controlled by another device, for multiplexing, or any other situation where it is desirable for the register (or at least its outputs) to effectively drop off the circuit. The Master Clear pin is also active low, and will reset all of the register's pins when it is activated; thus, if it isn't actively controlled by a microcontroller, it must be kept high for the shift register to operate.