SlideShare a Scribd company logo
1 of 41
Download to read offline
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56
Basic Concepts
Mr. Anand H. D.
1
Basic Concepts
Department of Electronics & Communication Engineering
Dr. Ambedkar Institute of Technology
Bengaluru-56
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 2
Topics to be covered
Lexical conventions
Data types
System tasks and Compiler directives
Basic Concepts
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 3
Let us discuss about
Lexical conventions
Data types
System tasks and Compiler directives
Basic Concepts
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 4
Basic Concepts
Lexical conventions
īƒ˜Multiple-line comments cannot be nested. However, one-line comments can be
embedded in multiple-line comments.
1. Whitespace
īƒ˜Blank spaces (b) , tabs (t) and newlines (n) comprise the whitespace. Whitespace is
ignored by Verilog except when it separates tokens. Whitespace is not ignored in strings.
2. Comments
Comments can be inserted in the code for readability and documentation.
īƒ˜There are two ways to write comments.
īƒ˜A one-line comment starts with "//". Verilog skips from that point to the end of line.
īƒ˜A multiple-line comment starts with "/*" and ends with "*/".
Examples:
a = b && c; // This is a one-line comment
/* This is a multiple line comment */
/* This is /* an illegal */ comment */
/* This is //a legal comment */
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 5
Basic Concepts
Lexical conventions
3. Operators
īƒ˜Operators are of three types: unary, binary, and ternary.
īƒ˜Unary operators precede the operand.
īƒ˜Binary operators appear between two operands.
īƒ˜Ternary operators have two separate operators that separate three operands.
Examples: a = ~ b; // ~ is a unary operator. b is the operand
a = b && c; // && is a binary operator. b and c are operands
a = b ? c : d; // ?: is a ternary operator. b, c and d are operands
4. Number Specification
There are two types of number specification in Verilog: sized and unsized.
A.)Sized numbers
B.) Unsized numbers
C.) X or Z values
D.) Negative numbers
E.)Underscore characters and question marks
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 6
Basic Concepts
Lexical conventions
A.)Sized numbers
īƒ˜Sized numbers are represented as <size> '<base format> <number>.
īƒ˜<size> is written only in decimal and specifies the number of bits in the number.
īƒ˜Legal base formats are decimal ('d or 'D), hexadecimal ('h or 'H), binary ('b or
'B) and octal ('o or 'O).
īƒ˜The number is specified as consecutive digits from 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a,
b, c, d, e, f.
īƒ˜Only a subset of these digits is legal for a particular base.
īƒ˜Uppercase letters are legal for number specification.
Examples:
4'b1111 // This is a 4-bit binary number
12'habc // This is a 12-bit hexadecimal number
16'd255 // This is a 16-bit decimal number.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 7
Basic Concepts
Lexical conventions
B.) Unsized numbers
īƒ˜Numbers that are specified without a <base format> specification are decimal
numbers by default.
īƒ˜Numbers that are written without a <size> specification have a default number
of bits that is simulator- and machine-specific (must be at least 32).
Examples: 23456 // This is a 32-bit decimal number by default
'hc3 // This is a 32-bit hexadecimal number
'o21 // This is a 32-bit octal number
C.) X or Z values
Verilog has two symbols for unknown and high impedance values.
īƒ˜These values are very important for modeling real circuits.
īƒ˜An unknown value is denoted by an x.
īƒ˜A high impedance value is denoted by z.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 8
Basic Concepts
Lexical conventions
Examples:
12'h13x // This is a 12-bit hex number; 4 least significant bits unknown
6'hx // This is a 6-bit hex number
32‘dz // This is a 32-bit high impedance number
īƒ˜An x or z sets four bits for a number in the hexadecimal base, three bits for a
number in the octal base, and one bit for a number in the binary base.
īƒ˜If the most significant bit of a number is 0, x, or z, the number is automatically
extended to fill the most significant bits, respectively, with 0, x, or z. This makes it
easy to assign x or z to whole vector.
īƒ˜If the most significant digit is 1, then it is also zero extended.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 9
Basic Concepts
Lexical conventions
D.) Negative numbers
īƒ˜Negative numbers can be specified by putting a minus sign before the size for a
constant number.
īƒ˜Size constants are always positive. It is illegal to have a minus sign between
<base format> and <number>.
īƒ˜An optional signed specifier can be added for signed arithmetic.
Examples:
-6'd3 // 8-bit negative number stored as 2's complement of 3
-6'sd3 // Used for performing signed integer math
4'd-2 // Illegal specification also zero extended.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 10
Basic Concepts
Lexical conventions
E.)Underscore characters and question marks
īƒ˜An underscore character "_" is allowed anywhere in a number except the first
character.
īƒ˜Underscore characters are allowed only to improve readability of numbers and
are ignored by Verilog.
A question mark "?" is the Verilog HDL alternative for z in the context of numbers.
The ? is used to enhance readability in the casex and casez statements, where the
high impedance value is a don't care condition.
Examples:
12'b1111_0000_1010 // Use of underline characters for readability
4'b10?? // Equivalent of a 4'b10zz
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 11
Basic Concepts
Lexical conventions
5. Strings
A string is a sequence of characters that are enclosed by double quotes.
īƒ˜The restriction on a string is that it must be contained on a single line, that is, without a
carriage return. It cannot be on multiple lines.
īƒ˜Strings are treated as a sequence of one-byte ASCII values.
Examples: "Hello Verilog World" // is a string
"a / b" // is a string
6. Identifiers and Keywords
īƒ˜Keywords are special identifiers reserved to define the language constructs.
īƒ˜Keywords are in lowercase.
īƒ˜Identifiers are names given to objects so that they can be referenced in the design.
īƒ˜Identifiers are made up of alphanumeric characters, the underscore ( _ ), or the dollar sign ($).
Identifiers are case sensitive.
īƒ˜Identifiers start with an alphabetic character or an underscore. They cannot start with a digit
or a $ sign Examples: reg value; // reg is a keyword; value is an identifier
input clk; // input is a keyword, clk is an identifier
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 12
Basic Concepts
Lexical conventions
7. Escaped Identifiers
īƒ˜Escaped identifiers begin with the backslash (  ) character and end with
whitespace (space, tab, or newline).
īƒ˜All characters between backslash and whitespace are processed literally.
īƒ˜Any printable ASCII character can be included in escaped identifiers.
īƒ˜Neither the backslash nor the terminating whitespace is considered to be a part
of the identifier.
a+b-c
**my_name**
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 13
Let us discuss about
Lexical conventions
Data types
System tasks and Compiler directives
Basic Concepts
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 14
Basic Concepts
Data types
1. Value Set: Verilog supports four values and eight
strengths to model the functionality of real hardware
Value
Level
Condition in Hardware
Circuits
0 Logic zero, false condition
1 Logic one, true condition
x Unknown logic value
z
High impedance, floating
state
īƒ˜In addition to logic values, strength levels are often used to
resolve conflicts between drivers of different strengths in digital
circuits. Value levels 0 and 1 can have the strength levels listed
in table:
īƒ˜If two signals of unequal strengths are driven on a wire, the
stronger signal prevails. For example, if two signals of strength
strong1 and weak0 contend, the result is resolved as a strong1.
īƒ˜If two signals of equal strengths are driven on a wire, the
result is unknown. If two signals of strength strong1 and
strong0 conflict, the result is an x.
īƒ˜Strength levels are particularly useful for accurate modeling of
signal contention, MOS devices, dynamic MOS, and other low-
level devices.
īƒ˜Only trireg nets can have storage strengths large, medium, and
small.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 15
Basic Concepts
Data types
2. Nets: Nets represent connections between hardware elements.
īƒ˜In the figure net a is connected to the output of and gate g1.
Net a will continuously assume the value computed at the output of
gate g1, which is b & c.
īƒ˜Nets are declared primarily with the keyword wire.
īƒ˜Nets are one-bit values by default unless they are declared explicitly as vectors
īƒ˜The terms wire and net are often used interchangeably. The default value of a net is z
(except the trireg net, which defaults to x).
īƒ˜Nets get the output value of their drivers. If a net has no driver, it gets the value z.
wire a; // Declare net a for the above circuit
wire b,c; // Declare two wires b,c for the above circuit
wire d = 1'b0; // Net d is fixed to logic value 0 at declaration.
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.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 16
Basic Concepts
Data types
3 Register:
īƒ˜Registers represent data storage elements.
īƒ˜Registers retain value until another value is placed onto them.
īƒ˜In Verilog, the term register merely means a variable that can hold a value. Unlike a net, a
register does not need a driver.
īƒ˜Verilog registers do not need a clock as hardware registers do. Values of registers can be
changed anytime in a simulation by assigning a new value to the register.
īƒ˜Register data types are commonly declared by the keyword reg.
īƒ˜The default value for a reg data type is x.
Example-1 Example of Register
reg reset; // declare a variable reset that can hold its value
initial // this construct will be discussed later
begin reset = 1'b1; //initialize reset to 1 to reset the digital circuit.
#100 reset = 1'b0; // after 100 time units reset is deasserted
end
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 17
Basic Concepts
Data types
Registers can also be declared as signed variables. Such registers can be used for signed
arithmetic.
Example-2 Signed Register Declaration
reg signed [63:0] m; // 64 bit signed value
integer i; // 32 bit signed value
4 Vectors
īƒ˜Nets or reg data types can be declared as vectors (multiple bit widths).
īƒ˜If bit width is not specified, the default is scalar (1-bit).
wire a; // scalar net variable, default
wire [7:0] bus; // 8-bit bus
wire [31:0] busA,busB,busC; // 3 buses of 32-bit width.
reg clock; // scalar register, default
reg [0:40] virtual_addr; // Vector register, virtual address 41 bits wide
īƒ˜Vectors can be declared at [high# : low#] or [low# : high#], but the left number in the squared
brackets is always the most significant bit of the vector.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 18
Basic Concepts
Data types
Vectors can be declared at [high# : low#] or [low# : high#], but the left number in the squared
brackets is always the most significant bit of the vector.
Vector Part Select
It is possible to address bits or parts of vectors.
busA[7] // bit # 7 of vector busA
bus[2:0] // Three least significant bits of vector bus,
virtual_addr[0:1] // Two most significant bits of vector virtual_addr
Variable Vector Part Select
Verilog HDl supports variable part selects of a vector. This allows part selects to be put in for loops
to select various parts of the vector.
There are two special part-select operators:
[<starting_bit>+:width] - part-select increments from starting bit
[<starting_bit>-:width] - part-select decrements from starting bit
The starting bit of the part select can be varied, but the width has to be constant.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 19
Basic Concepts
Data types
The following example shows the use of variable vector part select:
reg [255:0] data1; //Little endian notation
reg [0:255] data2; //Big endian notation
reg [7:0] byte;
//Using a variable part select, one can choose parts
byte = data1[31-:8]; //starting bit = 31, width =8 => data[31:24]
byte = data1[24+:8]; //starting bit = 24, width =8 => data[31:24]
byte = data2[31-:8]; //starting bit = 31, width =8 => data[24:31]
byte = data2[24+:8]; //starting bit = 24, width =8 => data[24:31]
255 â€Ļ. â€Ļ. 0
31 24
255 â€Ļ. â€Ļ. 0
31 24
0 â€Ļ. â€Ļ. 255
24 31
24 31 â€Ļ. 255
0 â€Ļ.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 20
Basic Concepts
Data types
//The starting bit can also be a variable. The width has to be constant. Therefore, one can use
//the variable part select in a loop to select all bytes of the vector.
for (j=0; j<=31; j=j+1)
byte = data1[(j*8)+:8]; //Sequence is [7:0], [15:8]... [255:248]
255 â€Ļ.. 2
3
2
2
2
1
2
0
1
9
1
8
1
7
1
6
1
5
1
4
1
3
1
2
1
1
1
0
9 8 7 6 5 4 3 2 1 0
//Can initialize a part of the vector
data1[(byteNum*8)+:8] = 8'b0; //If byteNum = 1, clear 8 bits [15:8]
255 2
2
2
1
2
0
1
9
1
8
1
7
1
6
1
5
1
4
1
3
1
2
1
1
1
0
9 8 7 6 5 4 3 2 1 0
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
data1[(byteNum*5)-:10] = 10'b0; //If byteNum = 2
255 2
2
2
1
2
0
1
9
1
8
1
7
1
6
1
5
1
4
1
3
1
2
1
1
1
0
9 8 7 6 5 4 3 2 1 0
*
*
*
*
*
*
*
*
*
*
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 21
Basic Concepts
Data types
5.Integer , Real, and Time Register Data Types:
Integer, real, and time register data types are supported in Verilog.
Integer: An integer is a general purpose register data type used for manipulating quantities.
Integers are declared by the keyword integer.
īƒ˜It is more convenient to declare an integer variable for purposes such as counting.
īƒ˜The default width for an integer is the host-machine word size, which is implementation-
specific but is at least 32 bits.
īƒ˜Registers declared as data type reg store values as unsigned quantities, whereas integers store
values as signed quantities.
Examples:
integer counter; // general purpose variable used as a counter.
Initial
counter = -1; // A negative one is stored in the counter
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 22
Basic Concepts
Data types
Real: Real number constants and real register data types are declared with the keyword real.
īƒ˜Real numbers cannot have a range declaration, and their default value is 0.
Example:
real delta; // Define a real variable called delta
initial
begin
delta = 4e10; // delta is assigned in scientific notation
delta = 2.13; // delta is assigned a value 2.13
end
integer i; // Define an integer I
initial
i = delta; // i gets the value 2 (rounded value of 2.13)
īƒ˜They can be specified in decimal notation (e.g., 3.14) or in scientific notation (e.g., 3e6, which
is 3 x 106 ).
īƒ˜When a real value is assigned to an integer, the real number is rounded off to the
nearest integer.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 23
Basic Concepts
Data types
Time: Verilog simulation is done with respect to simulation time. A special time register data type
is used in Verilog to store simulation time.
īƒ˜A time variable is declared with the keyword time. The width for time register data types is
implementation-specific but is at least 64 bits.
īƒ˜The system function $time is invoked to get the current simulation time.
Example:
time save_sim_time; // Define a time variable save_sim_time
Initial
save_sim_time = $time; // Save the current simulation time
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 24
Basic Concepts
Data types
Arrays: Arrays are allowed in Verilog for reg, integer, time, real, realtime and vector register data
types.
īƒ˜Multi-dimensional arrays can also be declared with any number of dimensions.
īƒ˜Arrays of nets can also be used to connect ports of generated instances.
īƒ˜Each element of the array can be used in the same fashion as a scalar or vector net.
īƒ˜Arrays are accessed by <array_name>[<subscript>]. For multi-dimensional arrays, indexes
need to be provided for each dimension.
Example:
integer count[0:7]; // An array of 8 count variables
reg bool[31:0]; // Array of 32 one-bit boolean register variables
time chk_point[1:100]; // Array of 100 time checkpoint variables
reg [4:0] port_id[0:7]; // Array of 8 port_ids; each port_id is 5 bits wide integer
matrix[4:0][0:255]; // Two dimensional array of integers
reg [63:0] array_4d [15:0][7:0][7:0][255:0]; //Four dimensional array
wire [7:0] w_array2 [5:0]; // Declare an array of 8 bit vector wire
wire w_array1[7:0][5:0]; // Declare an array of single bit wires
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 25
Basic Concepts
Data types
īƒ˜It is important not to confuse arrays with net or register vectors.
īƒ˜A vector is a single element that is n-bits wide.
īƒ˜On the other hand, arrays are multiple elements that are 1-bit or n-bits wide
Examples of assignments to elements of arrays discussed above are shown below:
count[5] = 0; // Reset 5th element of array of count variables
chk_point[100] = 0; // Reset 100th time check point value
port_id[3] = 0; // Reset 3rd element (a 5-bit value) of port_id array.
matrix[1][0] = 33559; // Set value of element indexed by [1][0] to 33559
array_4d[0][0][0][0][15:0] = 0; //Clear bits 15:0 of the register accessed by indices [0][0][0][0]
port_id = 0; // Illegal syntax - Attempt to write the entire array
matrix [1] = 0; // Illegal syntax Attempt to write [1][0]..[1][255]
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 26
Basic Concepts
Data types
Memories: In digital simulation, one often needs to model register files, RAMs, and ROMs.
Memories are modeled in Verilog simply as a one-dimensional array of registers.
īƒ˜Each element of the array is known as an element or word and is addressed by a single array
index.
īƒ˜Each word can be one or more bits. It is important to differentiate between n 1-bit registers
and one n-bit register.
īƒ˜A particular word in memory is obtained by using the address as a memory array subscript.
Examples:
reg mem1bit[0:1023]; // Memory mem1bit with 1K 1-bit words
reg [7:0] membyte[0:1023]; // Memory membyte with 1K 8-bit words(bytes)
membyte[511] // Fetches 1 byte word whose address is 511
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 27
Basic Concepts
Data types
Parameters
īƒ˜Verilog allows constants to be defined in a module by the keyword parameter.
īƒ˜Parameters cannot be used as variables. Parameter values for each module instance can be
overridden individually at compile time. This allows the module instances to be customized.
Parameter types and sizes can also be defined.
Examples:
parameter port_id = 5; // Defines a constant port_id
Parameter cache_line_width = 256; // Constant defines width of cache line
parameter signed [15:0] WIDTH; // Fixed sign and range for parameter WIDTH
īƒ˜Module definitions may be written in terms of parameters. Hardcoded numbers should be
avoided. Parameters values can be changed at module instantiation or by using the
defparam statement. Thus, the use of parameters makes the module definition flexible.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 28
Basic Concepts
Data types
īƒ˜Module behavior can be altered simply by changing the value of a parameter.
īƒ˜Verilog HDL local parameters (defined using keyword localparam -) are identical to
parameters except that they cannot be directly modified with the defparam statement or by the
ordered or named parameter value assignment..
localparam state1 = 4'b0001,
state2 = 4'b0010,
state3 = 4'b0100,
state4 = 4'b1000;
īƒ˜The localparam keyword is used to define parameters when their values should not be
changed.
īƒ˜For example, the state encoding for a state machine can be defined using localparam. The
state encoding cannot be changed. This provides protection against inadvertent parameter
redefinition.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 29
Basic Concepts
Data types
Strings
īƒ˜Strings can be stored in reg. The width of the register variables must be large enough to hold
the string.
īƒ˜Each character in the string takes up 8 bits (1 byte).
īƒ˜If the width of the register is greater than the size of the string, Verilog fills bits to the left of
the string with zeros.
īƒ˜If the register width is smaller than the string width, Verilog truncates the leftmost bits of the
string.
īƒ˜It is always safe to declare a string that is slightly wider than necessary.
reg [8*18:1] string_value; // Declare a variable that is 18 bytes wide
initial
string_value = "Hello Verilog World"; // String can be stored in variable
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 30
Basic Concepts
Data types
īƒ˜Special characters serve a special purpose in displaying strings, such as newline, tabs, and
displaying argument values.
īƒ˜Special characters can be displayed in strings only when they are preceded by escape
characters, as shown in Table.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 31
Let us discuss about
Lexical conventions
Data types
System tasks and Compiler directives
Basic Concepts
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 32
Basic Concepts
System tasks and Compiler directives
īƒ˜Verilog provides standard system tasks for certain routine operations.
īƒ˜All system tasks appear in the form $<keyword>.
īƒ˜$display is the main system task for displaying values of variables or strings or expressions.
This is one of the most useful tasks in Verilog.
Displaying information
īƒ˜Usage: $display(p1, p2, p3,....., pn);
p1, p2, p3,..., pn can be quoted strings or variables or expressions.
īƒ˜The format of $display is very similar to printf in C.
īƒ˜A $display inserts a newline at the end of the string by default.
īƒ˜A $display without any arguments produces a newline.
īƒ˜Operations such as displaying on the screen, monitoring values of nets, stopping, and
finishing are done by system tasks.
īƒ˜We will discuss only the most useful system tasks. Other tasks are listed in Verilog manuals
provided by your simulator vendor or in the IEEE Standard Verilog Hardware Description
Language specification.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 33
Basic Concepts
System tasks and Compiler directives
īƒ˜Strings can be formatted using the specifications
listed in Table.
Example-$display Task
//Display the string in quotes
$display("Hello Verilog World");
-- Hello Verilog World
//Display value of current simulation time 230
$display($time);
-- 230
//Display value of 41-bit virtual address 1fe0000001c at time
200
reg [0:40] virtual_addr;
$display("At time %d virtual address is %h", $time,
virtual_addr);
-- At time 200 virtual address is 1fe0000001c
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 34
Basic Concepts
System tasks and Compiler directives
Example - $display Task
//Display value of port_id 5 in binary
reg [4:0] port_id;
$display("ID of the port is %b", port_id);
-- ID of the port is 00101
//Display x characters
//Display value of 4-bit bus 10xx (signal contention) in binary
reg [3:0] bus;
$display("Bus value is %b", bus);
-- Bus value is 10xx
/*Display the hierarchical name of instance p1 instantiated
under the highest-level module called top. No argument is
required. This is a useful feature*/
$display("This string is displayed from %m level of hierarchy");
-- This string is displayed from top.p1 level of hierarchy
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 35
Basic Concepts
System tasks and Compiler directives
Example- Special Characters
//Display special characters, newline and %
$display("This is a n multiline string with a %% sign");
-- This is a
-- multiline string with a % sign
īƒ˜Verilog provides a mechanism to monitor a signal when its value changes.
īƒ˜This facility is provided by the $monitor task.
Monitoring information
īƒ˜Usage: $monitor(p1, p2, p3,....., pn);
The parameters p1, p2, ... , pn can be variables, signal names, or quoted strings.
īƒ˜A format similar to the $display task is used in the $monitor task. $monitor continuously
monitors the values of the variables or signals specified in the parameter list and displays all
parameters in the list whenever the value of any one variable or signal changes.
īƒ˜Unlike $display, $monitor needs to be invoked only once.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 36
Basic Concepts
System tasks and Compiler directives
īƒ˜Only one monitoring list can be active at a time. If there is more than one $monitor statement
in your simulation, the last $monitor statement will be the active statement.
īƒ˜The earlier $monitor statements will be overridden.
īƒ˜ Two tasks are used to switch monitoring on and off.
Usage:
$monitoron;
$monitoroff;
īƒ˜The $monitoron tasks enables monitoring, and the $monitoroff task disables
monitoring during a simulation.
īƒ˜Monitoring is turned on by default at the beginning of the simulation and can
be controlled during the simulation with the $monitoron and $monitoroff tasks.
Example- Monitor Statement
//Monitor time and value of the signals clock and reset
//Clock toggles every 5 time units and reset goes down at 10 time units
initial
begin
$monitor($time,
" Value of signals clock = %b reset = %b", clock,reset);
end
Partial output of the monitor statement:
-- 0 Value of signals clock = 0 reset = 1
-- 5 Value of signals clock = 1 reset = 1
-- 10 Value of signals clock = 0 reset = 0
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 37
Basic Concepts
System tasks and Compiler directives
īƒ˜The task $stop is provided to stop during a simulation.
Stopping and finishing in a simulation
īƒ˜Usage: $stop
īƒ˜The $stop task puts the simulation in an interactive mode. The designer can then debug
the design from the interactive mode.
īƒ˜The $finish task terminates the simulation.
īƒ˜Usage: $finish
Example-Stop and Finish Tasks
// Stop at time 100 in the simulation and examine the results
// Finish the simulation at time 1000.
initial // to be explained later. time = 0
begin
clock = 0;
reset = 1;
#100 $stop; // This will suspend the simulation at time = 100
#900 $finish; // This will terminate the simulation at time = 1000
end
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 38
Basic Concepts
System tasks and Compiler directives
Example- `define Directive
//define a text macro that defines default word size
//Used as 'WORD_SIZE in the code
'define WORD_SIZE 32
//define an alias. A $stop will be substituted wherever 'S appears
'define S $stop;
//define a frequently used text string
'define WORD_REG reg [31:0]
// you can then define a 32-bit register as 'WORD_REG reg32;
Compiler Directives
īƒ˜Compiler directives are provided in Verilog. All compiler directives are defined by using the
`<keyword> construct. We deal with the two most useful compiler directives.
`define
īƒ˜The `define directive is used to define text macros in Verilog.
īƒ˜The Verilog compiler substitutes the text of the macro wherever it encounters a
`<macro_name>.
īƒ˜This is similar to the #define construct in C.
īƒ˜The defined constants or text macros are used in the Verilog code by preceding them with a
` (back tick).
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 39
Basic Concepts
System tasks and Compiler directives
Example `include Directive
// Include the file header.v, which contains declarations in the
// main verilog file design.v.
'include header.v
...
...
<Verilog code in file design.v>
...
...
`include
īƒ˜The `include directive allows you to include entire contents of a Verilog source file in
another Verilog file during compilation.
īƒ˜This works similarly to the #include in the C programming language.
īƒ˜This directive is typically used to include header files, which typically contain global or
commonly used definitions
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 20
Basic Concepts
Reference
Samir Palnitkar, “Verilog HDL – A guide to Digital
Design and Synthesis”, Pearson, 2003
For Further Studies
Prof. Anand H. D.
M. Tech. (PhD.)
Assistant Professor,
Department of Electronics & Communication Engineering
Dr. Ambedkar Institute of Technology, Bengaluru-56
Email: anandhd.ec@drait.edu.in
Phone: 9844518832

More Related Content

What's hot

VHDL-PRESENTATION.ppt
VHDL-PRESENTATION.pptVHDL-PRESENTATION.ppt
VHDL-PRESENTATION.pptDr.YNM
 
gate level modeling
gate level modelinggate level modeling
gate level modelingVandanaBR2
 
An Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl pprAn Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl pprPrabhavathi P
 
Verilog VHDL code Multiplexer and De Multiplexer
Verilog VHDL code Multiplexer and De Multiplexer Verilog VHDL code Multiplexer and De Multiplexer
Verilog VHDL code Multiplexer and De Multiplexer Bharti Airtel Ltd.
 
axi protocol
axi protocolaxi protocol
axi protocolAzad Mishra
 
Vlsi physical design-notes
Vlsi physical design-notesVlsi physical design-notes
Vlsi physical design-notesDr.YNM
 
Day2 Verilog HDL Basic
Day2 Verilog HDL BasicDay2 Verilog HDL Basic
Day2 Verilog HDL BasicRon Liu
 
verilog code for logic gates
verilog code for logic gatesverilog code for logic gates
verilog code for logic gatesRakesh kumar jha
 
Divide by N clock
Divide by N clockDivide by N clock
Divide by N clockMantra VLSI
 
VLSI Fresher Resume
VLSI Fresher ResumeVLSI Fresher Resume
VLSI Fresher Resumevikas kumar
 
System verilog important
System verilog importantSystem verilog important
System verilog importantelumalai7
 
VLSI Testing Techniques
VLSI Testing TechniquesVLSI Testing Techniques
VLSI Testing TechniquesA B Shinde
 
Design your career in VLSI
Design your career in VLSIDesign your career in VLSI
Design your career in VLSIM. Raja Reddy
 

What's hot (20)

VHDL-PRESENTATION.ppt
VHDL-PRESENTATION.pptVHDL-PRESENTATION.ppt
VHDL-PRESENTATION.ppt
 
gate level modeling
gate level modelinggate level modeling
gate level modeling
 
An Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl pprAn Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl ppr
 
Verilog VHDL code Multiplexer and De Multiplexer
Verilog VHDL code Multiplexer and De Multiplexer Verilog VHDL code Multiplexer and De Multiplexer
Verilog VHDL code Multiplexer and De Multiplexer
 
axi protocol
axi protocolaxi protocol
axi protocol
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
 
Vhdl programming
Vhdl programmingVhdl programming
Vhdl programming
 
Verilog
VerilogVerilog
Verilog
 
Vlsi physical design-notes
Vlsi physical design-notesVlsi physical design-notes
Vlsi physical design-notes
 
Day2 Verilog HDL Basic
Day2 Verilog HDL BasicDay2 Verilog HDL Basic
Day2 Verilog HDL Basic
 
Verilog hdl
Verilog hdlVerilog hdl
Verilog hdl
 
verilog code for logic gates
verilog code for logic gatesverilog code for logic gates
verilog code for logic gates
 
Divide by N clock
Divide by N clockDivide by N clock
Divide by N clock
 
Verilog Tasks and functions
Verilog Tasks and functionsVerilog Tasks and functions
Verilog Tasks and functions
 
VLSI Fresher Resume
VLSI Fresher ResumeVLSI Fresher Resume
VLSI Fresher Resume
 
VERY LARGE SCALE INTEGRATION (VLSI) TECHNOLOGY
VERY LARGE SCALE INTEGRATION (VLSI) TECHNOLOGYVERY LARGE SCALE INTEGRATION (VLSI) TECHNOLOGY
VERY LARGE SCALE INTEGRATION (VLSI) TECHNOLOGY
 
System verilog important
System verilog importantSystem verilog important
System verilog important
 
VLSI Testing Techniques
VLSI Testing TechniquesVLSI Testing Techniques
VLSI Testing Techniques
 
Design your career in VLSI
Design your career in VLSIDesign your career in VLSI
Design your career in VLSI
 
Vlsi
VlsiVlsi
Vlsi
 

Similar to Basic concepts in Verilog HDL

VHDL_Lecture_new1 [Autosaved].ppt
VHDL_Lecture_new1 [Autosaved].pptVHDL_Lecture_new1 [Autosaved].ppt
VHDL_Lecture_new1 [Autosaved].pptNAVEENM849290
 
Fpga 05-verilog-programming
Fpga 05-verilog-programmingFpga 05-verilog-programming
Fpga 05-verilog-programmingMalik Tauqir Hasan
 
Verilog Final Probe'22.pptx
Verilog Final Probe'22.pptxVerilog Final Probe'22.pptx
Verilog Final Probe'22.pptxSyedAzim6
 
Chapter 4:Object-Oriented Basic Concepts
Chapter 4:Object-Oriented Basic ConceptsChapter 4:Object-Oriented Basic Concepts
Chapter 4:Object-Oriented Basic ConceptsIt Academy
 
the-vhsic-.pptx
the-vhsic-.pptxthe-vhsic-.pptx
the-vhsic-.pptxjpradha86
 
Vhdl introduction
Vhdl introductionVhdl introduction
Vhdl introductionVandanaPagar1
 
Chap1 language fondamentale of java ( scjp /ocjp)
Chap1 language fondamentale of java ( scjp /ocjp)Chap1 language fondamentale of java ( scjp /ocjp)
Chap1 language fondamentale of java ( scjp /ocjp)It Academy
 
VHDL- data types
VHDL- data typesVHDL- data types
VHDL- data typesVandanaPagar1
 
System Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLSystem Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLE2MATRIX
 
C# Data Types and Comments_Lecture2_C#.pdf
C# Data Types and Comments_Lecture2_C#.pdfC# Data Types and Comments_Lecture2_C#.pdf
C# Data Types and Comments_Lecture2_C#.pdfAzhar Babil
 
System design using HDL - Module 1
System design using HDL - Module 1System design using HDL - Module 1
System design using HDL - Module 1Aravinda Koithyar
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITASIT
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)IJERD Editor
 
Fpga implementation of linear ldpc encoder
Fpga implementation of linear ldpc encoderFpga implementation of linear ldpc encoder
Fpga implementation of linear ldpc encodereSAT Journals
 
Literals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersLiterals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersTanishq Soni
 

Similar to Basic concepts in Verilog HDL (20)

DDUV.pdf
DDUV.pdfDDUV.pdf
DDUV.pdf
 
VHDL_Lecture_new1 [Autosaved].ppt
VHDL_Lecture_new1 [Autosaved].pptVHDL_Lecture_new1 [Autosaved].ppt
VHDL_Lecture_new1 [Autosaved].ppt
 
Verilogspk1
Verilogspk1Verilogspk1
Verilogspk1
 
Verilog HDL
Verilog HDL Verilog HDL
Verilog HDL
 
Fpga 05-verilog-programming
Fpga 05-verilog-programmingFpga 05-verilog-programming
Fpga 05-verilog-programming
 
Verilog Final Probe'22.pptx
Verilog Final Probe'22.pptxVerilog Final Probe'22.pptx
Verilog Final Probe'22.pptx
 
Chapter 4:Object-Oriented Basic Concepts
Chapter 4:Object-Oriented Basic ConceptsChapter 4:Object-Oriented Basic Concepts
Chapter 4:Object-Oriented Basic Concepts
 
the-vhsic-.pptx
the-vhsic-.pptxthe-vhsic-.pptx
the-vhsic-.pptx
 
Vhdl introduction
Vhdl introductionVhdl introduction
Vhdl introduction
 
Chap1 language fondamentale of java ( scjp /ocjp)
Chap1 language fondamentale of java ( scjp /ocjp)Chap1 language fondamentale of java ( scjp /ocjp)
Chap1 language fondamentale of java ( scjp /ocjp)
 
Spdas2 vlsibput
Spdas2 vlsibputSpdas2 vlsibput
Spdas2 vlsibput
 
VHDL- data types
VHDL- data typesVHDL- data types
VHDL- data types
 
System Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLSystem Verilog Tutorial - VHDL
System Verilog Tutorial - VHDL
 
C# Data Types and Comments_Lecture2_C#.pdf
C# Data Types and Comments_Lecture2_C#.pdfC# Data Types and Comments_Lecture2_C#.pdf
C# Data Types and Comments_Lecture2_C#.pdf
 
System design using HDL - Module 1
System design using HDL - Module 1System design using HDL - Module 1
System design using HDL - Module 1
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASIT
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)
 
Fpga implementation of linear ldpc encoder
Fpga implementation of linear ldpc encoderFpga implementation of linear ldpc encoder
Fpga implementation of linear ldpc encoder
 
Literals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersLiterals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiers
 
Vhdl 1 ppg
Vhdl 1 ppgVhdl 1 ppg
Vhdl 1 ppg
 

More from anand hd

RMV sensors
RMV sensorsRMV sensors
RMV sensorsanand hd
 
RMV robot programming
RMV robot programmingRMV robot programming
RMV robot programminganand hd
 
Robot applications
Robot applicationsRobot applications
Robot applicationsanand hd
 
RMV Mechanics
RMV MechanicsRMV Mechanics
RMV Mechanicsanand hd
 
Robot Machine Vision
Robot Machine VisionRobot Machine Vision
Robot Machine Visionanand hd
 
RMV Artificial Intelligence
RMV Artificial IntelligenceRMV Artificial Intelligence
RMV Artificial Intelligenceanand hd
 
OS file systems
OS file systemsOS file systems
OS file systemsanand hd
 
OS virtual memory
OS virtual memoryOS virtual memory
OS virtual memoryanand hd
 
OS scheduling
OS schedulingOS scheduling
OS schedulinganand hd
 
OS Memory Management
OS Memory ManagementOS Memory Management
OS Memory Managementanand hd
 
Characteristics and Quality Attributes of Embedded System
Characteristics and Quality Attributes of Embedded SystemCharacteristics and Quality Attributes of Embedded System
Characteristics and Quality Attributes of Embedded Systemanand hd
 
Typical Embedded System
Typical Embedded SystemTypical Embedded System
Typical Embedded Systemanand hd
 
OS-Process Management
OS-Process ManagementOS-Process Management
OS-Process Managementanand hd
 
Robotics Endeffectors
Robotics EndeffectorsRobotics Endeffectors
Robotics Endeffectorsanand hd
 
Structure of Operating System
Structure of Operating System Structure of Operating System
Structure of Operating System anand hd
 
Fundamentals of Robotics and Machine Vision System
Fundamentals of Robotics and Machine Vision SystemFundamentals of Robotics and Machine Vision System
Fundamentals of Robotics and Machine Vision Systemanand hd
 
Os overview
Os overviewOs overview
Os overviewanand hd
 
OS introduction
OS introductionOS introduction
OS introductionanand hd
 
Robotics and Automation Introduction
Robotics and Automation IntroductionRobotics and Automation Introduction
Robotics and Automation Introductionanand hd
 
Programmable Logic Devices
Programmable Logic DevicesProgrammable Logic Devices
Programmable Logic Devicesanand hd
 

More from anand hd (20)

RMV sensors
RMV sensorsRMV sensors
RMV sensors
 
RMV robot programming
RMV robot programmingRMV robot programming
RMV robot programming
 
Robot applications
Robot applicationsRobot applications
Robot applications
 
RMV Mechanics
RMV MechanicsRMV Mechanics
RMV Mechanics
 
Robot Machine Vision
Robot Machine VisionRobot Machine Vision
Robot Machine Vision
 
RMV Artificial Intelligence
RMV Artificial IntelligenceRMV Artificial Intelligence
RMV Artificial Intelligence
 
OS file systems
OS file systemsOS file systems
OS file systems
 
OS virtual memory
OS virtual memoryOS virtual memory
OS virtual memory
 
OS scheduling
OS schedulingOS scheduling
OS scheduling
 
OS Memory Management
OS Memory ManagementOS Memory Management
OS Memory Management
 
Characteristics and Quality Attributes of Embedded System
Characteristics and Quality Attributes of Embedded SystemCharacteristics and Quality Attributes of Embedded System
Characteristics and Quality Attributes of Embedded System
 
Typical Embedded System
Typical Embedded SystemTypical Embedded System
Typical Embedded System
 
OS-Process Management
OS-Process ManagementOS-Process Management
OS-Process Management
 
Robotics Endeffectors
Robotics EndeffectorsRobotics Endeffectors
Robotics Endeffectors
 
Structure of Operating System
Structure of Operating System Structure of Operating System
Structure of Operating System
 
Fundamentals of Robotics and Machine Vision System
Fundamentals of Robotics and Machine Vision SystemFundamentals of Robotics and Machine Vision System
Fundamentals of Robotics and Machine Vision System
 
Os overview
Os overviewOs overview
Os overview
 
OS introduction
OS introductionOS introduction
OS introduction
 
Robotics and Automation Introduction
Robotics and Automation IntroductionRobotics and Automation Introduction
Robotics and Automation Introduction
 
Programmable Logic Devices
Programmable Logic DevicesProgrammable Logic Devices
Programmable Logic Devices
 

Recently uploaded

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEslot gacor bisa pakai pulsa
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 

Recently uploaded (20)

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 

Basic concepts in Verilog HDL

  • 1. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 Basic Concepts Mr. Anand H. D. 1 Basic Concepts Department of Electronics & Communication Engineering Dr. Ambedkar Institute of Technology Bengaluru-56
  • 2. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 2 Topics to be covered Lexical conventions Data types System tasks and Compiler directives Basic Concepts
  • 3. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 3 Let us discuss about Lexical conventions Data types System tasks and Compiler directives Basic Concepts
  • 4. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 4 Basic Concepts Lexical conventions īƒ˜Multiple-line comments cannot be nested. However, one-line comments can be embedded in multiple-line comments. 1. Whitespace īƒ˜Blank spaces (b) , tabs (t) and newlines (n) comprise the whitespace. Whitespace is ignored by Verilog except when it separates tokens. Whitespace is not ignored in strings. 2. Comments Comments can be inserted in the code for readability and documentation. īƒ˜There are two ways to write comments. īƒ˜A one-line comment starts with "//". Verilog skips from that point to the end of line. īƒ˜A multiple-line comment starts with "/*" and ends with "*/". Examples: a = b && c; // This is a one-line comment /* This is a multiple line comment */ /* This is /* an illegal */ comment */ /* This is //a legal comment */
  • 5. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 5 Basic Concepts Lexical conventions 3. Operators īƒ˜Operators are of three types: unary, binary, and ternary. īƒ˜Unary operators precede the operand. īƒ˜Binary operators appear between two operands. īƒ˜Ternary operators have two separate operators that separate three operands. Examples: a = ~ b; // ~ is a unary operator. b is the operand a = b && c; // && is a binary operator. b and c are operands a = b ? c : d; // ?: is a ternary operator. b, c and d are operands 4. Number Specification There are two types of number specification in Verilog: sized and unsized. A.)Sized numbers B.) Unsized numbers C.) X or Z values D.) Negative numbers E.)Underscore characters and question marks
  • 6. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 6 Basic Concepts Lexical conventions A.)Sized numbers īƒ˜Sized numbers are represented as <size> '<base format> <number>. īƒ˜<size> is written only in decimal and specifies the number of bits in the number. īƒ˜Legal base formats are decimal ('d or 'D), hexadecimal ('h or 'H), binary ('b or 'B) and octal ('o or 'O). īƒ˜The number is specified as consecutive digits from 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f. īƒ˜Only a subset of these digits is legal for a particular base. īƒ˜Uppercase letters are legal for number specification. Examples: 4'b1111 // This is a 4-bit binary number 12'habc // This is a 12-bit hexadecimal number 16'd255 // This is a 16-bit decimal number.
  • 7. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 7 Basic Concepts Lexical conventions B.) Unsized numbers īƒ˜Numbers that are specified without a <base format> specification are decimal numbers by default. īƒ˜Numbers that are written without a <size> specification have a default number of bits that is simulator- and machine-specific (must be at least 32). Examples: 23456 // This is a 32-bit decimal number by default 'hc3 // This is a 32-bit hexadecimal number 'o21 // This is a 32-bit octal number C.) X or Z values Verilog has two symbols for unknown and high impedance values. īƒ˜These values are very important for modeling real circuits. īƒ˜An unknown value is denoted by an x. īƒ˜A high impedance value is denoted by z.
  • 8. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 8 Basic Concepts Lexical conventions Examples: 12'h13x // This is a 12-bit hex number; 4 least significant bits unknown 6'hx // This is a 6-bit hex number 32‘dz // This is a 32-bit high impedance number īƒ˜An x or z sets four bits for a number in the hexadecimal base, three bits for a number in the octal base, and one bit for a number in the binary base. īƒ˜If the most significant bit of a number is 0, x, or z, the number is automatically extended to fill the most significant bits, respectively, with 0, x, or z. This makes it easy to assign x or z to whole vector. īƒ˜If the most significant digit is 1, then it is also zero extended.
  • 9. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 9 Basic Concepts Lexical conventions D.) Negative numbers īƒ˜Negative numbers can be specified by putting a minus sign before the size for a constant number. īƒ˜Size constants are always positive. It is illegal to have a minus sign between <base format> and <number>. īƒ˜An optional signed specifier can be added for signed arithmetic. Examples: -6'd3 // 8-bit negative number stored as 2's complement of 3 -6'sd3 // Used for performing signed integer math 4'd-2 // Illegal specification also zero extended.
  • 10. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 10 Basic Concepts Lexical conventions E.)Underscore characters and question marks īƒ˜An underscore character "_" is allowed anywhere in a number except the first character. īƒ˜Underscore characters are allowed only to improve readability of numbers and are ignored by Verilog. A question mark "?" is the Verilog HDL alternative for z in the context of numbers. The ? is used to enhance readability in the casex and casez statements, where the high impedance value is a don't care condition. Examples: 12'b1111_0000_1010 // Use of underline characters for readability 4'b10?? // Equivalent of a 4'b10zz
  • 11. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 11 Basic Concepts Lexical conventions 5. Strings A string is a sequence of characters that are enclosed by double quotes. īƒ˜The restriction on a string is that it must be contained on a single line, that is, without a carriage return. It cannot be on multiple lines. īƒ˜Strings are treated as a sequence of one-byte ASCII values. Examples: "Hello Verilog World" // is a string "a / b" // is a string 6. Identifiers and Keywords īƒ˜Keywords are special identifiers reserved to define the language constructs. īƒ˜Keywords are in lowercase. īƒ˜Identifiers are names given to objects so that they can be referenced in the design. īƒ˜Identifiers are made up of alphanumeric characters, the underscore ( _ ), or the dollar sign ($). Identifiers are case sensitive. īƒ˜Identifiers start with an alphabetic character or an underscore. They cannot start with a digit or a $ sign Examples: reg value; // reg is a keyword; value is an identifier input clk; // input is a keyword, clk is an identifier
  • 12. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 12 Basic Concepts Lexical conventions 7. Escaped Identifiers īƒ˜Escaped identifiers begin with the backslash ( ) character and end with whitespace (space, tab, or newline). īƒ˜All characters between backslash and whitespace are processed literally. īƒ˜Any printable ASCII character can be included in escaped identifiers. īƒ˜Neither the backslash nor the terminating whitespace is considered to be a part of the identifier. a+b-c **my_name**
  • 13. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 13 Let us discuss about Lexical conventions Data types System tasks and Compiler directives Basic Concepts
  • 14. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 14 Basic Concepts Data types 1. Value Set: Verilog supports four values and eight strengths to model the functionality of real hardware Value Level Condition in Hardware Circuits 0 Logic zero, false condition 1 Logic one, true condition x Unknown logic value z High impedance, floating state īƒ˜In addition to logic values, strength levels are often used to resolve conflicts between drivers of different strengths in digital circuits. Value levels 0 and 1 can have the strength levels listed in table: īƒ˜If two signals of unequal strengths are driven on a wire, the stronger signal prevails. For example, if two signals of strength strong1 and weak0 contend, the result is resolved as a strong1. īƒ˜If two signals of equal strengths are driven on a wire, the result is unknown. If two signals of strength strong1 and strong0 conflict, the result is an x. īƒ˜Strength levels are particularly useful for accurate modeling of signal contention, MOS devices, dynamic MOS, and other low- level devices. īƒ˜Only trireg nets can have storage strengths large, medium, and small.
  • 15. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 15 Basic Concepts Data types 2. Nets: Nets represent connections between hardware elements. īƒ˜In the figure net a is connected to the output of and gate g1. Net a will continuously assume the value computed at the output of gate g1, which is b & c. īƒ˜Nets are declared primarily with the keyword wire. īƒ˜Nets are one-bit values by default unless they are declared explicitly as vectors īƒ˜The terms wire and net are often used interchangeably. The default value of a net is z (except the trireg net, which defaults to x). īƒ˜Nets get the output value of their drivers. If a net has no driver, it gets the value z. wire a; // Declare net a for the above circuit wire b,c; // Declare two wires b,c for the above circuit wire d = 1'b0; // Net d is fixed to logic value 0 at declaration. 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.
  • 16. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 16 Basic Concepts Data types 3 Register: īƒ˜Registers represent data storage elements. īƒ˜Registers retain value until another value is placed onto them. īƒ˜In Verilog, the term register merely means a variable that can hold a value. Unlike a net, a register does not need a driver. īƒ˜Verilog registers do not need a clock as hardware registers do. Values of registers can be changed anytime in a simulation by assigning a new value to the register. īƒ˜Register data types are commonly declared by the keyword reg. īƒ˜The default value for a reg data type is x. Example-1 Example of Register reg reset; // declare a variable reset that can hold its value initial // this construct will be discussed later begin reset = 1'b1; //initialize reset to 1 to reset the digital circuit. #100 reset = 1'b0; // after 100 time units reset is deasserted end
  • 17. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 17 Basic Concepts Data types Registers can also be declared as signed variables. Such registers can be used for signed arithmetic. Example-2 Signed Register Declaration reg signed [63:0] m; // 64 bit signed value integer i; // 32 bit signed value 4 Vectors īƒ˜Nets or reg data types can be declared as vectors (multiple bit widths). īƒ˜If bit width is not specified, the default is scalar (1-bit). wire a; // scalar net variable, default wire [7:0] bus; // 8-bit bus wire [31:0] busA,busB,busC; // 3 buses of 32-bit width. reg clock; // scalar register, default reg [0:40] virtual_addr; // Vector register, virtual address 41 bits wide īƒ˜Vectors can be declared at [high# : low#] or [low# : high#], but the left number in the squared brackets is always the most significant bit of the vector.
  • 18. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 18 Basic Concepts Data types Vectors can be declared at [high# : low#] or [low# : high#], but the left number in the squared brackets is always the most significant bit of the vector. Vector Part Select It is possible to address bits or parts of vectors. busA[7] // bit # 7 of vector busA bus[2:0] // Three least significant bits of vector bus, virtual_addr[0:1] // Two most significant bits of vector virtual_addr Variable Vector Part Select Verilog HDl supports variable part selects of a vector. This allows part selects to be put in for loops to select various parts of the vector. There are two special part-select operators: [<starting_bit>+:width] - part-select increments from starting bit [<starting_bit>-:width] - part-select decrements from starting bit The starting bit of the part select can be varied, but the width has to be constant.
  • 19. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 19 Basic Concepts Data types The following example shows the use of variable vector part select: reg [255:0] data1; //Little endian notation reg [0:255] data2; //Big endian notation reg [7:0] byte; //Using a variable part select, one can choose parts byte = data1[31-:8]; //starting bit = 31, width =8 => data[31:24] byte = data1[24+:8]; //starting bit = 24, width =8 => data[31:24] byte = data2[31-:8]; //starting bit = 31, width =8 => data[24:31] byte = data2[24+:8]; //starting bit = 24, width =8 => data[24:31] 255 â€Ļ. â€Ļ. 0 31 24 255 â€Ļ. â€Ļ. 0 31 24 0 â€Ļ. â€Ļ. 255 24 31 24 31 â€Ļ. 255 0 â€Ļ. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  • 20. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 20 Basic Concepts Data types //The starting bit can also be a variable. The width has to be constant. Therefore, one can use //the variable part select in a loop to select all bytes of the vector. for (j=0; j<=31; j=j+1) byte = data1[(j*8)+:8]; //Sequence is [7:0], [15:8]... [255:248] 255 â€Ļ.. 2 3 2 2 2 1 2 0 1 9 1 8 1 7 1 6 1 5 1 4 1 3 1 2 1 1 1 0 9 8 7 6 5 4 3 2 1 0 //Can initialize a part of the vector data1[(byteNum*8)+:8] = 8'b0; //If byteNum = 1, clear 8 bits [15:8] 255 2 2 2 1 2 0 1 9 1 8 1 7 1 6 1 5 1 4 1 3 1 2 1 1 1 0 9 8 7 6 5 4 3 2 1 0 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * data1[(byteNum*5)-:10] = 10'b0; //If byteNum = 2 255 2 2 2 1 2 0 1 9 1 8 1 7 1 6 1 5 1 4 1 3 1 2 1 1 1 0 9 8 7 6 5 4 3 2 1 0 * * * * * * * * * *
  • 21. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 21 Basic Concepts Data types 5.Integer , Real, and Time Register Data Types: Integer, real, and time register data types are supported in Verilog. Integer: An integer is a general purpose register data type used for manipulating quantities. Integers are declared by the keyword integer. īƒ˜It is more convenient to declare an integer variable for purposes such as counting. īƒ˜The default width for an integer is the host-machine word size, which is implementation- specific but is at least 32 bits. īƒ˜Registers declared as data type reg store values as unsigned quantities, whereas integers store values as signed quantities. Examples: integer counter; // general purpose variable used as a counter. Initial counter = -1; // A negative one is stored in the counter
  • 22. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 22 Basic Concepts Data types Real: Real number constants and real register data types are declared with the keyword real. īƒ˜Real numbers cannot have a range declaration, and their default value is 0. Example: real delta; // Define a real variable called delta initial begin delta = 4e10; // delta is assigned in scientific notation delta = 2.13; // delta is assigned a value 2.13 end integer i; // Define an integer I initial i = delta; // i gets the value 2 (rounded value of 2.13) īƒ˜They can be specified in decimal notation (e.g., 3.14) or in scientific notation (e.g., 3e6, which is 3 x 106 ). īƒ˜When a real value is assigned to an integer, the real number is rounded off to the nearest integer.
  • 23. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 23 Basic Concepts Data types Time: Verilog simulation is done with respect to simulation time. A special time register data type is used in Verilog to store simulation time. īƒ˜A time variable is declared with the keyword time. The width for time register data types is implementation-specific but is at least 64 bits. īƒ˜The system function $time is invoked to get the current simulation time. Example: time save_sim_time; // Define a time variable save_sim_time Initial save_sim_time = $time; // Save the current simulation time
  • 24. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 24 Basic Concepts Data types Arrays: Arrays are allowed in Verilog for reg, integer, time, real, realtime and vector register data types. īƒ˜Multi-dimensional arrays can also be declared with any number of dimensions. īƒ˜Arrays of nets can also be used to connect ports of generated instances. īƒ˜Each element of the array can be used in the same fashion as a scalar or vector net. īƒ˜Arrays are accessed by <array_name>[<subscript>]. For multi-dimensional arrays, indexes need to be provided for each dimension. Example: integer count[0:7]; // An array of 8 count variables reg bool[31:0]; // Array of 32 one-bit boolean register variables time chk_point[1:100]; // Array of 100 time checkpoint variables reg [4:0] port_id[0:7]; // Array of 8 port_ids; each port_id is 5 bits wide integer matrix[4:0][0:255]; // Two dimensional array of integers reg [63:0] array_4d [15:0][7:0][7:0][255:0]; //Four dimensional array wire [7:0] w_array2 [5:0]; // Declare an array of 8 bit vector wire wire w_array1[7:0][5:0]; // Declare an array of single bit wires
  • 25. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 25 Basic Concepts Data types īƒ˜It is important not to confuse arrays with net or register vectors. īƒ˜A vector is a single element that is n-bits wide. īƒ˜On the other hand, arrays are multiple elements that are 1-bit or n-bits wide Examples of assignments to elements of arrays discussed above are shown below: count[5] = 0; // Reset 5th element of array of count variables chk_point[100] = 0; // Reset 100th time check point value port_id[3] = 0; // Reset 3rd element (a 5-bit value) of port_id array. matrix[1][0] = 33559; // Set value of element indexed by [1][0] to 33559 array_4d[0][0][0][0][15:0] = 0; //Clear bits 15:0 of the register accessed by indices [0][0][0][0] port_id = 0; // Illegal syntax - Attempt to write the entire array matrix [1] = 0; // Illegal syntax Attempt to write [1][0]..[1][255]
  • 26. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 26 Basic Concepts Data types Memories: In digital simulation, one often needs to model register files, RAMs, and ROMs. Memories are modeled in Verilog simply as a one-dimensional array of registers. īƒ˜Each element of the array is known as an element or word and is addressed by a single array index. īƒ˜Each word can be one or more bits. It is important to differentiate between n 1-bit registers and one n-bit register. īƒ˜A particular word in memory is obtained by using the address as a memory array subscript. Examples: reg mem1bit[0:1023]; // Memory mem1bit with 1K 1-bit words reg [7:0] membyte[0:1023]; // Memory membyte with 1K 8-bit words(bytes) membyte[511] // Fetches 1 byte word whose address is 511
  • 27. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 27 Basic Concepts Data types Parameters īƒ˜Verilog allows constants to be defined in a module by the keyword parameter. īƒ˜Parameters cannot be used as variables. Parameter values for each module instance can be overridden individually at compile time. This allows the module instances to be customized. Parameter types and sizes can also be defined. Examples: parameter port_id = 5; // Defines a constant port_id Parameter cache_line_width = 256; // Constant defines width of cache line parameter signed [15:0] WIDTH; // Fixed sign and range for parameter WIDTH īƒ˜Module definitions may be written in terms of parameters. Hardcoded numbers should be avoided. Parameters values can be changed at module instantiation or by using the defparam statement. Thus, the use of parameters makes the module definition flexible.
  • 28. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 28 Basic Concepts Data types īƒ˜Module behavior can be altered simply by changing the value of a parameter. īƒ˜Verilog HDL local parameters (defined using keyword localparam -) are identical to parameters except that they cannot be directly modified with the defparam statement or by the ordered or named parameter value assignment.. localparam state1 = 4'b0001, state2 = 4'b0010, state3 = 4'b0100, state4 = 4'b1000; īƒ˜The localparam keyword is used to define parameters when their values should not be changed. īƒ˜For example, the state encoding for a state machine can be defined using localparam. The state encoding cannot be changed. This provides protection against inadvertent parameter redefinition.
  • 29. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 29 Basic Concepts Data types Strings īƒ˜Strings can be stored in reg. The width of the register variables must be large enough to hold the string. īƒ˜Each character in the string takes up 8 bits (1 byte). īƒ˜If the width of the register is greater than the size of the string, Verilog fills bits to the left of the string with zeros. īƒ˜If the register width is smaller than the string width, Verilog truncates the leftmost bits of the string. īƒ˜It is always safe to declare a string that is slightly wider than necessary. reg [8*18:1] string_value; // Declare a variable that is 18 bytes wide initial string_value = "Hello Verilog World"; // String can be stored in variable
  • 30. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 30 Basic Concepts Data types īƒ˜Special characters serve a special purpose in displaying strings, such as newline, tabs, and displaying argument values. īƒ˜Special characters can be displayed in strings only when they are preceded by escape characters, as shown in Table.
  • 31. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 31 Let us discuss about Lexical conventions Data types System tasks and Compiler directives Basic Concepts
  • 32. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 32 Basic Concepts System tasks and Compiler directives īƒ˜Verilog provides standard system tasks for certain routine operations. īƒ˜All system tasks appear in the form $<keyword>. īƒ˜$display is the main system task for displaying values of variables or strings or expressions. This is one of the most useful tasks in Verilog. Displaying information īƒ˜Usage: $display(p1, p2, p3,....., pn); p1, p2, p3,..., pn can be quoted strings or variables or expressions. īƒ˜The format of $display is very similar to printf in C. īƒ˜A $display inserts a newline at the end of the string by default. īƒ˜A $display without any arguments produces a newline. īƒ˜Operations such as displaying on the screen, monitoring values of nets, stopping, and finishing are done by system tasks. īƒ˜We will discuss only the most useful system tasks. Other tasks are listed in Verilog manuals provided by your simulator vendor or in the IEEE Standard Verilog Hardware Description Language specification.
  • 33. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 33 Basic Concepts System tasks and Compiler directives īƒ˜Strings can be formatted using the specifications listed in Table. Example-$display Task //Display the string in quotes $display("Hello Verilog World"); -- Hello Verilog World //Display value of current simulation time 230 $display($time); -- 230 //Display value of 41-bit virtual address 1fe0000001c at time 200 reg [0:40] virtual_addr; $display("At time %d virtual address is %h", $time, virtual_addr); -- At time 200 virtual address is 1fe0000001c
  • 34. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 34 Basic Concepts System tasks and Compiler directives Example - $display Task //Display value of port_id 5 in binary reg [4:0] port_id; $display("ID of the port is %b", port_id); -- ID of the port is 00101 //Display x characters //Display value of 4-bit bus 10xx (signal contention) in binary reg [3:0] bus; $display("Bus value is %b", bus); -- Bus value is 10xx /*Display the hierarchical name of instance p1 instantiated under the highest-level module called top. No argument is required. This is a useful feature*/ $display("This string is displayed from %m level of hierarchy"); -- This string is displayed from top.p1 level of hierarchy
  • 35. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 35 Basic Concepts System tasks and Compiler directives Example- Special Characters //Display special characters, newline and % $display("This is a n multiline string with a %% sign"); -- This is a -- multiline string with a % sign īƒ˜Verilog provides a mechanism to monitor a signal when its value changes. īƒ˜This facility is provided by the $monitor task. Monitoring information īƒ˜Usage: $monitor(p1, p2, p3,....., pn); The parameters p1, p2, ... , pn can be variables, signal names, or quoted strings. īƒ˜A format similar to the $display task is used in the $monitor task. $monitor continuously monitors the values of the variables or signals specified in the parameter list and displays all parameters in the list whenever the value of any one variable or signal changes. īƒ˜Unlike $display, $monitor needs to be invoked only once.
  • 36. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 36 Basic Concepts System tasks and Compiler directives īƒ˜Only one monitoring list can be active at a time. If there is more than one $monitor statement in your simulation, the last $monitor statement will be the active statement. īƒ˜The earlier $monitor statements will be overridden. īƒ˜ Two tasks are used to switch monitoring on and off. Usage: $monitoron; $monitoroff; īƒ˜The $monitoron tasks enables monitoring, and the $monitoroff task disables monitoring during a simulation. īƒ˜Monitoring is turned on by default at the beginning of the simulation and can be controlled during the simulation with the $monitoron and $monitoroff tasks. Example- Monitor Statement //Monitor time and value of the signals clock and reset //Clock toggles every 5 time units and reset goes down at 10 time units initial begin $monitor($time, " Value of signals clock = %b reset = %b", clock,reset); end Partial output of the monitor statement: -- 0 Value of signals clock = 0 reset = 1 -- 5 Value of signals clock = 1 reset = 1 -- 10 Value of signals clock = 0 reset = 0
  • 37. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 37 Basic Concepts System tasks and Compiler directives īƒ˜The task $stop is provided to stop during a simulation. Stopping and finishing in a simulation īƒ˜Usage: $stop īƒ˜The $stop task puts the simulation in an interactive mode. The designer can then debug the design from the interactive mode. īƒ˜The $finish task terminates the simulation. īƒ˜Usage: $finish Example-Stop and Finish Tasks // Stop at time 100 in the simulation and examine the results // Finish the simulation at time 1000. initial // to be explained later. time = 0 begin clock = 0; reset = 1; #100 $stop; // This will suspend the simulation at time = 100 #900 $finish; // This will terminate the simulation at time = 1000 end
  • 38. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 38 Basic Concepts System tasks and Compiler directives Example- `define Directive //define a text macro that defines default word size //Used as 'WORD_SIZE in the code 'define WORD_SIZE 32 //define an alias. A $stop will be substituted wherever 'S appears 'define S $stop; //define a frequently used text string 'define WORD_REG reg [31:0] // you can then define a 32-bit register as 'WORD_REG reg32; Compiler Directives īƒ˜Compiler directives are provided in Verilog. All compiler directives are defined by using the `<keyword> construct. We deal with the two most useful compiler directives. `define īƒ˜The `define directive is used to define text macros in Verilog. īƒ˜The Verilog compiler substitutes the text of the macro wherever it encounters a `<macro_name>. īƒ˜This is similar to the #define construct in C. īƒ˜The defined constants or text macros are used in the Verilog code by preceding them with a ` (back tick).
  • 39. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 39 Basic Concepts System tasks and Compiler directives Example `include Directive // Include the file header.v, which contains declarations in the // main verilog file design.v. 'include header.v ... ... <Verilog code in file design.v> ... ... `include īƒ˜The `include directive allows you to include entire contents of a Verilog source file in another Verilog file during compilation. īƒ˜This works similarly to the #include in the C programming language. īƒ˜This directive is typically used to include header files, which typically contain global or commonly used definitions
  • 40. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 20 Basic Concepts Reference Samir Palnitkar, “Verilog HDL – A guide to Digital Design and Synthesis”, Pearson, 2003 For Further Studies
  • 41. Prof. Anand H. D. M. Tech. (PhD.) Assistant Professor, Department of Electronics & Communication Engineering Dr. Ambedkar Institute of Technology, Bengaluru-56 Email: anandhd.ec@drait.edu.in Phone: 9844518832