Lab 2 Tutorial PDF
Lab 2 Tutorial PDF
Type in a file name lab01 for example (The file name can be different from the project
name) and select Verilog as Add file as type option.
3. To start typing in your code, Double Click the file name to edit it. The Editor window
appears and you can start your coding in this window.
4. The next step is to compile the code. In the toolbar, select the compile icon (first
icon) to compile it.
A dialog box asking Add to Project appears. Click Yes to add the file (lab01.v) to your project.
Go to Simulate>Simulate
Expand the work option and select the name of your test bench module like stim in this case.
To view simulation results select the Run All option from the toolbar in wave window.
With the ever increasing complexity of modern circuits and digital systems, it is very difficult
(almost impossible) to design the system directly on hardware (by picking up the physical up
components and placing them right away). If somehow we are able to do that, then the
verification or testing of the system takes a lot of time and we have No before-hand method to
verify the functionality of our system unless we have physical systems in our hands.
In order to overcome this problem and several other issues, the computer languages for
designing and simulating circuits have been introduced so that we can verify the functionality of
our system and modify if needed before actually producing a physical hardware system. As
opposed to our conventional computer programming languages (in which we are programming
the Computer, the existing hardware), the languages used to design circuits are essentially
defining and describing the new hardware we want to produce so these languages are termed
as Hardware Description Languages and fall in category of low-level programming languages.
Although most of the HDLs are used for digital circuits, yet there are some modifications which
allow analog components to be included is design as well.
The two major versions of HDL are VHDL and Verilog HDL. We would be using the Verilog
HDL or Verilog in this course. The software we would be using for compiling and simulating
Verilog is ModelSim SE 5.7f. To get familiar with the ModelSim you may refer to tutorial
Getting Started with ModelSim. This tutorial covers the introduction to Verilog and gate level
programming (to be explained later).
Gate Level Modeling (using the basic gates and, or, Not, etc to and their inter-connection to
describe the whole system)
Dataflow Modeling (defining the flow of data among different components of design using
operators, No interconnection between gates needed)
Behavioral Modeling (defining the overall behavior of system like if input is x then output is y)
There is yet aNother abstraction level Switch Level Modeling in which the transistor level of
hardware is dealt with. It is a very complex level and is only used in critical applications or part
of a system. In this course we will be dealing with the first 3 only.
Verilog is a modular language which means the basic component of a Verilog code is a module
or in other words our Verilog code consists of one or more modules and these modules call
each other to perform the desired functionality. Let us start with writing a simple Verilog code
for designing and simulating a two input OR gate. We will be using ModelSim for compiling and
simulating our Verilog Code.
Before beginning the following section make sure that you have read the manual Getting
Started with ModelSim 5.7f.
task1
in1 out
in2
#100 IN1=1'b1;IN2=1'b0; #100 denotes a delay of 100ns or whatever your timescale is defined. By
default, in most of the simulators it is in ns.
#100 IN1=1'b1;IN2=1'b1;
We are giving the values to inputs IN1 and IN2 in a logical manner as we
end
did in hardware or while making truth table. You may give them in any
endmodule order.