Introduction To HDL
Introduction To HDL
Introduction To HDL
Unit - 1
Evolution of Computer Aided Digital Design
• Digital circuit design has evolved rapidly over the last 25 years.
• The earliest digital circuits were designed with vacuum tubes and transistors.
• Integrated circuits were then invented where logic gates were placed on a single chip.
• SSI (Small scale integration)
• MSI (Medium Scale Integration)
• LSI (Large Scale Integration)
2
EDA(Electronic Design Automation)
• Design processes started getting very complicated, and designers felt the need to automate
these processes.
• Chip designers began to use circuit and logic simulation techniques to verify the functionality
of building blocks.
• VLSI (Very Large Scale Integration) designers could design single chips with more than
millions of transistors.
• Computer-aided techniques became critical for verification and design of VLSI digital circuits
• Logic simulators came into existence to verify the functionality of these circuits before they
were fabricated on chip
• Designers could iron out functional bugs in the architecture before the chip was designed
further
• Goals
– most reliable design process, with minimum cost and time
– avoid design errors!
3
HDL (Hardware Description Language)
• HDL allowed the designers to model the concurrency of processes found in hardware elements.
• Hardware description languages such as Verilog HDL and VHDL became popular.
• The advent of logic synthesis in the late 1980s changed the design methodology radically.
• Digital circuits could be described at a register transfer level (RTL) by use of an HDL.
• The details of gates and their interconnections to implement the circuit were automatically
extracted by logic synthesis tools from the RTL description.
• HDLs were used for simulation of system boards, interconnect buses, FPGAs (Field
Programmable Gate Arrays), and PAL (Programmable Array Logic).
4
VLSI design flow
• Architectural design – input, output, Unshaded – design description
components, cost estimate
Shaded – design process
• Translate
• Technology Mapping
• Optimize • List of gates and nets (interconnections)
• Testability
• Transistor level
5
6
Two Modeling Hardware Description Languages
7
Verilog HDL
⦿ Verifying Logic
⦿ Phil Moorby from Gateway Design Automation in 1984 to 1987 (absorbed by Cadence)
⦿ Verilog-XL Simulator from GDA in 1986
⦿ Synopsys synthesis tool in 1988
⦿ In 1990 became open language, OVI (Open Verilog International)
⦿ IEEE standard 1995
⦿ Similar to C
⦿ Fairly efficient and easy to write
⦿ Case sensitive
8
What is Verilog HDL?
• Verilog Hardware Description Language(HDL)?
– A high-level computer language to model, represent and simulate digital design
• Hardware concurrency
• Parallel Activity Flow
• Semantics for Signal Value and Time
Examples :
• module, endmodule
• input, output, inout
• reg, integer, real, time
• not, and, nand, or, nor, xor
• parameter
• begin, end
• fork, join
• specify, endspecify
19
Ports
input, output, inout
These keywords declare input, output and bidirectional ports of a module or task.
Input and inout ports are of type wire.
An output port can be configured to be of type wire, reg, wand, wor or tri.
The default is wire.
Syntax
input [msb:lsb] input_port_list;
output [msb:lsb] output_port_list;
inout [msb:lsb] inout_port_list;
20
Instances
• The process of creating objects from a module template is called instantiation, and
the objects are called instances.
• Each instance must be given a unique name.
• A module definition can incorporate copies of other modules by instantiating
them.
Module instantiation
• Port mapping by order
Example:
half_adder ha1 (a , b, s1, c1)
half_adder ha2 (s1 , cin, sum, c2)
or or1 (cout, c1, c2)
• Port mapping by name (may skip any ports; advantageous when large number of
ports are there)
Example:
half_adder ha1 (.a(a) , .b(b), .sum(s1), .carry(c1))
half_adder ha2 (.a(s1) , .b(cin), .sum(sum), .carry(c2))
or or1 (cout, c1, c2)
//Port-mapping by order
module SYNCHRO (ASYNC,SYNC,CLOCK);
input ASYNC;
input CLOCK;
module DFF (Q, D, CLK); output SYNC;
input D, CLK; wire C1_ASYNC;
output reg Q; DFF DFF1 (C1_ASYNC, ASYNC, CLOCK);
always @ (posedge CLK) DFF DFF2 (SYNC, C1_ASYNC, CLOCK);
Q <= D; endmodule
----------------------------------------------------
endmodule
//Port-mapping by name
module SYNCHRO (ASYNC, SYNC, CLOCK);
input ASYNC;
input CLOCK;
output SYNC;
wire C1_ASYNC;
• X: unknown
31
Data Types
• Nets and Registers
• Vectors
• Integer, Real, and Time Register Data Types
• Arrays
• Memories
• Parameters
• Strings
32
Nets
• Used to represent connections between HW elements
– Values continuously driven on nets
• Keyword: wire
– Default: One-bit values (unless declared as vectors)
– Default value: z
• For trireg, default is x
– Note that net is not a keyword but represents a class of data types such as wire,
wand, wor, tri, triand, trior, trireg, etc. The wire declaration is used most
frequently.
– Examples
• wire a;
• wire b, c;
• wire d=1’b0;
• Port declaration – “nets” by default
33
Registers
• Registers represent data storage elements
– Retain value until next assignment
– NOTE: this is not a hardware register or flipflop
– Keyword: reg
– Default value: x
– Example:
reg reset;
initial
begin
reset = 1’b1;
#100 reset=1’b0;
end
35
Vectors
• Net and register data types can be declared as vectors (multiple bit widths)
• Syntax:
– wire/reg [msb_index : lsb_index] data_id;
• Example
wire a;
wire [7:0] bus;
wire [31:0] busA, busB, busC;
reg clock;
reg [0:40] virtual_addr;
36
Vectors (cont’d)
• Consider
wire [7:0] bus;
wire [31:0] busA, busB, busC;
reg [0:40] virtual_addr; // bit-0 is the MSB
• Access to bits or parts of a vector is possible:
busA[7]
bus[2:0] // three least-significant bits of bus
// bus[0:2] is illegal.
virtual_addr[0:1] /* two most-significant bits
* of virtual_addr
*/
37
Integer, Real, and Time - Register Data Types (cont’d)
• Integer
– Keyword: integer
– Very similar to a vector of reg
• integer variables are signed numbers
• reg vectors are unsigned numbers
– Bit width: implementation-dependent (at least 32-bits)
• Designer can also specify a width:
integer [7:0] tmp;
– Examples:
integer counter;
initial
counter = -1;
38
Integer, Real, and Time - Register Data Types (cont’d)
• Real
– Keyword: real
– Values:
• Default value: 0
• Decimal notation: 12.24
• Scientific notation: 3e6 (=3x106)
– Cannot have range declaration; bit-width 64
39
Integer, Real, and Time - Register Data Types (cont’d)
• Time
– Used to store values of simulation time
– Keyword: time
– Bit width: implementation-dependent (at least 64)
– $time system function gives current simulation time
– Example:
time save_sim_time;
initial
save_sim_time = $time;
• Simulation time is measured in terms of simulation seconds.
40
Arrays
• Only one-dimensional arrays supported
• Allowed for reg, integer, time
– Not allowed for real data type
• Syntax:
<data_type> <var_name> [start_idx : end_idx];
• Examples:
integer count [0:7];
reg bool[31:0];
time chk_point [1:100];
reg [4:0] port_id [0:7];
integer matrix[4:0][4:0]; // illegal
count[5]
chk_point[100]
port_id[3]
• Note the difference between vectors and arrays
Verilog thinks in bits, so reg [7:0] a[0:3] will give you a 4x8 bit array (=4x1 byte array).
You get the first byte out of this with a[0]. The third bit of the 2nd byte is a[1][2].
Memories
• RAM, ROM, and register-files used many times in digital systems
• Memory = array of registers in Verilog
• Word = an element of the array
– Can be one or more bits
• Examples:
reg membit[0:1023];
reg [7:0] membyte[0:1023];
membyte[511]
• Note the difference (as in arrays): It is important to differentiate between n 1-bit
registers and one n-bit register.
reg membit[0:127];
reg [0:127] register;
42
Parameters
• Similar to const in C
– But can be overridden for each module at compile-time
• Syntax:
parameter <const_id>=<value>;
• Gives flexibility
– Allows to customize the module
• Example:
parameter port_id=5;
parameter cache_line_width=256;
parameter bus_width=8;
wire [bus_width-1:0] bus;
43
Strings
• Strings are stored in reg variables.
• 8-bits required per character
• Example:
reg [8*18:1] string_value;
initial
string_value = “Hello World!”;
• Escaped characters
– \n : newline
– \t : tab
– %% : %
– \\ : \
– \” : “
46
Numbers
Format : <size>’<base><value>
Example : 8’d16
8’h10
8’b00010000
8’o20
47
• Modules
• Ports
• System tasks & compiler directives
Lexical Conventions – White space
White space
Comments
Case sensitivity
Identifiers
Numbers format
Numbers format
Numbers format
Escaped characters
Escaped characters
System Tasks and Compiler Directives
System Tasks
– Operations such as displaying on the screen, monitoring values of nets, stopping, and
finishing are done by system tasks.
Displaying information ($display)
• $display is the main system task for displaying values of variables or strings or
expressions.
• Usage: $monitor(p1,p2,p3,....,pn);
• The parameters p1, p2, ...,pn can be variables, signal names, or quoted strings.
• The $stop task is used whenever the designer wants to suspend the simulation and
examine the values of signals in the design.
• The <reference-time-unit> specifies the unit of measurement for times and delays.
The <time-precision> specifies the precision to which the delays are rounded off
during simulation.
• Only 1, 10, and 100 are valid integers for specifying time unit and time precision
• https://www.javatpoint.com/verilog-timescale
Examples
•
Comparator using full adders