Transcript Document
數位系統實驗
Experiment on Digital System
Lab05:
IC design flow and FPGA
Introduction to Verilog HDL
負責助教:葉俊顯 stanley
Outline
IC Design Flow and FPGA
Introduction to HDL
Write Verilog code using Quartus II
Lab
2015/7/20
2
Outline
IC Design Flow and FPGA
Introduction to HDL
Write Verilog code using Quartus II
Lab
2015/7/20
3
Digital system
Digital system
數位系統 (digital system) 通常被設計用來實現或完成
某一些特殊的功能需求
MP3 player
Mobile phone
…
一個數位系統可能包含數個不同功能特質的數位電路,
而數位電路一般是使用所謂的半導體技術實作於積體電路
(Integrated circuit, IC) 上
2015/7/20
4
IC design flow
Product specification
Sim/Ver
Circuit design
Sim/Ver
Layout
(placement & routing)
GDS-II
2015/7/20
5
ASIC and FPGA
當設計者完成RTL(Register Transfer Level)電路後,若使用製作
功能應用導向晶片(Application Specific Integrated Circuit,ASIC)
的EDA tools來進行合成、模擬、驗證,最後,會產生一個GDSII檔案。最後,可將此檔案委請晶圓廠製成一顆ASIC晶片
FPGA/CPLD是一種可依需要做程式規劃的晶片,其中包含許多
可被使用的cells,透過FPGA廠商提供的FPGA-EDA tool進行合
成、模擬與驗證,最後將所設計的電路燒錄到FPGA上面
FPGA (Field Programmable Gate Array) – 本課程所使用
CPLD (Complex Programmable Logic Device)
2015/7/20
6
FPGA design flow
Design ideas
Detailed design
Functional simulation
Implementation
(P & R)
Time simulation
Device programming
2015/7/20
7
Outline
IC Design Flow and FPGA
Introduction to HDL
Write Verilog code using Quartus II
Lab
2015/7/20
8
Introduction to HDL
HDL
Hardware description language
Similar to general-purpose languages like C
Modeling and simulation of the functionality of
combinational and sequential circuits
Parallel vs. sequential behaviors
Two competitive forces
Verilog: C-like language – 本課程所使用
VHDL: ADA-like language
2015/7/20
9
Introduction to Verilog HDL
C-like syntax/semantics
Basic building block
Module
Four kinds of model for circuits
Switch Level Model or Transistor Model (npn & pnp …)
Gate Level Model (or & and …)
Data Flow Model (assign)
Behavioral Model (RTL description) (always@() begin … end)
2015/7/20
10
Design hierarchy
output1
input1
top_module
sub_module1
output2
input2
output3
input3
sub_module2
sub_module3
output4
input4
output5
2015/7/20
11
Identifier
Names of modules, ports, wires and instances are all
identifiers
First character must be a letter, and other characters can
be letters, numbers or underscore ( _ )
Upper case and lower case letters are different
2015/7/20
12
Keyword
All keywords are defined in lower case
2015/7/20
13
Keyword
All keywords are defined in lower case
2015/7/20
14
Data type
net
reg
parameter
2015/7/20
15
Data type - net (wire)
2015/7/20
16
Data type - reg
A reg data type represents a variable in Verilog
Type ”reg” variable stores values, but not necessarily a
FF (register)
Are only assigned in an ”always” block task or function
If a reg data type is assigned a value in an always block
that has a clock edge expression, a flip-flop is inferred
2015/7/20
17
Data type - reg
By default, net and register are one-bit wide
2015/7/20
18
Data type - parameter
Represents constants
Declared by: parameter data_size = 5;
Cannot be changed at run time
2015/7/20
19
Value Set
Verilog has four value levels
2015/7/20
20
Operator Priority
2015/7/20
21
Module
2015/7/20
22
Module - example
module
name
module half_adder (
x,
y,
c,
port name
s
);
// port declaration
input x; // width: 1 bit
input y;
output c, s;
2015/7/20
// I/O type and data type
wire c;
wire s;
// functionality or structure
xor (s, x, y); // (out, in, ……)
and (c, x, y);
endmodule
Verilog
primitive
23
Circuit design using
- Four kinds of model
Switch Level Model
Gate Level Model
Data Flow Model
Behavioral Model
2015/7/20
24
Example: Half adder
module half_adder (
//input
x,
y,
//output
c,
s
);
// port declaration
input x; // width: 1 bit
input y;
output c, s; Gate Level Model
// I/O type and data type
wire c;
wire s;
// functionality or structure
xor (s, x, y);
and (c, x, y);
x
S
half_adder
y
x
S
C
Behavioral Model
C
y
reg s,c;
always @(x or y)
begin
s=x^y;
c=x&y;
Data Flow Model
assign s=x^y;
assign c=x&y;
end
endmodule
25
Example: Full adder (Gate Level Model)
module full_adder (x, y, z, S, C);
input x, y, z;
output S, C;
wire01
x
S
xor01
// internal nets/registers
wire wire01;
wire wire02;
wire wire03;
xor02
wire03
y
C
and01
and02
z
wire02
// functionality or structure
xor xor01(wire01, x, y);
and and01(wire02, x, y);
xor xor02(S, wire01, z);
and and02(wire03, wire01, z);
or (C, wire02, wire03);
endmodule
26
Example: Full adder (2HA+1OR)
module full_adder (x, y, z, S, C);
input x, y, z; output S, C;
wire wire1, wire2, wire3 ;
// functionality or structure
// module instantiations
half_adder ha1(
//input
.x (x),
.y (y),
//output
.c (wire2),
.s (wire1)
);
half_adder ha2(
//input
.x (wire1),
.y (z),
//output
.c (wire3),
.s (S)
);
or (C, wire2, wire3);
endmodule
x
s
HA 1
y
z
wire1
S
s
HA 2
c
c
wire3
C
wire2
27
Instantiation and port mapping
In order
// in half_adder.v
half_adder (x, y, c, s);
// in full_adder.v
half_adder ha1(x, y, wire2, wire1);
half_adder ha2(wire1, z, wire3, s);
By name
// in half_adder.v
half_adder (x, y, c, s);
// in full_adder.v
half_adder ha1(.x(x), .y(y), .c(wire2), .s(wire1));
half_adder ha2(.x(wire1), .y(z), .s(s), .c(wire3));
28
Outline
IC Design Flow and FPGA
Introduction to HDL
Write Verilog code using Quartus II
Lab
2015/7/20
29
Step by Step
Getting Started –
Start the Quartus II software
30
Step by Step
Create a New Project –
Open New Project Wizard (File → New Project Wizard…)
31
Step by Step
Specify the working directory and the name of the
project
可先新增資料夾
請記住!
32
Step by Step
Select design files. Or click “Next” to skip this step
Specify device settings - (Here we use the VerLite Device
family)
EP1C6Q240C8
33
Step by Step
Edit a Schematic File Open a new Verilog HDL file
(File → New → Verilog HDL File → OK)
34
Step by Step
Write Verilog code
Top module name 一定要跟 Project name 相同 !!
1:
2:
3:
4:
//File Name:Half_Adder.v
module
Half_Adder(a, b, sum, carry);
input
a, b;
output
sum, carry;
5:
6:
7:
輸入(input)
被加數(a)
加數(b)
0
0
0
1
1
0
1
1
a
assign sum = a ^ b;
b
輸出(output)
和(sum)
進位(carry)
0
0
1
0
1
0
0
1
Half Adder
sum
carry
assign carry = a & b;
8:
9:
endmodule
35
Step by Step
Compiling the Designed Circuit
(Processing → Start Compilation)
36
Step by Step
Successful compilation
37
Step by Step
Simulating the Designed Circuit
Using the Waveform Editor (File → New → Vector
Waveform File)
38
Step by Step
Simulating the Designed Circuit
Use node finder to find all the pins (Edit → Insert →
Insert Node or Bus…)
39
Step by Step
Simulating the Designed Circuit
Selecting nodes to insert into the Waveform
Editor
沒跑出pin腳,表示你剛剛忘記compile
40
Step by Step
Simulating the Designed Circuit
Selecting nodes to insert into the Waveform
Editor
41
Step by Step
Simulating the Designed Circuit
Select and edit waveform
42
Step by Step
Simulating the Designed Circuit
Setting of test values
43
Step by Step
Performing the Simulation
Modify default settings (Assignments → Settings… →
Simulator Settings → Functional → OK)
44
Step by Step
Generate functional simulation netlist before
simulation (Processing → Generate Functional Simulation Netlist)
45
Step by Step
Start simulation (Processing → Start Simulation
)
46
Step by Step
The result of functional simulation
輸入(input)
被加數
加數(b)
(a)
0
0
0
1
輸出(output)
進位
和(sum)
(carry)
0
0
1
0
1
0
1
0
1
1
0
1
47
Outline
IC Design Flow and FPGA
Introduction to HDL
Write Verilog code using Quartus II
Lab
2015/7/20
48
Lab I
Using Verilog to implement a 1-bit Full Adder
Simulation Result
z
y
x
S
C
0
0
0
0
0
0
0
1
1
0
0
1
0
1
0
0
1
1
0
1
1
0
0
1
0
1
0
1
0
1
1
1
0
0
1
1
1
1
1
1
49
Lab I - Hint
Hint (Gate Level Model)
wire01
x
S
xor01
xor02
wire03
y
C
and01
and02
z
wire02
50
Lab II
Using Verilog to implement a 2-bit Full Adder
Simulation Result
z1
y1
x1 C1 y2
x2
S1
S2 C2
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
1
1
0
0
1
0
0
1
0
1
1
0
0
1
1
1
0
0
0
1
0
1
0
0
0
1
1
1
0
1
1
0
1
1
0
1
0
0
1
1
1
0
1
1
0
0
0
1
1
1
1
1
1
1
1
1
1
51
Lab II - Hint
wire01
wire01
x1x
S1
S
xor01
xor02
wire03
wire03
y1y
and01
C
C1
and02
z1z
or01
Ref. Instantiation and port mapping
wire01
wire04
x
x2
xor01
xor03
wire02
wire02
xor04
S
S2
xor02
wire06
wire03
y2
y
z
X
C1
and01
and03
and02
and04
C
C2
or02
wire05
wire02
52
Notice
請勿在桌面建立 Project 及請勿命名中文資料夾
Device family 請確認與 FPGA Chip 符合 (EP1C6Q240C8)
Top module name & Project name 需要一致
確認 module … endmodule 為keyword 變成藍色字體
53