Do-it-yourself projects and technology updates

Decoding NES controller

Filed under: Uncategorized — Greg Lipscomb on February 3, 2006 @ 2:19 pm


Image from joystiq.com

Have you ever picked up an old NES controller, looked at the connector, and asked how can it send the data for 8 buttons over just 7 pins? You know that two pins have to be ground and +5v, so that only leaves five pins. Actually, it only uses 3 pins for data transmission.

If you look inside of a NES controller, you will see a 4021 IC. This chip is a parallel to serial asynchronous shift register. This IC will convert the 8 pin parallel inputs to a one pin serial output. What is a serial output you ask? Well a serial output is a way of sending data on just one pin, obviously. It is based off of a clock wave. Lets imagine you have a binary number. We will use the number 9, or in binary it would be 1001. Now if this binary number correspondeded to a parallel line, the outer two pins would be high volts, and the middle two would be low volts.

If you wanted to transmit this data on one pin you would need a clock signal to carry the information on. I could transmit this data to you by rasing my hand. If you flash a light at me for every second, and I raise my hand during that second for a 1, or leave my hand down for a 0, then in four seconds I would have sent you the information. This is exactly the same as serial, and this is how the 4021 works. It has two input control signals and one serial output. It also has 8 parallel inputs, which are what will be converted to the serial data. One of the inputs is a clock signal. On each clock signal, the chip will send out one bit of information. It will take 8 clock signals to send out the entire 8 bits worth of data.

Now, the 4021 chip needs to be able to know when it has finished sending all 8 bits, and when to start over again. This is where the third control line comes in. This is the pulse signal. It goes high, and tells the 4021 to start over.



You can see from this picture how this all comes together. The serial output goes low meaning that (in this example), the B button has been pressed. The next important thing is that you need to know what order the information is being transmitted. You get your pulse wave, so you need to know what to expect in order to decode it. The NES controller sends out the information in a logical manner, the order is A, B, Select, Start, Up, Down, Left, Right.

Now if you want to drive this chip, you have to provide the two clock signals going to the 4021. You can do this with a microcontroller. You would generate a pulse wave, and would also generate a clock wave. Then on each clock wave, you would read the input serial data. There is a good explanation of parallel to serial circuits at allaboutcircuits.com

One more important thing is to include the adaptor for the NES controller pin out. I got this from devcast.dcemulation.com.



In this picture you can see the +5v, the ground, the serial out, the clock, and the latch (or pulse signal)

Now for decoding this signal, It can be done two different ways. You could get an 8 bit serial to parallel chip, and drive it with a microcontroller. You could use the same microcontroller that you are driving the 4021 chip with. You can use a 74AHC594 serial in parallel out shift register with an output register. The output register holds a steady signal while the chip is obtaining new data. An example of how to do this can be found here. You could also do all of the decoding with a microcontroller. The problem with this method is that you would have to have 3 pins for controlling the 4021, and then 8 more for outputs, which restricts you to using a larger microcontroller, but the microcontroller is small, and concise. It may be a better choice, it all depends on the user and the application. An example of decoding with a microcontroller can be found here

Now finally you ask, why on earth would you want to do this. This article is not just for a NES controller. There are tons of reasons to use a serial data line. By using these two circuits, you can reduce the number of inputs going into a microcontroller. You may want to make a NES controller mod without having to hack apart the controller. You could build a USB joystick blackbox for your controller. This box would decode the serial data, and then convert it to USB. It would have a female NES plug, so that you could take any NES cotroller and connect it to a NES. It keeps you from destroying the controller, and anybody could use it.

4 Responses to “Decoding NES controller”

  1. darkeasc Says:
  2. Good night…

    First of all, let me say, I don’t speak english so good, i am Colombian, I Speak spanish!!! so I will tray to explain what I want…
    i don’t understand how to do it, my nes pad has a serial output, with 9 “pins” here the nes pad has 7 pins, can you tell me how to build a adapter to my pc whit my pad???

    Thanks, and I am sorry if you can’t understand me!!!

  3. alejandro Says:
  4. ahi te va en espaƱol, necesitas saber para que es cada cable, abre el control, lo mas seguro es que tenga el integrado 4021, busca la configuracion de este integrado y verifica para que es cada cable, forsozamente son 5 cables

  5. Nelson Says:
  6. Thanks for this article! It’s the most concise, useful one on the subject I could find on the Internet. One thing that could be clearer is that as soon as you strobe the latch, the A bit comes out, _before_ you strobe CLK. The way the diagram is drawn with “B” as the labeled bit makes it look like you need to strobe CLK before you get any data. (Of course if I were awake, I would have noticed that “B” is the second bit to come out…)

  7. Mohamad Hadi Amini Says:
  8. I want to do a simple project , I am an Electrical Engineering Bs Student

Leave a Reply