Basic Logic Design With Verilog HDL: Combinational Circuits
Basic Logic Design With Verilog HDL: Combinational Circuits
Combinational Circuits
Lecture note ver.1 by Chen-han Tsai ver.2 by Chih-hao Chao ver.3 by Xin-Yu Shi ver.4 by Bo-Yuan Peng ver.5 by Cheng-Zhou Zhan
Outline
Introduction to Verilog HDL Syntax in Verilog HDL Gate-Level Modeling Test-Bench Compilation and Simulation Tools Preview of Lab Questions
Outline
Introduction to Verilog HDL Syntax in Verilog HDL Gate-Level Modeling Test-Bench Compilation and Simulation Tools Preview of Lab Questions
Gate Level
Describe the logic gates and the interconnections between them.
Cost Low
High
Verilog
Gate Level Simulation
Logic Synthesizer
Gate Level Code
Tape Out
Low
High
Chip
sel 0 out 1
sel 0 0 0 0 1
in1 0 0 1 1 0 0 1 1
in2 0 1 0 1 0 1 0 1
out 0 0 1 1 0 1 0 1
in1 in2
1 1 1
iv_sel
a1 a2
a1_o
o 1
out
a2_o
sel
iv_sel
Gate Level: you see only netlist (gates and wires) in the code.
10
always block
assign
Outline
Introduction to Verilog HDL Syntax in Verilog HDL Gate-Level Modeling Test-Bench Compilation and Simulation Tools Preview of Lab Questions
12
port/wire declaration
13
Module
Interface is defined by ports May contain instances of other modules All modules run concurrently
14
Module Instantiation
Adder
instance example
Adder
Adder
Adder_tree
15
Instances
A module provides a template from which you can create actual objects. When a module is invoked, Verilog creates a unique object from the template. Each object has its own name, variables, parameters and I/O interface.
16
Instantiation
Member Hierachy
c_Name obj_name;
obj_name.member_data
17
Port Connection
Single line: // its a single line comment example Multi-line: /* When the comment exeeeds single line, multi-line comment is necesssary */
19
Register
Keyword: reg, integer, time, real Event-driven modeling Storage element (modeling sequential circuit) Assignment in always block (LHS of expressions)
20
Net
Keyword: wire, wand, wor, tri, triand, trior, supply0, supply1 Doesnt store value, just a connection Input, output and inout ports are default wire
21
22
23
Logic System
24
0 0 1 0 0
1 0 1
X 0 X
Z 0 X
X
Z
0
0
X
X
X
X
X
X
b y
x z
x z
x z
x z
25
Number Representation
Format: <size><base_format><number> <size> - decimal specification of bits count
26
Number Representation
Format: <size><base_format><number> <number> - value given in base of base format
27
Number Representation
Examples:
6b010_111 8b0110 4bx01 16H3AB 24 5O36 16Hx 8hz gives 010111 gives 00000110 gives xx01 gives 0000001110101011 gives 00011000 gives 11110 gives xxxxxxxxxxxxxxxx gives zzzzzzzz
28
Number Representation
659 // unsized decimal h 837ff // unsized hexadecimal o7460 // unsized octal 4af // illegal syntax 4b1001 // 4-bit binary 5D 3 // 5-bit decimal 3b01x // 3-bit number with unknown LSB 12hx// 12-bit unknown 8d -6 // illegal syntax -8d 6 // phrase as - (8d6)
// underline usage 27_195_000 16b0001_0101_0001_1111 32h12ab_f001 // X and Z is sign-extended reg [11:0] a; initial begin a = hx; a = h3x; a = h0x; end
29
Net Concatenation
Module B
Module A
3o7
Representations {b[3:0],c[2:0]} {a,b[3:0],w,3b101} {4{w}} {b,{3{a,b}}} Meanings
{b[3] ,b[2] ,b[1] ,b[0], c[2] ,c[1] ,c[0]} {a,b[3] ,b[2] ,b[1] ,b[0],w,1b1,1b0,1b1} {w,w,w,w} {b,a,b,a,b,a,b}
30
Module C
Operators
Arithmetic Operators Relational Operators Equality Operators Logical Operators Bit-wise Operators Unary Reduction Shift Operators Conditional Operators Concatenations +, -, *, /, % <, <=, >, >= ==, !=, ===, !== !, &&, || ~, &, |, ^, ~^ &, ~&, |, ~|, ^, ~^ >>, << ?: {}
Operator Examples
Compiler Directives
'define
'define RAM_SIZE 16 Defining a name and gives a constant value to it.
'include
'include adder.v Including the entire contents of other verilog source file.
'timescale
'timescale 100ns/1ns Setting the reference time unit and time precision of your simulation.
33
System Tasks
$monitor
$monitor ($time,"%d %d %d",address,sinout,cosout); Displays the values of the argument list whenever any of the arguments change except $time.
$display
$display ("%d %d %d",address,sinout,cosout); Prints out the current values of the signals in the argument list
$finish
$finish Terminate the simulation
34
Outline
Introduction to Verilog HDL Syntax in Verilog HDL Gate-Level Modeling Test-Bench Compilation and Simulation Tools Preview of Lab Questions
35
Steps
Develop the Boolean function of output Draw the circuit with logic gates/primitives Connect gates/primitives with net (usually wire)
Primitives
Primitives are modules ready to be instanced Smallest modeling block for simulator Verilog build-in primitive gate
not, buf
prim_name #delay inst_name( out0, out1, ..., in0);
0 0
Co
Full Adder S
Ci
0 0 1 1 1 1
38
Co = AB + BCi + CiA
A B B Ci Ci A
Co
39
a b c sum
sum = a b ci
a b c
sum
40
a b c
41
Outline
Introduction to Verilog HDL Syntax in Verilog HDL Gate-Level Modeling Test-Bench Compilation and Simulation Tools Preview of Lab Questions
42
Test Methodology
Systematically verify the functionality of a model. Procedure of simulation
43
Test Methodology
Stimulus
Testbench
Response
44
Verilog Simulator
45
initial begin #10 a = 0; b = #10 a = 0; b = #10 a = 1; b = #10 a = 1; b = #10 a = 0; b = #10 a = 0; b = #10 a = 1; b = #10 a = 1; b = end endmodule
0; 1; 0; 1; 0; 1; 0; 1;
46
Summary
Test-bench
Feed input data and compare output values at right timing slots Usually describe in behavioral level Not real hardware, just like software programming (e.g. C/C++)
47
Note
Verilog is a platform
Support hardware design (design module) Also support C/C++ like coding (test bench)
Hardware
Combinational circuits (todays topic) Sequential circuits (we wont model them in this course)
48
Outline
Introduction to Verilog HDL Syntax in Verilog HDL Gate-Level Modeling Test-Bench Compilation and Simulation Tools Preview of Lab Questions
49
Create a Project
Assign by yourself
Your design
Your testbench
Compile
Simulation
2. Press Simulate
Simulation
2. Press OK
Simulation
View Signals
View Signals
View Signals
View Signals
Run
End Simulation