Sunteți pe pagina 1din 9

08-03-2018

Verilog vs. VHDL In general, Verilog is easier to learn than VHDL. This is due, in part, to
the popularity of the C programming language, making most
Verilog and VHDL are Hardware Description languages that are used to programmers familiar with the conventions that are used in Verilog.
write programs for electronic chips. These languages are used in VHDL is a little bit more difficult to learn and program.
electronic devices that do not share a computer’s basic architecture.
VHDL is the older of the two, and is based on Ada and Pascal, thus VHDL has the advantage of having a lot more constructs that aid in
inheriting characteristics from both languages. Verilog is relatively high-level modeling, and it reflects the actual operation of the device
recent, and follows the coding methods of the C programming being programmed. Complex data types and packages are very
language. desirable when programming big and complex systems, that might
have a lot of functional parts. Verilog has no concept of packages, and
VHDL is a strongly typed language, and scripts that are not strongly all programming must be done with the simple data types that are
typed, are unable to compile. A strongly typed language like VHDL does provided by the programmer.
not allow the intermixing, or operation of variables, with different
classes. Verilog uses weak typing, which is the opposite of a strongly Lastly, Verilog lacks the library management of software programming
typed language. Another difference is the case sensitivity. Verilog is languages. This means that Verilog will not allow programmers to put
case sensitive, and would not recognize a variable if the case used is needed modules in separate files that are called during compilation.
not consistent with what it was previously. On the other hand, VHDL is Large projects on Verilog might end up in a large, and difficult to
not case sensitive, and users can freely change the case, as long as the trace, file.
characters in the name, and the order, stay the same.

Summary:
Hardware Description Language - Introduction
1. Verilog is based on C, while VHDL is based on Pascal and
Ada. • HDL is a language that describes the hardware of digital
systems in a textual form.
2. Unlike Verilog, VHDL is strongly typed. • It resembles a programming language, but is specifically
oriented to describing hardware structures and behaviors.
3. Ulike VHDL, Verilog is case sensitive. • The main difference with the traditional programming
languages is HDL’s representation of extensive parallel
operations whereas traditional ones represents mostly serial
4. Verilog is easier to learn compared to VHDL. operations.
• The most common use of a HDL is to provide an alternative to
5. Verilog has very simple data types, while VHDL allows users schematics.
to create more complex data types.

6. Verilog lacks the library management, like that of VHDL.

1
08-03-2018

HDL – Introduction (2) HDL – Introduction (3)

• HDL can be used to represent logic diagrams,


• When a language is used for the above purpose (i.e. to Boolean expressions, and other more complex digital
provide an alternative to schematics), it is referred to as a circuits.
structural description in which the language describes an
interconnection of components.
• Thus, in top down design, a very high-level
description of a entire system can be precisely
• Such a structural description can be used as input to logic
specified using an HDL.
simulation just as a schematic is used.
• Models for each of the primitive components are
• This high-level description can then be refined and
required. partitioned into lower-level descriptions as a part of
the design process.
• If an HDL is used, then these models can also be written in
the HDL providing a more uniform, portable
representation for simulation input.

HDL – Introduction (4) Logic Simulation

• As a documentation language, HDL is used to represent and • A simulator interprets the HDL description and produces a
document digital systems in a form that can be read by both readable output, such as a timing diagram, that predicts
humans and computers and is suitable as an exchange how the hardware will behave before its is actually
language between designers. fabricated.
• The language content can be stored and retrieved easily and • Simulation allows the detection of functional errors in a
processed by computer software in an efficient manner. design without having to physically create the circuit.
• There are two applications of HDL processing: Simulation and
Synthesis

2
08-03-2018

Logic Simulation (2) Logic Simulation


• The stimulus that tests the functionality of the design is called • Logic simulation is a fast,
a test bench.
accurate method of
• To simulate a digital system analyzing a circuit to see its
– Design is first described in HDL waveforms
– Verified by simulating the design and checking it with a test bench
which is also written in HDL.

