FPGA Beginner’s Series, 10: LEDs and Switches

In my last few blogs, I’ve taken an existing command-line tutorial and brought it up in the Xilinx ISE development environment. That’s an important first step, but now it’s time to start doing something of my own. I’ll begin simply, borrowing heavily from the example we just completed. Basically, I’m going to edit the counter back to four light-emitting diodes (LEDs) — the way it was before we modified it — and then add in some logic to “Start” and “Stop” the count
sequence being displayed on the LEDs.

Today, we are going to:

  1. Create a new project called “led_input”
  2. Use most of the code from our prior example
  3. Change a few names to better fit what we’re doing
  4. Take the two extra LEDs out of the register and turn them into independent outputs
  5. Add two switch inputs
  6. See what happens next…

You will need:

  1. Your Spartan-6 LX9 development board plugged into your computer
  2. The two LEDs with pigtail wires that we created in our earlier columns
  3. Two switches with pigtail wires soldered to them so they can be plugged into the header
    block on the FPGA board
  4. The old code from “ledflash_ISE_ver” (or the “led_input.v” file from this blog) opened in
    a text editor

To start, we need to follow the steps I outlined in an earlier column. (See: Discovering FPGAs: Bringing Up the IDE.) Start up ISE and create your empty project (Steps 1 through 4 in that prior column). The only difference so far is that this one will be named “led_input.” Next, when you open the New Source Wizard, we’ll start to see some differences. Define your ports as shown in the above image.

“CLK_66MHZ” and “USER_RESET” are the same as in our last project. The inputs “START_COUNT” and “STOP_COUNT” will be our new switch inputs. I changed the name of the port from plain “LED” to “COUNTING_LEDS” because non-descriptive names kind of drive me nuts. This is especially true in the case of something like “LED” when I also have to reference the physical light emitting diodes. “COUNTING_LEDS” is still marked as a bus, but the MSB is now 3 instead of 5.

“LED_STARTED” and “LED_STOPPED” will be the extra LEDs (you see — now I can just say “LEDs,” instead of spelling out the acronym, and not get confused) that we stuck into the header J5 in an earlier column. This time, however, they aren’t assigned to be part of the main port; instead, they will be used as visual indicators displaying the status of the two switches we are going to add.

Take a close look at the UCF (user constraints file) in the following image. It has a lot in common with the “ledflash_ISE_ver.ucf” we used in prior blogs. To create it here, go to the project menu and select “New Source.” When the New Source Wizard comes up, choose “Implementation Constraints File” and again, name it, “led_input.” Finally, enter the constraints code shown in the image below:

Programmable Planet whats next - led_input UCF

The switch “START_COUNT” will go into pin 4 of header J4, while switch “STOP_COUNT” will be plugged into pin 10 of J4. Pin 4 on the header is connected to pin E18 on the FPGA chip, while pin 10 on the header is connected pin F18 on the FPGA. Both of these pins are in the 3.3 volt section of the FPGA. There are no hardware pull-down resistors on the board for the header pins, so we’ll indicate that we wish to activate these in the FPGA via the UCF employing the same technique that is used for the “USER_RESET” signal.

We’ll finish this up in my next blog, but before we move on, take a look at the hardware we’ll be using. The red square switch is a push-on / push-off switch, which connects between pins 4 and 6 of header block J4.

Programmable Planet whats next - switches and leds

The black round switch is a momentary contact, connecting between pins 12 and 10 of J4. The
LEDs, as in our earlier columns, connect between pins 4 and 5 and between pins 10 and 11 of
header block J5.

Programmable Planet whats next - header blocks