by Joe Pardue
Follow along with this
series! Joe’s book & kits
are available at
A Little Shifty
Last month, we finished looking at the AVR memory
architecture and wrote a bootloader that lets us upload
programs to an AVR without having an external programmer.
One of the things we learned in the memory series is that
the AVR was designed around Flash EEPROM for program
memory. Flash memory is great stuff and you probably
have a few billion bytes of it in the form of media cards
sitting around in odd places like your cell phone, digital
camera, or music player. In addition to the ubiquitous
media cards, Atmel has a family of ICs called DataFlash
that allow you to use Flash in your circuit designs. Both
the media cards and the DataFlash have something in
common: they can be written to or read from using the
SPI (Serial Peripheral Interface) bus which is probably the
simplest serial communications protocol around.
In the next few Workshops, we will progress to using
external Flash memory via SPI, but first we will learn about
shift registers which lead logically to SPI. The shift registers
we are using could be used with AVR hardware SPI, but
we will first write our own software to use our shift registers
mainly to show how easy it is and to help understand how
these things work. We will look at the 74HC595 eight-bit
serial-in-parallel-out and the 74HC597 eight-bit parallel-in-serial-out ICs. [We could also use the 74HC164 74HC165
pair, but the boat left the dock before I realized I had
those lying around.] Finally this month, we will apply these
chips to create yet another Cylon Eyes display, but this
time we will have 16 LEDs to sweep and a full eight-bit
DIP switch to allow the user to change the LED patterns.
Instead of having to use 24 pins as we would if we did this
parallel, we only use four of our AVR I/O pins.
■ FIGURE 1. Butterfly with Shift Registers.
If you’ve had the good fortune of taking a college
level course in digital logic, then you already know a lot
about shift registers and their basic element: the flip-flop.
These circuits are fundamental to the entire digital
revolution and if you want to really understand how all
your digital electronic servants work, you are going to need
to understand these guys. Since our goal at this point is
just to use them, I’ll leave the gory details to your Google
self-education program and glide over the fundamentals.
A flip-flop is a circuit that can remember a bit state;
either 0 or 1. The most common type of flip-flop is the D
or delay flip-flop that records the input bit state on the rising
edge and puts that value on the output on the falling edge.
Prior to the falling edge, the output is the previous bit state.
The rising or falling edge allows us to create a serial shift
register with D-type flip-flops arrayed in a sequence such that
each input records the prior flip-flop’s output on the rising
edge, then puts that value on its output on the falling edge.
This is shown in Figure 2. [Caveat: Not all flip-flops
work exactly the same.] You could do this equally well by
having the reverse clock logic if the design calls for it.
Each of the flip-flops will also have a clear pin so that you
can set them all to 0 at once. When you string eight flip-flops together, then you consider the input of the flip-flop