Verilog
Types of HDL
• There are two standard HDL’s that are supported by IEEE. • Verilog HDL has a syntax that describes precisely the legal
– VHDL (Very-High-Speed Integrated Circuits Hardware constructs that can be used in the language.
Description Language) - Sometimes referred to as VHSIC • It uses about 100 keywords pre-defined, lowercase, identifiers
HDL, this was developed from an initiative by US. Dept. of that define the language constructs.
Defense. • Example of keywords: module, endmodule, input, output wire,
– Verilog HDL – developed by Cadence Data systems and and, or, not , etc.,
later transferred to a consortium called Open Verilog • Any text between two slashes (//) and the end of line is
International (OVI). interpreted as a comment.
• Blank spaces are ignored and names are case sensitive.

3
08-03-2018

Verilog - Module Verilog – Module (2)


• A module is the building block in Verilog.
• It is declared by the keyword module and is always
terminated by the keyword endmodule.
• Each statement is terminated with a semicolon, but there
is no semi-colon after endmodule.
• A module can be an element or a collection of lower-level HDL Example
design blocks. Typically, elements are grouped into module smpl_circuit(A,B,C,x,y);
modules to provide common functionality that is used at input A,B,C;
many places in the design.
output x,y;
• A module provides the necessary functionality to the
wire e;
higher-level block through its port interface (inputs and
outputs), but hides the internal implementation. This and g1(e,A,B);
allows the designer to modify module internals without not g2(y,C);
affecting the rest of the design. or g3(x,e,y);
endmodule

Verilog – Gate Delays Verilog – Module (4)


• Sometimes it is necessary to specify the amount of //Description of circuit with
delay from the input to the output of gates. delay
• In Verilog, the delay is specified in terms of time units
and the symbol #. module circuit_with_delay
• The association of a time unit with physical time is (A,B,C,x,y);
made using timescale compiler directive. input A,B,C;
• Compiler directive starts with the “backquote (`)”
symbol. output x,y;
`timescale 1ns/100ps wire e;
• The first number specifies the unit of measurement and #(30) g1(e,A,B);
for time delays.
• The second number specifies the precision for which or #(20) g3(x,e,y);
the delays are rounded off, in this case to 0.1ns. not #(10) g2(y,C);
endmodule

4
08-03-2018

Verilog – Module (5)


Verilog – Module (6)
• In order to simulate a circuit with HDL, it is module circuit_with_delay //Stimulus for simple circuit
necessary to apply inputs to the circuit for the (A,B,C,x,y); module stimcrct;
input A,B,C;
simulator to generate an output response. reg A,B,C;
output x,y; wire x,y;
• An HDL description that provides the stimulus to a wire e; circuit_with_delay cwd(A,B,C,x,y);
design is called a test bench. and #(30) g1(e,A,B); initial
or #(20) g3(x,e,y); begin
• The initial statement specifies inputs between the not #(10) g2(y,C); A = 1'b0; B = 1'b0; C = 1'b0;
keyword begin and end. endmodule #100
A = 1'b1; B = 1'b1; C = 1'b1;
• Initially ABC=000 (A,B and C are each set to 1’b0 #100 $finish;
(one binary digit with a value 0). end
• $finish is a system task. endmodule

Verilog – Module (6) Verilog – Module (7)

Bitwise operators
– Bitwise NOT : ~
– Bitwise AND: &
– Bitwise OR: |
– Bitwise XOR: ^
– Bitwise XNOR: ~^ or ^~
In the above example, cwd is declared as one instance
circuit_with_delay. (similar in concept to object<->class relationship)

5
08-03-2018

Verilog – Module (8) Verilog – Module (9)

Boolean Expressions:
//Circuit specified with Boolean equations
• These are specified in Verilog HDL with a
continuous assignment statement consisting module circuit_bln (x,y,A,B,C,D);
of the keyword assign followed by a Boolean input A,B,C,D;
Expression. output x,y;
assign x = A | (B & C) | (~B & C);
• The earlier circuit can be specified using the
statement: assign y = (~B & C) | (B & ~C & ~D);
endmodule
assign x = (A&B)|~C)
E.g. x = A + BC + B’D
y = B’C + BC’D’

Verilog – Module (10) Verilog – Module (12)


UDP features ….
• UDP’s do not use the keyword module. Instead they
are declared with the keyword primitive.
User Defined Primitives (UDP): • There can be only one output and it must be listed
• The logic gates used in HDL descriptions with first in the port list and declared with an output
keywords and, or,etc., are defined by the keyword.
system and are referred to as system • There can be any number of inputs. The order in which
they are listed in the input declaration must conform
primitives. to the order in which they are given values in the table
• The user can create additional primitives by that follows.
defining them in tabular form. • The truth table is enclosed within the keywords table
and endtable.
• These type of circuits are referred to as user- • The values of the inputs are listed with a colon (:). The
defined primitives. output is always the last entry in a row followed by a
semicolon (;).
• It ends with the keyword endprimitive.

6
08-03-2018

Verilog – Module (13) Verilog – Module (14)


• Verilog is both a behavioral and a structural language. Internals of
//User defined primitive(UDP)
primitive crctp (x,A,B,C);
each module can be defined at four levels of abstraction,
output x;
depending on the needs of the design. A module can be described
input A,B,C; in any one (or a combination) of the following modeling
//Truth table for x(A,B,C) = Minterms (0,2,4,6,7) techniques.
table – Gate-level modeling using instantiation of primitive gates and
user defined modules.
// A B C : x(Note that this is only a comment)
0 0 0 : 1;
• This describes the circuit by specifying the gates and how
they are connected with each other.
0 0 1 : 0; – Dataflow modeling using continuous assignment statements
0 1 0 : 1; with the keyword assign.
0 1 1 : 0; // Instantiate primitive • This is mostly used for describing combinational circuits.
1 0 0 : 1; module declare_crctp; – Behavioral modeling using procedural assignment statements
1 0 1 : 0; with keyword always.
1 1 0 : 1; reg x,y,z; • This is used to describe digital systems at a higher level of
1 1 1 : 1; wire w; abstraction.
endtable  Switch level modeling is the lowest level of abstraction
endprimitive crctp (w,x,y,z); provided by Verilog. A module can be implemented in terms of
switches, storage nodes, and the interconnections between
endmodule them.

Gate-Level Modeling
• The module is implemented in terms of logic gates and Gate-level modeling (2)
interconnections between these gates. Design at this level is
similar to describing a design in terms of a gate-level logic • When a primitive gate is incorporated into a
diagram. module, we say it is instantiated in the module.
• Here a circuit is specified by its logic gates and their • In general, component instantiations are
interconnections.
statements that reference lower-level
• It provides a textual description of a schematic diagram. components in the design, essentially creating
• Verilog recognizes 12 basic gates as predefined primitives. unique copies (or instances) of those components
– 4 primitive gates of 3-state type. in the higher-level module.
– Other 8 are: and, nand, or, nor, xor, xnor, not, buf • Thus, a module that uses a gate in its description
• When the gates are simulated, the system assigns a four- is said to instantiate the gate.
valued logic set to each gate – 0,1,unknown (x) and high
impedance (z)

7
08-03-2018

Gate-level Modeling (3) Gate-level Modeling


• Two or more modules can be combined to build a
• Modeling with vector data (multiple bit hierarchical description of a design.
widths): • There are two basic types of design
methodologies.
– A vector is specified within square brackets – Top down: In top-down design, the top level
block is defined and then sub-blocks necessary
and two numbers separated with a colon. to build the top level block are identified.
e.g. output[0:3] D; - This declares an – Bottom up: Here the building blocks are first
identified and then combine to build the top
output vector D with 4 bits, 0 through 3. level block.
• In a top-down design, a 4-bit binary adder is
wire[7:0] SUM; – This declares a defined as top-level block with 4 full adder blocks.
wire vector SUM with 8 bits numbered 7 Then we describe two half-adders that are
required to create the full adder.
through 0. • In a bottom-up design, the half-adder is defined,
then the full adder is constructed and the 4-bit
The first number listed is the most significant adder is built from the full adders.
bit of the vector.

Gate-level Modeling Half Adder


• A bottom-up hierarchical description of a 4-bit
adder is described in Verilog as
– Half adder: defined by instantiating primitive
gates.
– Then define the full adder by instantiating
two half-adders.
– Finally the third module describes 4-bit adder
by instantiating 4 full adders.
• Note: In Verilog, one module definition cannot
be placed within another module description.

8
08-03-2018

Full Adder Adder

//Gate-level hierarchical description of 4-bit adder

module halfadder (S,C,x,y);


input x,y;
output S,C;
//Instantiate primitive gates
xor (S,x,y);
and (C,x,y);
endmodule

4-bit Full Adder


module fulladder (S,C,x,y,z);
input x,y,z; module _4bit_adder (S,C4,A,B,C0);
input [3:0] A,B;
output S,C; input C0;
output [3:0] S;
wire S1,D1,D2; //Outputs of first XOR and two AND gates
output C4;
//Instantiate the half adders wire C1,C2,C3; //Intermediate carries
halfadder HA1(S1,D1,x,y), //Instantiate the full adder
HA2(S,D2,S1,z);
fulladder FA0 (S[0],C1,A[0],B[0],C0),
or g1(C,D2,D1); FA1 (S[1],C2,A[1],B[1],C1),
FA2 (S[2],C3,A[2],B[2],C2),
endmodule FA3 (S[3],C4,A[3],B[3],C3);
endmodule

S-ar putea să vă placă și