dsd module 2
dsd module 2
Design
Module – 2 Verilog HDL
Dr. K. Chitra
Professor
School of Electronics Engineering
AB1-607A – Cabin no. 6
9500146958
Module-2 (Verilog HDL)
Lexical Conventions, Ports and Modules,
Operators, Data flow modeling, Gate level
modeling, Behavioral modeling, Test Bench
HDL
• Hardware Description Language (HDL) is a
computer-based language that describes the
hardware of a digital system in textual form.
• HDL describes
– hardware structures, and the behavior of logic
circuits.
– logic diagram, truth tables, Boolean expressions,
and complex abstraction of the behavior of a
digital system.
HDLs
• Two most widely used HDLs and supported by IEEE are
– Verilog
– VHDL (VHSIC HDL – Very High Speed Integrated Circuit HDL)
• HDLs are used in major steps in the design flow of an
integrated circuit:
– Design entry
– Functional simulation or verification
– Logic synthesis
– Timing verification
– Fault simulation
Features of Verilog
• Verilog
– Composed of text using keywords about 100
– Keywords are predefined lowercase identifiers.
Ex. module, endmodule, input, output, wire, and,
or, not
– Text between “//” and end of the line – comment
– Multiline comment appears between /* and */
– Verilog is case sensitive
Lexical Conventions
• Logical values: 0, 1, X, Z
• Types of lexical tokens:
– Operators,
– white space,
– comment,
– Identifiers,
– number,
– string,
– Keywords (indicated in bold face)
Types of Operators
Arithmetic Operators +, -, *, /, %
Relational Operators <, <=, >, >=
Equality Operators ==, !=, ===, !==
Logical Operators !, &&, ||
Bit-Wise Operators ~, &, |, ^, ~^
Unary Reduction &, ~&, |, ~|, ^, ~^
Shift Operators >>, <<
Conditional Operators ?:
Concatenations {}
Operators..
{} concatenation ~ bit-wise NOT
+ - * / arithmetic & bit-wise AND
% modulus | bit-wise OR
> >= < <= relational ^ bit-wise XOR
^~ ~^ bit-wise XNOR
! logical NOT
& reduction AND
&& logical AND
| reduction OR
|| logical OR ~& reduction NAND
== logical equality ~| reduction NOR
!= logical ^ reduction XOR
inequality ~^ ^~ reduction XNOR
?: conditional << shift left
>> shift right
Precedence of operators
[ ]bit-select or part-select >, >=, <, <= relational
( ) parentheses ==, != logical equality
!, ~ logical and bit-wise & bit-wise AND
negation ^, ^~, ~^
&, |, ~&, ~|, ^, ~^, ^~ bit-wise XOR and XNOR
reduction operators | bit-wise OR
+, - unary arithmetic && logical AND
{ }concatenation || logical OR
*, /, % arithmetic ?: conditional
+, - arithmetic
<<, >> shift
Other lexicals..
• Comments: //, /* */
• Numbers: Decimal, hexa, octal, binary
• String: “Enclose between quotes”
• Identifiers:
– A..Z, a…z, 0..9, underscore and dollar sign
– Limited to 1024 characters long
– First character of identifier must not be a digit
– Verilog has Case sensitive characters
Keywords
Data types
1. Value sets (Logical 0, 1, x, z)
2. Nets
3. Vectors
4. Registers
5. Integer, real and time register
6. Arrays
7. Memories
8. Parameters
9. Strings
Numeric Constants
Data types
• Nets
– Nets are physical connections between devices.
– Nets always reflect the logic value of the driving device.
– Following types of nets are there, but wire is often used
– types of nets
• wire, tri : default
• wor, trior : wire-ORed
• wand, triand : wire-ANDed
• trireg : with capacitive storage
• tri1 : pull high
• tri0 ; pull low
• supply1 ; power
• supply0 ; ground
Registers and parameters
• Registers & Parameters
– Implicit storage – Does not necessarily imply a
hardware register.
– Register type is denoted by reg .
A register holds its value until a new value is
assigned to it.
Registers are used extensively in behavior
modeling and in applying stimuli.
Parameters are not variables, they are constants.
Variable Declaration
• Declaring a net
wire [<range>] <net_name> [<net_name>*];
Range is specified as [MSB:LSB]. Default is one bit wide
• Declaring a register
reg [<range>] <reg_name> [<reg_name>*];
• Declaring memory
reg [<range>] <memory_name> [<start_addr> : end_addr>];
• Examples
reg r; // 1-bit reg variable
wire w1, w2; // 2 1-bit wire variable
reg [7:0] vreg; // 8-bit register
reg [7:0] memory [0:1023]; a 1 KB memory
Integer and real register data type
• Integers are declared by the keyword integer.
The default width is 32 bits
• Architectural level
Algorithm
• Register transfer level (RTL)
• Gate level Architecture
Gate Level
Transistor Level
Verilog
• 3 levels of abstraction in Verilog:
– Gate level
• Circuit is modeled by logic gates
• Logic gates are predefined in Verilog library
– Data flow level
• Assignment statement is used (assign)
– Behavioral / Algorithmic level
• A region of code containing sequential statements
Gate level modeling
In gate level modeling a circuit can be defined by use of logic gates.
These gates predefined in verilog library.
The basic gates and their syntax is as follows:
not gate_name (output, input);
and gate_name(output, input);
or gate_name(output, input);
nand gate_name(output, input);
nor gate_name(output, input);
xor gate_name(output, input);
xnor gate_name(output, input);
Verilog Primitives
• Basic logic gates only
– and
– or
– not
– buf
– xor
– nand
– nor
– xnor
– bufif1, bufif0
– notif1, notif0
Multiple inputs
• One output and variable number of inputs
Syntax:
variable_lvalue = [timing_control] expression
variable_lvalue <= [timing_control] expression
[timing_control] variable_lvalue = expression
[timing_control] variable_lvalue <= expression
Blocking assignments
• Are executed in the order they are coded. Hence they
are sequential.
• Since they block the execution of next statement , till
the current statement is executed , they are called
blocking assignments.
// blocking assignments
initial begin
x = #5 1'b0; // at time 5
y = #3 1'b1; // at time 8
z = #6 1'b0; // at time 14
end
Nonblocking assignments
• They are executed in parallel.
• Since execution of next statement is not blocked due
to the execution of current statement .
• Therefore they are called as non-blocking assignment.
reg x, y, z;
// nonblocking assignments
initial begin
x <= #5 1'b0; // at time 5
y <= #3 1'b1; // at time 3
z <= #6 1'b0; // at time 6
end
Statements
• Control/conditional statements
• If and If-else statements
• Case statements
– Casex and casez statements
• Loop statements
– Forever, repeat, while, for
Control/ Conditional statement
//Type 1 conditional statement. No else statement.
//Statement executes or does not execute.
if () true_statement ;
reg x, y;
integer count;
#25 y <= ~x; // at time 25
#15 count <= count + 1; // at time 40
Intra assignment delay control
• Defers the assignment to the left-hand-side
variable
y=#25 ~x; // assign to y at time 25
count = #15 count + 1; // assign to count at time 40
always
wait (count_enable) count = count –1 ;
always
wait (count_enable) #10 count = count –1 ;
2-4 decoder – Behavioral modeling
module two-four-decoder(data_in, data-out);
input [1:0]data_in;
output [3:0]data_out;
reg [3:0] data_out;
always @(data_in)
case (data_in)
2’b00 : data_out = 4’b0001;
2’b01 : data_out = 4’b0010;
2’b10 : data_out = 4’b0100;
2’b11 : data_out = 4’b1000;
endcase
endmodule
3-to-8 decoder
module three-eight-decoder(data_in, data_out);
input [2:0]data_in;
output [7:0]data_out;
reg [7:0] data_out;
always @(data_in)
case (data_in)
3’b000 : data_out = 8’b00000001;
3’b001 : data_out = 8’b00000010;
3’b010 : data_out = 8’b00000100;
3’b011 : data_out = 8’b00001000;
3’b100 : data_out = 8’b00010000;
3’b101 : data_out = 8’b00100000;
3’b110 : data_out = 8’b01000000;
3’b111 : data_out = 8’b10000000;
endcase
endmodule