Education – 4021 Chip

The 4021 chip is a parallel in, serial out, 8-bit shift register.  That’s a lot of words to describe a single chip, so we’ll take them a little at a time.

Parallel In

This means that the chip connects to some number sources of information in parallel.  In most cases, these sources are switches or buttons of some sort.   That should make it fairly obvious why these chips are often found in joysticks.  A joystick is just a device full of buttons that you want to know the individual states of while someone is playing a game.

Serial Out

This means that the information collected from lots of buttons is transmitted out of the chip in single file.  This is handy because it means that the information from all of those buttons doesn’t need a lot of wires to send it to a video game console.

8-bit

This is the amount of storage in the chip for holding the data that came from all the buttons.  The data is arranged as one bit per parallel input on the chip and has nothing to do with how many bits the console system CPU has.

Shift Register

This describes how the data is moved inside the chip as it is requested by the connected system.  In this case, each time the data is requested the front bit is sent on its way and the remaining bits all shift one spot over toward the front.  The back is filled in with zeros.  Eventually all of the data space inside is filled with zeros and there is nothing else to retrieve.

Chaining Chips Together

In most situations, 8 bits isn’t enough.  The original NES controller has 8 buttons, so it will work perfectly, but a SNES controller has 12 buttons.  You can’t connect 12 parallel inputs (buttons) to a chip that only knows how to deal with 8, there just aren’t enough places to solder things to.  Fortunately the folks that designed this chip knew that might be a problem and made sure there was a way to chain more than one of them together.  There is a pin on the chip that can be connected to the output on another chip.  When data is read from the chip and normally the register would fill in the back of the data with zeros, it uses the output data from the next chip in line instead.  There is theoretically no limit to how many you can chain together in this way, but I’ve never tried more than two.

Latch Signal

Buttons are being pressed and released all the time on the joystick when someone is playing a game.  Logically that could have a very confusing effect on the data coming out of the register unless there is a way to prevent button state changes from screwing things up.  The way this is achieved is what is called a latch.  Essentially when a latch signal gets to the chip, it means “remember everything as it is right now, and ignore all other button presses until we are done reading all the data.”

Data Output

There is a single pin on the chip that is used to send data out from the chip.  First a latch signal is received, and then data is sent out once per clock pulse received on the clock pin.

Pin Layout

We have now covered the basic flow of information for this chip and we’ve talked about a lot of inputs and outputs, so it will now be helpful to know how they are laid out on the chip itself.  The best way to do that is with a diagram.

I consider it to be a somewhat unfortunate layout for the pins due to the inputs being all over the place, but as long as you have a map handy like the one above, you shouldn’t have any trouble connecting things to the right places.  The two pins without labels (2 and 12) don’t have anything connected to them, and in situations where you are not chaining multiple chips together, Data Input (pin 11) should be connected to ground.

This concludes our discussion about the 4021 chip and how it works, hopefully you now understand their uses and why they are often found in joysticks.