Professional Documents
Culture Documents
EXPERIMENT NO. : 14
Objective:
This laboratory assignment introduces the Verilog Hardware Description Language
(HDL) and shows you how to model and simulate basic combinational circuits. HDLs,
such as, Verilog, are used extensively in the process of designing and implementing
digital computer hardware.
Theory:
Verilog:
Verilog is a great low level language. Structural models are easy to design and
Behavioral RTL code is pretty good. The syntax is regular and easy to remember. It is the
fastest HDL language to learn and use. However Verilog lacks user defined data types
and lacks the interface-object separation of the VHDL's entity-architecture model.
History of Verilog:
Verilog simulator was first used beginning in 1985 and was extended substantially
through 1987. The implementation was the Verilog simulator sold by Gateway. The first
major extension was Verilog-XL, which added a few features and implemented the
infamous "XL algorithm" which was a very efficient method for doing gate-level
simulation.
The standard, which combined both the Verilog language syntax and the PLI in a
single volume, was passed in May 1995 and now known as IEEE Std. 1364-1995.
After many years, new features have been added to Verilog, and the new version
is called Verilog 2001. This version seems to have fixed a lot of problems that Verilog
1995 had. This version is called 1364-2001.
Digital Logic Design, EE Department, Wah Engineering College
VHDL
VHDL is good for designing behavioral models and incorporates some of the
modern object oriented techniques. It's syntax is strange and irregular, and the language is
difficult to use. Structural models require a lot of code that interferes with the readability
of the model.
C++:
C++ as an hardware modeling language is excellent choice for high-level
behavioral analysis of a system (like evaluating different data flow architectures in a
microprocessor). However C++ lacks the basic hardware concepts like knowledge of
strengths, connections, and concurrent execution which complicates model generation for
lower level simulations.
Module components can be simple logic gates or they can be instances of other
modules. Module components are interconnected by wires. Wires represent the actual
conductors connecting the output of a gate to the input of another.
The port list of a module is the interface between the module and its environment.
In this example, the ports are the inputs and outputs of the circuit. The port list is
enclosed in parentheses, and commas are used to separate elements of the list. The
statement is terminated with a semicolon (;). Next, the keywords input and output
specify which of the ports are inputs and which are outputs. Internal connections are
declared as wires. The circuit in this example has one internal connection, at terminal w1,
and is declared with the keyword wire. The structure of the circuit is specified by a list of
(predefined) primitive gates, each identified by a descriptive keyword (and, not, or). The
elements of the list are referred to as instantiations of a gate, each of which is referred to
as a gate instance. Each gate instantiation consists of an optional name (such as G1, G2,
etc.) followed by the gate output and inputs separated by commas and enclosed within
parentheses. The output of a primitive gate is always listed first, followed by the inputs.
For example, the OR gate of the schematic is represented by the or primitive, is named
G3, and has output D and inputs w1 and E. (Note: The output of a primitive must be listed
first, but the inputs and outputs of a module may be listed in any order.) The module
description ends with the keyword endmodule. Each statement must be terminated with a
semicolon, but there is no semicolon after endmodule.
Digital Logic Design, EE Department, Wah Engineering College
The waveforms of the input signals are abstractly modeled (generated) by Verilog
statements specifying waveform values and transitions. The initial keyword is used with
a set of statements that begin executing when the simulation is initialized; the signal
activity associated with initial terminates execution when the last statement has finished
executing. The initial statements are commonly used to describe waveforms in a test
bench. The set of statements to be executed is called a block statement and consists of
several statements enclosed by the keywords begin and end. The action specified by the
statements begins when the simulation is launched, and the statements are executed in
sequence, left to right, from top to bottom, by a simulator in order to
provide the input to the circuit. Initially, A, B, C = 0. (A, B, and C are each set to 1b0,
which signifies one binary digit with a value of 0.) After 100 ns, the inputs change to
A, B, C = 1. After another 100 ns, the simulation terminates at time 200 ns. A second
initial statement uses the $finish system task to specify termination of the simulation.
Boolean Expressions:
Boolean equations describing combinational logic are specified in Verilog with a
continuous assignment statement consisting of the keyword assign followed by a
Boolean expression. To distinguish arithmetic operators from logical operators, Verilog
uses the symbols (&), (/), and (~) for AND, OR, and NOT (complement), respectively.
The logic of a module can be described in any one (or a combination) of the
following modeling styles:
For example
or or1( z, x1, x2, x3, x4 );
and and1( x1, a, b );
and and2( x2, a, c );
not not1(na, a);
not not2(ne, e);
and and3( x3, na, d );
and and4( x4, ne, d );
how the associated statement is to execute (subject to the event control expression). The
always statement executes repeatedly in a loop. The initial statement executes only once,
starting from simulation time 0, and may continue with any operations that are delayed
by a given number of time units, as specified by the symbol #.
initial
begin
A 0; B 0;
#10 A 1;
#20 A 0; B 1;
end
The block is enclosed between the keywords begin and end . At time 0, A and B are set
to 0. Ten time units later, A is changed to 1. Twenty time units after that (at t 30 ), A is
changed to 0 and B to 1.
The response to the stimulus generated by the initial and always blocks will appear in
text format as standard output and as waveforms (timing diagrams) in simulators having
graphical output capability. Numerical outputs are displayed by using Verilog system
tasks. These are built-in system functions that are recognized by keywords that begin
with the symbol $ . Some of the system tasks that are useful for display are
$displaydisplay a one-time value of variables or strings with an end-of-line return,
$writesame as $display, but without going to next line,
$monitordisplay variables whenever a value changes during a simulation run,
$timedisplay the simulation time,
$finishterminate the simulation.
Example:
The first line of text is a comment (optional) providing useful information to the
reader. The second line begins with the keyword module and starts the declaration
(description) of the module; the last line completes the declaration with the keyword
Digital Logic Design, EE Department, Wah Engineering College
endmodule. The keyword module is followed by a name and a list of ports. The name
(Simple_Circuit in this example) is an identifier. Identifiers are names given to modules,
variables (e.g., a signal), and other elements of the language so that they can be
referenced in the design. In general, we choose meaningful names for modules.
Identifiers are composed of alphanumeric characters and the underscore (_), and are case
sensitive. Identifiers must start with an alphabetic character or an underscore, but they
cannot start with a number.
MODEL SIM
Model sim is used to design the circuits .Here we dicuss the work of model sim.
Creating a project to create a project in Model Sim, select File > New > Project.... A Create
Project window will appear.
The create project window consists of several fields: project name, project location, default library
name, and copy settings field. Project name is a user selected name and the location is the directory where
the source files are located.
Digital Logic Design, EE Department, Wah Engineering College
Compiling a Project
Once the project has been created, it is necessary to compile it. Compilation in
ModelSim checks if the project files are correct and creates intermediate data that will be
used during simulation. To perform compilation, select Compile All from the Compile
menu. When the compilation is successful, a green check mark will appear to the right
of the serial.vhd file in the Project tab.
Simulation:
PART (B)
(a) Implementation of basic and universal gates using Verilog
Comments:
Conclusion: