Verilog HDL Introduction: Textbook
Verilog HDL Introduction: Textbook
10
Verilog HDL
HDL???
Fall
10
The principal feature of a hardware description language is that it contains the capability to describe the function of a piece of hardware independently of the implementation. The great advance with modern HDLs was the recognition that a single language could be used to describe the function of the design and also to describe the implementation. This allows the entire design process to take place in a single language, and thus a single representation of the design.
VLSI System Design Verilog HDL
2
Verilog HDL
Fall
10
The Verilog Hardware Description Language, usually just called Verilog, was designed and first implemented by Phil Moorby at Gateway Design Automation in 1984 and 1985. It was first used beginning in 1985 and was extended substantially through 1987. The implementation was the VerilogXL simulator sold by Gateway. Present version: IEEE 1364-2001 Compliant
Verilog HDL
Fall
10
Fall
10
Simulate
Test Bench
Simulate
5
Verilog HDL
Verilog HDL is for writing models of a system Reasons for modeling requirements specification documentation testing using simulation formal verification synthesis Goal most reliable design process, with minimum cost and time avoid design errors!
VLSI System Design Verilog HDL
6
Fall
10
Geometric
VLSI System Design Verilog HDL
7
Fall
10
Register-Transfer Language
Boolean Equation Differential Equation
Geometric
VLSI System Design Verilog HDL
Fall
10
Functional
Gate Transistor
Geometric
VLSI System Design Verilog HDL
9
Fall
10
Geometric
VLSI System Design Verilog HDL
10
Hierarchy
Verilog allows you to represent the hierarchy of a design. The Verilog structures which build the hierarchy are: modules, ports. A Verilog model is composed of modules. A module is the basic unit of the model, and it may be composed of instances of other modules. A module which is composed of other module instances is called a parent module, and the instances are called child modules.
Fall
10
Verilog HDL
11
Hierarchy contd
A more common way of depicting hierarchical relationships is: We say that a parent instantiates a child module. That is, it creates an instance of it to be a submodel of the parent. Comp_1 System instantiates comp_1, comp_2. comp_2 instantiates sub_3.
Fall
10
SYSTEM
Comp_2
Sub_3
Verilog HDL
12
Module
A module is defined like this:
Fall
10
module <module_name> (<module_terminal_list >); . <module internals> Verilog HDL is a case-sensitive . language. All keywords are in endmodule
lowercase
Each module must have a <module_name> which is a identifier for the module, and a <module_termininal_list>, which describes the input and output terminals of the module.
Verilog HDL
13
Module contd
Signifies starting of the module
module test (out , in1,in2); . statement1; statement2; . endmodule
Fall
10
Verilog HDL
14
Instances
Fall
10
The process of creating objects from a module template is called instantiation, and objects are called instances. Name assigned to the instantiation Name of the output lead Names of the input leads
nand_gate is the name assigned to the module. The nand_gate can be instantiated by the designer as many times as desired. Each instantiation has to be assigned identifier name (ic1, ic2 .. ). As part of the instantiation declaration, the input and output terminals are to be defined. The convention followed is to stick to the same order as in the module declaration.
Verilog HDL
15
Instances contd
a1 The other way of instantiation is given as nand_gate ic1 (O(b), I8(a8), I7(a7), I1(a1) );
Fall
10
I1
I8
a8
Each module can be defined only once. They cannot be nested. Any module can be instantiated inside another any number of times.
Verilog HDL
16
Example
// 4-bit Ripple Carry Counter module ripple_carry_counter (q, clk, reset); output [3:0] q; input clk, reset; T_FF tff0 (q[0], clk, reset); T_FF tff1 (q[1], q[0], reset); T_FF tff2 (q[2], q[1], reset); T_FF tff3 (q[3], q[2], reset); endmodule
Fall
10
// Define the module T_FF. It instantiates a D_FF. module T_FF (q, clk, reset); output q; input clk, reset; wire d; D_FF dff0 (q, d, clk, reset); not n1 (d, q); // not gate is verilog primitive endmodule
// Define the module D_FF module D_FF (q1, d, clk, reset); output q1; input d, clk, reset; reg q1; always @(posedge reset or negedge clk) if (reset) q1 <= 1'b0 ; else q1 <= d; endmodule
17
Verilog HDL
Levels of modelling
Switch level (Circuit level) Gate level
Fall
10
Verilog HDL
18
Switch level
Fall
10
This is lowest level of abstraction provided by Verilog. A module can be implemented in terms of switches, storage vdd nodes and the interconnection between them.
Example : // inverter module my_inv(out, in); output out; input in; supply1 vdd ; supply0 gnd; pmos p1(out, pwr, in); nmos n1( out, gnd, in); endmodule VLSI System Design Verilog HDL
in
out
gnd
19
Gate level
Fall
10
This is next level of abstraction provided by Verilog. The module is implemented in terms of logic gates and the interconnections between these gates
and a1 (A, B, C); or and (A, B, C);
Verilog HDL
20
Data flow
Fall
10
This is the next level of abstraction. At the data flow level, signals are assigned through the data manipulating equations. The design description are more compact than those at the gate level.
assign C = A & B;
Verilog HDL
21
Behavioral level
Fall
10
Behavioral level constitutes the highest level of design description. A module can be implemented in terms of the desired design algorithm without concern for the hardware implementation details. Designing at this level is very similar to C programming. The behavioral level should contain atleast a initial or always block
Verilog HDL
22
Lexical conventions
White space:
blank space (\b) tabs (\t) newline (\n)
Fall
10
Verilog HDL
23
Number specifiations
(-)<size>`<base format><number>
Fall
10
<size> : specify the size of the constant in the number of bits. (optional) 32-bit wide number by default <base format> : single character ` followed by one of the following characters b(binary), d(decimal), o(octal), h(hex) decimal by default
Examples
549 //decimal number `h 8FF //hex number `o765 // octal number 4`b11 // 4-bit binary number 0011 3`b10x // 3-bit binary number with least significant bit unknown 5`d3 // 5-bit decimal number -4`b11 // 4-bit twos complement of 0011 or 1101 this is a string // enclosed in double quotes
Verilog HDL
24
Operators
3 types
Unary operators precede the operand
Fall
10
Fall
10
Ternary example:
reg y; always @ (a or b or select) if (select) y = a; else y = b; OR y = (select) ? a : b;
Verilog HDL
26
Operators(1/8)
Arithmetic operators
Treats vectors as a whole value If any operand is x, then the results are unknown
Example : ain+ din = unknown
Fall
10
Verilog HDL
27
Operators(2/8)
Bitwise operators
Operates on each bit of operand Result is the size of the largest operand Left-extended if sizes are different
Fall
10
Verilog HDL
28
Operators(3/8)
Reduction operators
Fall
10
Reduces vector to single bit x is considered unknown, but result maybe a known value
Example: &din results in 1`b0
Verilog HDL
29
Operators(4/8)
Relational operators
Fall
10
Used to compare values Returns a 1 bit scalar value of boolean true (1) / false (0) If any operand is x, then the results are unknown
Verilog HDL
30
Operators(5/8)
Equality operators
Fall
10
Used to compare values Returns a 1 bit scalar value of boolean true (1) / false (0) If any operand is Z or X, then the results are unknown Case equality and inequality includes x
Verilog HDL
31
Operators(6/8)
Logical operators
Fall
10
Returns a 1 bit scalar value of boolean true (1) / false (0) If any operand is x, then the results are unknown
Verilog HDL
32
Operators(7/8)
Shift operators
Shifts a vector left or right some number of bits Zero fills Shifted bits are lost
Fall
10
Verilog HDL
33
Operators(8/8)
Miscellaneous operators
Fall
10
Verilog HDL
34
Operators precedence
Operators default precedence +, -, !, ~ (unary) +, - (binary) <<, >> <, >, <=, >= ==, != & ^, ^~ or ~^ | && || ?: (ternary) ( ) can be used to override default
VLSI System Design Verilog HDL Highest priority
Fall
10
Lowest priority
35
Data types(1/6)
4 value logical system in verilog.
ZERO
Fall
10
ONE
UNKNOWN
HIGH IMPEDANCE
VLSI System Design Verilog HDL
36
Data types(2/6)
3 major data types.
Nets
Represents physcial connection between devices
Fall
10
Registers
Represent abstract data storage elements
Parameters
Run-time constants
Declaration syntax
<data_type> [<MSB>:<LSB>] <list_of_identifier>
Verilog HDL
37
Data types(3/6)
Nets
wire is the most common type
Fall
10
Verilog HDL
38
Data types(4/6)
Register
reg is the most common type
Fall
10
Verilog HDL
39
Data types(5/6)
Vectors
Fall
10
Arrays
<array_name> [<subscript>]
integer temp [7:0] reg [7:0] temp[31:0]
Verilog HDL
40
Fall
10
Verilog HDL
41