This project demonstrates how to use Verilog HDL with an FPGA board. In this project you will use a switch on your FPGA board to turn on an LED. In doing this, you will learn the first steps of writing Verilog code and observe how a switch can control LEDs on an FPGA board. You won't need to have a really thorough understanding of digital engineering to make this project work; however, if you would like to know the inner workings of the digital circuit, more information is available in Project 1.
|1||Digilent® Nexys™4, Nexys™3, Nexys™2, or Basys™2 FPGA Board|
|1||Xilinx ISE Design Suite: WebPACK (14.6 Recommended)|
A Digital circuit contains a power supply, devices, and conduction nets. Some nets provide the circuit with inputs from the “outside world,” while others, conversely provide information from the circuit to the outside world. The nets that provide an interface between the circuit and the outside world are called ports.
Circuits need input devices to generate input signals. Input devices can take many forms, among them keyboards (such as on a PC), buttons, and switches. Circuits also need output devices to communicate their state to the user. In this project, a switch is used as the input device and an LED is used as the output device.
The digital circuit we will build is called the “led_sw,” as shown in Fig. 1 below. The circuit created in this project will be implemented inside the FPGA board. The board has an input port called “sw,” which receives an input signal from the external switch in the circuit and an output port called “led,” which drives the external LED in the circuit. The “led_sw” is a simple circuit that bypasses the signal on the input port and directly sends information to the output port. You can view this as a direct wired connection between the net “sw” and the net “led.” The circuit will be implemented using Verilog HDL. On different FPGA boards, switches and LEDs are connected to different pins on an FPGA chip. Thus, a user constraint file (UCF) is needed to map the input and output net of the circuit to the physical pin location on the FPGA chip. Take Nexys3 as an example, the Slide Switch 0 (SW0) is connected to FPGA pin T10, and FPGA pin U16 drives LED 0 (LD0).
When you slide the switch to the ON position, a high voltage will be placed on FPGA pin T10, which is mapped to the input port of the circuit “led_sw.” The digital circuit then transmits the signal onto the output port LED, which is connected to FPGA pin U16. The high voltage on the output port “led” will cause a voltage drop between node A and node B. This voltage drop will drive current through the LED, which will light the LED and inform the user that the switch is on.
In step 1, a template has been generated by the Xilinx tools as follows:
module led_sw( output led, input sw );
In this code, you have demonstrated that the net “led” is the output and the “sw” is an input. Now it is time to implement the circuit. At this time we will use an “assign” statement in Verilog to connect the output port “led” to the input port “sw”. The “assign” statement is used so that whenever a signal is placed on the input net it will be transmitted directly to the output port.
assign led = sw;
Lastly, you must always make sure to end the module with the “endmodule” code.
When you have completed this project file it should look like this:
'timescale 1ns/1ps module led_sw( output led, input sw ); assign led = sw; endmodule
The circuit has been implemented but the Xilinx tools still need to know what physical pins on the FPGA the input and output ports are mapped to. The UCF file will give the tools for this information. Please choose your board in the dropdown menu to see the UCF file corresponding to your board, as pin locations vary from board to board:
Net "sw" Loc=T10; Net "led" Loc=U16;
You can find the location you need from the schematic of your FPGA board, or you can download the master UCF for your board from the Digilent website and copy the corresponding lines for this step.
Double-click on “Generate Programming File” to generate the bit file and download it to your FPGA board. After you program your board, you can slide on the SW0 on your board to turn on LD0.
Now that you've completed this project, try these modifications: