Day-1 (Chipvidia)
Day-1 (Chipvidia)
Day-1 (Chipvidia)
Verilog Basics
and
HDL modelling
Introduction
-Very Large Scale Integration (VLSI) is a Technique
where many circuit components and the wiring that
connects them are manufactured simultaneously into a
compact, reliable and inexpensive chip.
-VLSI circuits are everywhere ... your computer, your
car, your brand new state-of-the-art digital camera, the
cell-phones, etc.
VLSI Design Flow
Basic Verilog Concepts Gate level
modeling
Introduction to
Verilog
● Standardized as IEEE 1364.
●
Hardware description language (HDL) used to
model electronic systems
●
Commonly used in the design and verification
of digital circuits
WHY?
● Why use an HDL
-> Describe complex Designs
-> Design Explorations and Simulation
● -> An input to SynthesisTools
Verilog Vs VHDL
●
-> Verilog is simpler to use and is similar to C
-> Mostly used in the Industry while VHDL is mostly used
in Educational and Research institutions
Modeling in Verilog
● A Module is the basic building block in Verilog
●
Modules can be interconnected to form a Digital
System
●
It is like a function in C
Top: Module - 1
Module - 2 Module - 3
Module - 4
Module Syntax
MUST add the
module <Module Name> <(<port list>)>;
semicolon
.
.
. Write Module Name Here Like:
. Shift_Register, Encoder_8_3,
. etc List of all input and output Pins
that are needed to be connected
. Like: a, b, c, clk, rst, y, op, etc
.
IMPORTANT: Do NOT
endmodule
... add Semicolon Here
Port Declaration
● There are three types of ports:
Registers
-> Used when data storage is required
-> Retains previous state value till changed
-> Does not necessarily imply register or flip-flop or latch, can also
imply a wire
-> Denoted by 'reg'
Integer, Real and
Time Data types
Integer:
● It is a general purpose register used for manipulating quantities.
●
Default width is the host-machine word size, which will be atleast
●
●
32-bits Can be used to store signed values
● It is not bit addressable
It can be synthesised
Real: Time:
●
●
Real number constants can Time register datatype is used to
be declared in this data type store simulation time.
●
●
Values can be specified in either Size of time register will be >= 64- bits
● decimal or scientific notation ● System function $time can be
● Cannot have range invoked to get current simulation
●
declaration It is not time It is not synthesisable
synthesisable
Variable Declaration
● Declaring a wire
wire <[<bit range>]> <net_name>;
Default width = 1
● Declaring a Register
reg <[<bit range>]> <reg_name>;
Default width = 1
● Declaring Memory
reg [<bit range>] <reg_name> [<start_addr>:<end_addr>];
Examples
reg r0; // 1 – bit register r0
● Not
● Buf
Gate level Instantiation
● Syntax:
<Gate> <*delay> <Instance_name>(<o/p variable>,<input
variables>);
Where,
Size: bit length of value (1,2,3,4-bit, 8, 32,...etc)
Radix: value represented in which format:
Example:
● Bit > b
1'b1 // 1
● Hexadecimal -> h
8'hE4 // 228 or 1110_0100
● Octal -> o 4'd5 // 5 or 0101
● Decimal -> d
Value: the value which needs to be assigned
Verilog Operators
●
Arithmatic Operators
●
Relational Operators
●
Equality Operators
●
Logical Operators
●
Bit-wise Operators
●
Reduction Operators
●
Shift Operators
●
Concatination Operators
●
Replication Operators
●
Conditional Operators
Arithmatic Operators
● Binary Operators: +, - , *, /, %
● Unary Operators: +, -
●
If any operand value is 'x', then the entire value of the output
is 'x'
Relational Operator
Operation Description
a<b a less than b
a>b a greater than b
a <= b a less than or equal to b
a >= b a greater than or equal to b
●
The result is a scalar value (example a < b)
●
0 if the relation is false (a is bigger then b)
●
●
1 if the relation is true ( a is smaller then b)
x if any of the operands has unknown x bits (if a or b contains X)
Equality Operator
Operation Description
a === b a equal to b, including x and z state
a !== b a not equal to b, including x and z state
a == b a equal to b, result may be unknown
a != b a not equal to b, result may be unknown
●
Operands are compared bit by bit, with zero filling if the two operands do
not have the same length
●
●
Result is 0 (false) or 1 (true)
●
For the == and != operators, the result is x, if either operand contains an x or a
z For the === and !== operators, bits with x and z are included in the
comparison and must match for the result to be true
Note : The result is always 0 or 1 for row 1 and 2
Logical Operator
Operator Description
! Negation
&& Logical And
|| Logical Or
●
Expressions connected by && and || are evaluated from left to
right
●
●
Evaluation stops as soon as the result is known
The
result is a scalar value:
0 if the relation is false
1 if the relation is true
x if any of the operands has x (unknown) bits
Bit-wise Operator
Operator Description
~ Negation
& AND
| OR
^ Exclusive OR
~^ or ^~ Exclusive NOR
1&x = x&x = x
1|x = 1
0|x = x|x = x
0^x = 1^x = x^x = x
0^~x = 1^~x = x^~x = x
●
When operands are of unequal bit length, the shorter operand is zero-filled in
the most significant bit positions.
Reduction Operator
Operator Description
& and
~& nand
| or
~| nor
^ xor
~^ or ^~ xnor
●
The left operand is shifted by the number of bit positions given by
the right operand.
●
The vacated bit positions are filled with zeroes.
ConcatenationOperator
Operation Description
{n{m}} Replicate value m, n times
Operator Symbols
Unary, Multiply, Divide, Modulus !, ~, *, /, %
Add, Subtract, Shift +, - , <<, >>
Relation, Equality <,>,<=,>=,==,!=,===,!==
Reduction &, ~&, ^, ^~, |, ~|
Logic &&, ||
Conditional ?:
Dataflow Level Modelling
●
At this level, the module is defined by defining the
data flow.
●
The designer is aware how the data flows between
the hardware registers and the data is processed in
the design.
Continuous Assignment
●
A continuous assignment replaces the gates in the
description of the circuit and describes the circuit in a higher
level of abstraction.
Eg. for sequential circuits, event list will consist of clock pin and
reset pin.
Procedural Assignments
●
It is IMPORTANT to note that all the variables present in the left side of
the '=' symbol in the procedural blocks must be declared as either a
reg, integer, real or time.
● They should NOT be a wire.
●
However those variables found on the right side of the '=' simbol can
be any datatype.
:output
Input:
Proceduaral Block register only
net/register
Blocking and Non blocking
Statements
Blocking statements: Non-Blocking statements:
Non-Blockingstatements allow
Blocking statements are executed in the
execution of the the
order they are specified in the order they
are specified in the sequential block. statements follow in the that
sequential block.
Only after the blocking assignment has
finished executing will it allow the next
instrictin in the block to execute.
Syntax:
Syntax:
initial begin
Inital begin
.
.
. // non-blocking
.
a <= 4'b0010; // statement
a = 4'b0010; // blocking statement
x <= a + x;
x = a + x;
...
...
end
end
Blocking Vs Non-Blocking
Blocking Non-blocking
<variable> = <statement> <variable> <= <statement>
Similar to C code The inputs are stored once
the procedure is triggered
The next assignment waits
until the present one is Statements are executed in
finished parallel
●
Verilog All start with $
●
Some commonly used system tasks are listed
below:
$display, $monitor, $time, $stop, $finish,
$random, $time
$display
● $display: displays values of variables, strings,
expressions.
● Syntax: $display(p1, p2, p3, …, pn);
●
p1,…, pn can be quoted string, variable, or
●
expression Adds a new-line after displaying pn by
●
default
Format
●
specifiers:
if (expression)
begin Example:
...statements...
end if (alu_func == 2'b00)
aluout = a + b;
else if (expression)
begin else if (alu_func == 2'b01)
...statements... aluout = a – b;
end else if (alu_func == 2'b10)
...more else if blocks aluout = a & b;
else // alu_func = 2'b11
else aluout = a | b;
begin
...statements...
end
Case Statement
Syntax
case (expression)
case_choice1:
begin
...statements... Example:
end case (sel)
case_choice2: 0: out = in[0];
begin 1: out = in[1];
...statements... 2: out = in[2];
end
3: out = in[3];
...more case choices blocks...
Default: out = 0;
default: endcase
begin
...statements...
End
endcase
For Statement
Syntax:
for(<initial_assignment>,<condition>,<step_assignment>
) begin
<statements>;
...
end
Note: This loop is partially
synthesisable,
Example: Depending on the
staements present inside
the loop
for (i = 2'b0; i <= 2'b11; i = i + 2'b01)
#10 y = y + 8'h01;
While Statement
Syntax: Example:
while (<expression>) while (i < 3) begin
begin #10 Y = Y + 1;
<statements>; i = i + 1;
...
end
end
Syntax:
repeat (<number of times>) Example:
begin repeat (4) #10 Y = Y + 1;
...
end Can be either an
integer or a variable
T = 20 time units
clk
Syntax:
Example:
forever
forever #10 clk = ~clk;
<statement>;
endtask
initial begin
reg p; // task invocation, values are
add (1, 0, p); // passed in the order they appear
$display (“p = %b”, p);
end
endmodule
Design Under Test (DUT)
module example1(A,B,C,D,cond);
case (cond)
00: A = B + C + D;
01: A = B - C + D;
default: A = B + C - D;
endcase
endmodule
Recommended Books
● Digital Logic Design
-M. Morris Mano and Michael D. Ciletti “Digital
Design with an introduction to Verilog HDL”
-Randy Katz, Gaetano Borriello, “Contemporary Logic
Design”
●
Verilog HDL
-Samir Palnitkar. “Verilog HDL”
●
Text book
- Zainalabedin Navabi, “Verilog Digital System Design”
Reference
● http://en.wikipedia.org/wiki/Verilog
Kunle Olukotun, Stanford EE183, http://www.stanford.edu/class/ee183/handouts_win2003/lect2.pdf
●
http://www.asic-world.com/verilog/
●
●
Samir Palnitkar, “Verilog HDL, A guide to digital design and synthesis”, Prentice Hall Professional,
2nd Edition
● Steve Poret, RCS, deimos.eos.uoguelph.ca/.../ENG6530-StevePoret-PaperReview2008.ppt
●
staff.fit.ac.cy/com.tk/ACOE361/Design_Flow.ppt
● http://www.xilinx.com/fpga/asic.htm
Mr. Dilip Risbud, Mr. Sameer D. Sahasrabuddhe, Ms. Shailaja Kulkarni, “VLSI : An article about
VLSI field and How to make career in this field”,
http://www.kokanastha.com/career_guide/introduction_VLSI.html
●
http://www.csee.umbc.edu/~tinoosh/cmpe650/slides/FPGAs-1.pdf
●
Dr. Esam Al-Qaralleh, “Introduction to Verilog Hardware Description Language”, Princess Sumaya
University for Technology
●
Thanasis Oikonomou, “Verilog HDL Basics,” Computer science department, University of Crete,
Greece, October 1998.