|
|
|
Lab 2 Tutorial - Introduction to Arithmetic and IP CoresBy now, you should be familiar with the following concepts, introduced in the first two labs.
In addition to the concepts listed above, this lab will introduce you to several new concepts, including the following:
As this lab will cover a substantial amount of material, you may wish to print out this tutorial so that you can quickly refer back to it during the course of the lab. This tutorial will be broken down into a sequence of easy-to-follow
steps. For the first part of this tutorial we will be concerned
with the design and implementation of a binary subtractor circuit
using Xilinx and VHDL. Part I: Developing in VHDL -- The Binary Subtractor. All serious hardware development done nowadays is done using various Hardware Design Languages (HDLs), such as Verilog, or VHDL. The HDL permits the engineer to describe highly complex logic systems for prototyping on programmable logic, such as an FPGA or a PLD/CPLD, or direct implementation on silicon using an ASIC (Application-Specific Integrated Circuit). The hardware description language we will be using throughout this course is VHDL. This course is not a VHDL course. What you will recieve is a basic introduction to VHDL as it applies to basic digital logic design. Creating a Project: Before we can implement a binary subtractor using VHDL, first we
need to create a project. Find and double-click the Project Navigator
icon on the desktop. This will launch the Xilinx ISE software.
Once you click on Ok, you will find yourself back in Project Navigator. From here, you will need to create the VHDL code which is required to make the project work. There are two ways to do this. One will require that you be able to create the code from scratch. The other will create the ports and entities for you. However, before you can take the easy way, you should do the footwork at least once. Here, we will take you through the steps necessary to create a working VHDL project. First, click on the New File icon on the icon bar (this would be the icon that looks like a blank sheet of paper.) On the right side of the screen, you will notice that a new window has been opened.
Basic VHDL -- Libraries and Entities. The tutorial will break the code into parts in order to explain them. You can find the full code that you should paste into your project after the explanation.. library IEEE; These first two lines are library statements. In other programming languages, such as C/C++, this would be like the #include statements found at the beginning of a program. When you write VHDL, what you are describing are actual instances of hardware you would be programming onto a PLD, or etching onto actual silicon in an ASIC. The two fundamental building blocks for each instance of hardware is the entity, and it's accompanying architecture. The entity is used to describe the inputs and outputs for the circuit, as defined in a port statement. The architecture statements, describe how the hardware is supposed to work. For our subtractor, we will need to define both the subtractor entity, and it's accompanying architecture. entity subtraction is Here, we have defined the subtractor entity. Inside the entity is the port statement, which describes all the inputs and outputs to the device. A brief description follows: in STD_LOGIC Single input pin. With our hardware entity declared, we must now define it's behavior. As you analyze the case statement look at the truth table listed below it. architecture subtraction_arch of subtraction
is Recall the 4-to-1 MUX you learned about in the lab lecture. Here, our two control lines S1 and S2 would be XY_IN, and our output pin would be connected to DIV_OUT. With each case, we would select one of four possible valid inputs. However, we are not done yet. Remember that our subtractor has two outputs. We have defined only the first one. We now need to define the second output, the BROW_OUT. Before we do so, here is the truth table developed in the lecture notes:
When X and Y are both true or false (00, or 11): The output
is BROW_IN With these hints in mind, examine the next bit of VHDL code. You will need to fill in the blank, denoted by five red stars. Here are a couple of hints: A simple true is denoted by '1' -- 4 to 1 multiplexer design with case
construct OUT_BROW:
end process; Do you have the blanks filled in? Do they look like the following? OUT_BROW:
end process; Here is the complete code to paste into your project: library IEEE; entity subtraction is architecture subtraction_arch of subtraction
is
end process; -- 4 to 1 multiplexer design with case
construct
end process; You will need to save this file. Click on the Save File icon. You will get a dialog box that looks like this:
Now, we are only halfway done. We have a VHDL design that has correct syntax and style. Unfortunately, we have only the slightest clue that it is going to work the way we want it to. To remedy this, we will need to simulate the design, and in order to do this, we will need to add another VHDL file to your project, a ModelSim testbench. Verifying Your Design -- Testbenches and Simulation . You will need to click on the New File icon once again to create a new blank file. Writing a VHDL testbench will be a little different from writing a simple VHDL source file, as you will see later on. The tutorial will explain the code in sections and you can find the complete code after the explanation. LIBRARY IEEE; --Declaration of ModelSim libraries used
As you can see, in order to properly implement the testbench, we needed to include several more libraries. And note, for the testbench, the testbench entity is left blank. ARCHITECTURE testbench_arch OF testbench IS COMPONENT subtraction What we have just defined is a component inside the testbench entity. This would be like a function in a C/C++ program, complete with it's own inputs and outputs. This is what we want to simulate. Notice that while we now have the component we want to simulate, we have nothing to simulate yet. This defined in the next few lines of code: SIGNAL br_in : std_logic; These signals will show up when we run the simulation itself. We now need to define some of the basic simulation parameters, and assign which simulation signal is connected to which input or output on the component we wish to simulate. The following lines of code accomplish this. --Defining the variable "CLK_PERIOD"
to be BEGIN ); Now we have assigned the inputs and outputs for our subtractor to the appropriate signals in the simulation, and we have defined a basic clock. The next section of code will define the behavior of each of the input signals in the simulation. All we will be doing here is cycling through all the possible combinations of inputs with each clock cycle. --Two separate processes that provide
for the two
end process; --Clock for XY_IN
end process; END testbench_arch; Notice here that with each clock pulse, the simulation should cycle through all the possible input combinations. Here is the complete testbench code. LIBRARY IEEE; --Declaration of ModelSim libraries used
ARCHITECTURE testbench_arch OF testbench IS COMPONENT subtraction
END COMPONENT; SIGNAL br_in : std_logic; --Defining the variable "CLK_PERIOD"
to be BEGIN
--Two separate processes that provide
for the two
end process; --Clock for XY_IN begin
end process; END testbench_arch; Again, you will need to save this new file. You must name it subtract_tb.vhd. Th is serves to remind you that this file will be a ModelSim testbench.
Simulate Behavioral VHDL Model Before we go on, notice that if you click on your subtract.vhd source in the Sources in Project window, you will see that all the options for that file will appear in the Processes for Current Source window, and vice-versa. Now, make sure that subtract_tb.vhd is highlighted in the first window, and double-click on Simulate Behavioral VHDL Model in the second window. When you do that, Xilinx will launch the ModelSim software. After some time, you will find several new windows have been spawned on your Taskbar. Locate the one labeled wave - default and expand it. Initially, it will be zoomed in far too much for you to see anything useful. To solve this problem, click on the Zoom drop-down menu, and select Zoom Full. You will now see the entire simulation from start to finish. Now, you can zoom in once or twice (using the magnifying glass with the '+' in the center) to see something useful.
You can now take the bold cyan line and drag it through the simulation, observing the inputs and outputs as they change over time. Take a moment to verify that the subtractor is working, that is, that the div_out and the br_out outputs match what you have on the Karnaugh-maps and truth tables. Now, you will have a chance to modify the testbench. The current testbench, as neat as it is, will not give us quite the demonstration of the subtractor's functionality that we are looking for. For better results, we would want to cycle through all four possible combinations of the xy_in input while the br_in input is low, and then cycle through the four combinations again, with the br_in input being high this time. Find the window marked ModelSim XE 5.6a and close it. This will cause you to exit ModelSim and return to Project Navigator. Click on the window containing your subtract_tb code . There, you must modify CLOCK: process so that instead of waiting for just one clock-cycle, it waits for four clock-cycles. (Hint: Like in C/C++, you can simply add *4 to each CLK_PERIOD in order to expand the number of clock-cycles it has to wait.) When you have done this, save the file and restart ModelSim. |
alnz - Last update: June 21, 2004