Professional Documents
Culture Documents
Thietkehenhung K63
Thietkehenhung K63
HỆ THỐNG NHÚNG
2
© DHBK 2010
3
© DHBK 2010
4
© DHBK 2010
Acknowledgement
• Trong bài trình bày này có sử dụng một số slides của
giáo sư Prabhat Mishra, Đại học Florida và của các
đồng nghiệp khác
5
© DHBK 2010
PHẦN 1:
GiỚI THIỆU VỀ HỆ THỐNG NHÚNG
6
© DHBK 2010
NỘI DUNG
7
© DHBK 2010
8
© DHBK 2010
9
© DHBK 2010
Định nghĩa
10
© DHBK 2010
Định nghĩa
• Vậy hệ thống nhúng là gì?
Hệ thống bất kỳ sử dụng vi xử lý mà không phải là máy tính đa
năng và được nhúng vào một hệ thống lớn hơn
Hệ thống nhúng đầu tiên: Máy tính dẫn đường cho Apollo
11
© DHBK 2010
• *Intelligent
2, 000, 000 LOC Transportation *Cabin Air *Lighting
System
Quality
• Windows CE OS *Safety
(ITS)
Systems
• 53 8-bit P
*Engine
• 11 32-bit P Performance
and Emission
Control
• 7 16-bit P (Traction
12
© DHBK 2010
13
© DHBK 2010
14
© DHBK 2010
15
© DHBK 2010
Các thành phần của hệ thống nhúng
Memory Controllers Interface
Software
(Application Programs)
Processor
Coprocessors
ASIC
Converters
17
© DHBK 2010
18
© DHBK 2010
20
© DHBK 2010
21
© DHBK 2010
22
© DHBK 2010
Yêu cầu thiết kế
Time-to-Market
• Time required to develop a
product to the point it can be
sold to customers
• Market window
Period during which the product
Revenues ($)
23
© DHBK 2010
Yêu cầu thiết kế
Thiệt hại khi đưa ra thị trường chậm
• Loss
D W 2W
The difference between the on-time
On-time Delayed Time
entry entry and delayed triangle areas (shaded
region)
24
© DHBK 2010
Yêu cầu thiết kế
Thiệt hại khi đưa ra thị trường chậm
On-time
delayed entry
(D(3W-D)/2W2)*100%
Market rise Market fall • Try some examples
Delayed
25
© DHBK 2010
Yêu cầu thiết kế
Giá thành (cost)
• Unit cost
the monetary cost of manufacturing each copy of the system, excluding NRE
cost
• NRE cost (Non-Recurring Engineering cost)
The one-time monetary cost of designing the system
• Total cost
NRE cost + unit cost * # of unit
• Per-product cost
total cost / # of units = (NRE cost / # of units) + unit cost
• Example
– NRE=$2000, unit=$100
– For 10 units
– total cost = $2000 + 10*$100 = $3000
– per-product cost = $2000/10 + $100 = $300
27
© DHBK 2010
g
c ứn
n
p hầ …)
k ế t ,
Ý tưởng Phân chia HW/SW Thiết a yo
u
Specification
s i s, L
e
y nth
(S
Th
iết
kế
(C ph
Estimation - om ần
pil mề
Exploration a ti m
on
,…
)
Phần mềm
Phần mềm
28
Validation and Evaluation (area, power, performance, …)
© DHBK 2010
29
© DHBK 2010
100K
10K
55%/year
1K
100
10
1 Time
1980 1985 1990 1995 2000 2005
1000 10 1
+ Communications
+ Ambient
Intelligence
31
© DHBK 2010
Xu hướng phát triển
Các thiết bị thông minh
32
© DHBK 2010
Xu hướng phát triển
Môi trường thông minh
34
© DHBK 2010
35
© DHBK 2010
Tổng quan
36
© DHBK 2010
Tổng quan
• Các linh kiện rời rạc (COTS)
e.g. wireless radios, sensors, I/O devices
Cheap
• Các IC chuyên dụng (ASICs)
ICs tailored to meet application needs
Good performance for their intended tasks
• Vi xử lý
DSPs
Microcontrollers
Microprocessors
• Các IC khả trình (PLD)
37
© DHBK 2010
Tổng quan
• Xu hướng phần cứng mới:
System-On-Chip (SOC)
Usual (or desired) specs:
32-bit RISC CPU
Built-in interfaces to RAM and ROM
Built-in DMA, interrupt and timing controllers
Built-in interfaces to disk or flash memory
Built-in Ethernet/802.11 interfaces
Built-in LCD/CRT interfaces
New SOCs appearing almost every week!
Examples
Intel StrongARM SA-1110
Motorola PowerPC MPC823e
NEC VR4181
Many, many more
38
© DHBK 2010
39
© DHBK 2010
Khối vào ra
• Các loại cảm biến:
Nhiệt, quang, áp suất, âm thanh, sinh học, CCD…
• Các bộ biến đổi
ADC, DAC
• Các thiết bị ra
Động cơ, van, xi lanh, LCD …
40
© DHBK 2010
Khối vào ra
Charge-Coupled Devices (CCD)
41
© DHBK 2010
Khối vào ra
Biometrical Sensors
Example: Fingerprint sensor (© Siemens, VDE):
42
© DHBK 2010
Khối vào ra
Artificial eyes
© Dobelle Institute
(www.dobelle.com)
43
© DHBK 2010
Khối vào ra
Artificial eyes
© Dobelle Institute
(www.dobelle.com)
44
© DHBK 2010
Khối vào ra
45
© DHBK 2010
46
© DHBK 2010
Sensor/actuator busses
47
© DHBK 2010
Khối truyền thông
Sensor/Actuator Bus
CNC:
48
Computerized Numerical Control
© DHBK 2010
Khối truyền thông
Field bus
• More powerful/expensive than sensor
interfaces; serial busses preferred.
•Examples:
Process Field Bus (Profibus)
http://www.profibus.com
Token passing;
9.6 kbit/s (1200 m) to 500 kbits/s (200m);
too slow to be used for hard time constraints.
49
© DHBK 2010
Khối truyền thông
Field busses
• Controller area network (CAN)
Designed by Bosch and Intel in 1981;
Used in cars and other equipment;
Differential signaling with twisted pairs,
Arbitration using CSMA/CA,
Throughput between 10kbit/s and 1 Mbit/s,
Low and high-priority signals,
Max. latency of 134 µs for high priority signals,
Coding similar to that of serial (RS-232) lines of PCs,
with modifications for differential signaling.
http://www.can.bosch.com
• IEEE 488
50
© DHBK 2010
Khối truyền thông
Wireless Communication
51
© DHBK 2010
52
© DHBK 2010
Khối xử lý
53
© DHBK 2010
Vi điều khiển
• Vi điều khiển = CPU + Bộ nhớ + các khối ghép nối ngoại vi +
các khối chức năng
EEPROM
RAM
ADC/DAC
Timer
Bộ tạo xung nhịp
PWM
UART
USB
...
• Word length
4 bit: 2%
8 bit: 36%
16 bit: 25%
32 bit: 34%
64 bit: 3%
• Not pushing the limits of performance for cost reasons
54
© DHBK 2010
Vi điều khiển
• Shipments- > 8 Billion in 2000, 8 bit > 1/2 market
• Major Players: Microchip 16Fxx, Intel 8051, Motorola
MC68HC05, National COP800, SGS/Thomson ST62, Zilog
Z86Cxx
55
© DHBK 2010
PIC16C5x
56
© DHBK 2010
PIC16C5x
• High-Performance RISC CPU:
Only 33 single word instructions to learn
All instructions are single cycle (200 ns) except for
program branches which are two-cycle
Operating speed: DC - 20 MHz clock input
DC - 200 ns instruction cycle
12-bit wide instructions
8-bit wide data path
Seven or eight special function hardware registers
Two-level deep hardware stack
Direct, indirect and relative addressing modes for
data and instructions
57
© DHBK 2010
PIC16C5x
• Peripheral Features:
8-bit real time clock/counter (TMR0) with 8-bit
programmable prescaler
Power-On Reset (POR)
Device Reset Timer (DRT)
Watchdog Timer (WDT) with its own on-chip
RC oscillator for reliable operation
Programmable code-protection
Power saving SLEEP mode
• Applications:
high-speed automotive and appliance motor control
low-power remote ransmitters/receivers
58
pointing devices and telecom processors.
© DHBK 2010
59
© DHBK 2010
MCS-51
• 8051 thuộc họ vi điều khiển MCS-51.
• MCS-51 được phát triển bởi Intel và các nhà sản xuất
khác (như Siemens, Philips) là các nhà cung cấp
đứng thứ hai của họ này.
• Tóm tắt một số đặc điểm chính của họ 8051:
4K bytes ROM trong
128 bytes RAM trong
4 cổng I/O 8-bit
2 bộ định thời 16 bit
Giao diện nối tiếp
Quản lý được 64K bộ nhớ code bên ngoài
Quản lý được 64K bộ nhớ dữ liệu bên ngoài
60
© DHBK 2010
Ram trong
FF
Thanh ghi 128 byte
chøc n¨ng ram
®Æc biÖt
80
§iÒu khiÓn Nguån 7F
ng¾t Ng¾t 128 byte
Trong RAM
00
CPU
Thanh ghi
§¬n vÞ ng¾t
Thanh ghi ®a n¨ng
lÖnh 32 x 8 §¬n vÞ SPI
128x8 Bé so s¸nh
EEPROM analog
15 ®êng dÉn
vµo/ra
62
© DHBK 2010
PSoC
63
© DHBK 2010
PROM Selection of 18
peripherals: address
serial comm.,
Loop controller timers,...
I/O
16
data
16
address
66
© DHBK 2010
Bộ nhớ
permanence
Storage Mask-programmed ROM Ideal memory
In-system
programmable SRAM/DRAM
Near
zero Write
ability
67
© DHBK 2010
68
© DHBK 2010
69
© DHBK 2010
RTOS Standard OS
70
© DHBK 2010
71
© DHBK 2010
73
© DHBK 2010
75
© DHBK 2010
76
© DHBK 2010
77
© DHBK 2010
78
© DHBK 2010
79
© DHBK 2010
4. Các vấn đề trong quy trình thiết kế hệ
nhúng
• Mô tả hệ thống (specification)
• Phân chia phần cứng, phần mềm (HW/SW
partitioning)
• Lựa chọn phương án thiết kế (Design space
exploration)
80
© DHBK 2010
4. Các vấn đề trong quy trình thiết kế hệ
nhúng
• Mô tả hệ thống (specification)
• Phân chia phần cứng, phần mềm (HW/SW
partitioning)
• Lựa chọn phương án thiết kế (Design space
exploration)
81
© DHBK 2010
g
c ứn
n
p hầ …)
k ế t ,
Ý tưởng Phân chia HW/SW Thiết a yo
u
Specification
s i s, L
e
y nth
(S
Th
iết
kế
(C ph
Estimation - om ần
pil mề
Exploration a ti m
on
,…
)
Phần mềm
Phần mềm
82
Validation and Evaluation (area, power, performance, …)
© DHBK 2010
Mô tả hệ thống
• Các ngôn ngữ mô tả hệ thống
State Charts
SDL
Petri Nets
UML, MSC
VHDL, Verilog
SpecC, SystemC, SystemVerilog
83
© DHBK 2010
Mô tả hệ thống
StateCharts: D. Harel, 1987
Hierarchy
superstate
substates
84
© DHBK 2010
Mô tả hệ thống
SDL
• Specification and Description Language
Designed for specification of distributed systems.
85
© DHBK 2010
Mô tả hệ thống
FSMs/Processes in SDL
state
input
output
86
© DHBK 2010
Mô tả hệ thống
SDL
87
© DHBK 2010
Mô tả hệ thống
Petri Nets
• Carl Adam Petri, PhD thesis, 1962.
• Focus on modeling causal dependencies; no global
synchronization assumed (message passing only).
• Applications:
Modeling of resources;
Modeling of mutual exclusion;
Modeling of synchronization.
• Key elements:
Conditions: Either met or not met.
Events: May take place if certain conditions are met.
Flow relations: Relates conditions and events.
• Conditions, events and the flow relation form a bipartite graph
(graph with two kinds of nodes).
88
© DHBK 2010
Mô tả hệ thống
Petri Nets
Preconditions
89
© DHBK 2010
Mô tả hệ thống
UML (Unified Modeling Language)
90
© DHBK 2010
Mô tả hệ thống
Verilog
91
© DHBK 2010
Mô tả hệ thống
VHDL
entity full_adder is
port(a, b, carry_in: in Bit; -- input ports
sum,carry_out: out Bit); --output
ports
end full_adder;
92
© DHBK 2010
Mô tả hệ thống
SystemC
#include <systemc .h>
#include <iostream>
SC _MODULE( hello ) {
void say_hello () {
cout << " hello " << name () << endl ;}
SC_CTOR( hello ) {
SC THREAD( say_hello );}
};
int sc_main ( int argc , char ** argv ) {
hello hello_inst (" world ");
sc_start ();
}
93
93
© DHBK 2010
Mô tả hệ thống
SystemVerilog
• Corresponds to Verilog versions 3.0 and 3.1.
• Includes:
Additional language elements to model behavior
C data types such as int
Type definition facilities
Definition of interfaces of hardware components as
separate entities
Mechanism for calling C/C++-functions from Verilog
Limited mechanism for calling Verilog functions from C.
94
© DHBK 2010
4. Các vấn đề trong quy trình thiết kế hệ
nhúng
• Mô tả hệ thống (specification)
• Phân chia phần cứng, phần mềm (HW/SW
partitioning)
• Lựa chọn phương án thiết kế (Design space
exploration)
95
© DHBK 2010
HW/SW Partitioning
96
© DHBK 2010
Hardware/Software Co-design
Specification
Mapping
Processor Processor
P1 P2 Hardware
[Niemann, Hardware/Software Co-Design for Data Flow Dominated Embedded Systems, Kluwer
Academic Publishers, 1998 (Comprehensive mathematical model)]
97
© DHBK 2010
4. Các vấn đề trong quy trình thiết kế hệ
nhúng
• Mô tả hệ thống (specification)
• Phân chia phần cứng, phần mềm (HW/SW
partitioning)
• Lựa chọn phương án thiết kế (Design space
exploration)
98
© DHBK 2010
Lựa chọn phương án thiết kế
Traditional HW/SW Co-Design Flow
Design
Specification Estimation
HW/SW Partitioning
HW SW
VHDL, Verilog C
Synthesis Compilation
Co-Simulation
On-Chip Processor
Memory Core
Off-Chip
Memory
Synthesized
Interface
HW
99
© DHBK 2010
HW/SW Partitioning
HW SW
VHDL, Verilog
C
Synthesis Compilation
Co-Simulation
ADL: Architecture
On-Chip Processor
Memory Core
Off-Chip Description Language
Memory
Synthesized
Interface
HW
100
© DHBK 2010
Lựa chọn phương án thiết kế
ADL-driven Design Space Exploration
Processor Memory Co-processor
IP Library IP Library IP Library
ADL Specification
Success
Verify
Failed
101
© DHBK 2010
102
© DHBK 2010
5. Tình hình đào tạo và phát triển hệ
nhúng ở VN
• Phát triển hệ thống nhúng trên thế giới
• Phát triển hệ thống nhúng ở Việt Nam
• Tình hình đào tạo hệ thống nhúng ở Việt Nam
103
© DHBK 2010
5. Tình hình đào tạo và phát triển hệ thống
nhúng ở VN
• Phát triển hệ thống nhúng trên thế giới
• Phát triển hệ thống nhúng ở Việt Nam
• Tình hình đào tạo hệ thống nhúng ở Việt Nam
104
© DHBK 2010
Phát triển hệ thống nhúng trên thế giới
105
© DHBK 2010
Phát triển hệ thống nhúng trên thế giới
106
© DHBK 2010
Phát triển hệ nhúng trên thế giới
Nhật Bản: 40% doanh thu phần mềm là từ phần mềm nhúng
107
© DHBK 2010
Phát triển hệ thống nhúng trên thế giới
108
© DHBK 2010
5. Tình hình đào tạo và phát triển hệ
nhúng ở VN
• Phát triển hệ nhúng trên thế giới
• Phát triển hệ thống nhúng ở Việt Nam
• Tình hình đào tạo hệ nhúng ở Việt Nam
109
© DHBK 2010
110
© DHBK 2010
5. Tình hình đào tạo và phát triển hệ thống
nhúng ở VN
• Phát triển hệ thống nhúng trên thế giới
• Phát triển hệ thống nhúng ở Việt Nam
• Tình hình đào tạo hệ thống nhúng ở Việt Nam
111
© DHBK 2010
Tình hình đào tạo hệ thống nhúng ở Việt Nam
113
© DHBK 2010
PHẦN 2:
THIẾT KẾ HỆ NHÚNG TRÊN
FPGA
114
© DHBK 2010
Chương 1. Giới thiệu chung về công nghệ IC
khả trình PLD
1.1 Công nghệ IC khả trình
1.2 Ứng dụng của công nghệ IC khả trình
115
© DHBK 2010
x y z x y z
F1 F1
116
© DHBK 2010
1.1 Công nghệ IC khả trình
Programmable logic array
• PLA
Programmable
And
Input
plane
Or Output
plane
117
© DHBK 2010
1.1 Công nghệ IC khả trình
Programmable logic array
• PLA
118
© DHBK 2010
1.1 Công nghệ IC khả trình
Programmable Array Logic
• PAL
Programmable
And
Input
plane
Fixed
Or Output
plane
119
© DHBK 2010
1.1 Công nghệ IC khả trình
Programmable Array Logic
120
© DHBK 2010
• CPLD
121
© DHBK 2010
Non-volatile
122
© DHBK 2010
Ví dụ: PROM
Vcc Vcc Vcc Vcc Fuse
After manufacturing
Address
2-to-4 Decoder
2
MSB
2
LSB
2-to-4 Mux
123 Data
© DHBK 2010
Ví dụ: PROM
Vcc Vcc Vcc Vcc
After programming
Address
2-to-4 Decoder
2
MSB
2
LSB
2-to-4 Mux
124 Data
© DHBK 2010
1.1 Công nghệ IC khả trình
Field-programmable Gate Array
• FPGA: XC40xx Routing viaLong
switching
lines matrices
SM SM SM SM
SM SM SM SM
125
© DHBK 2010
1.1 Công nghệ IC khả trình
Field-programmable Gate Array
• Cấu tạo của một CLB (Configurable Logic Block)
16x1 G
LUT: GQ
FF
Bool-function
of 4
G
variables
16x1
F
LUT: FQ
FF
Bool-function
of 4
variables F
126
© DHBK 2010
1.1 Công nghệ IC khả trình
Field-programmable Gate Array
• FPGA: Switching Matrix SM
Pass
TOR
127
© DHBK 2010
1.1 Công nghệ IC khả trình
Field-programmable Gate Array
• Công nghệ lập trình:
SRAM-based:
Volatile
Reprogrammble
Antifuse
Non-volatile
Programmed only-one
IP security
128
© DHBK 2010
1.1Công nghệ IC khả trình
Field-programmable Gate Array
• Hãng cung cấp FPGA hàng đầu thế giới
Công ty Xilinx: http://www.xilinx.com/
Công ty Altera: http://www.altera.com/
Công ty Lattice Semiconductor: http://www.latticesemi.com/
Công ty Actel: http://www.actel.com/
Công ty Crypress: http://www.cypress.com/
Công ty Atmel: http://www.atmel.com/
Công ty QuickLogic: http://www.quicklogic.com/
129
© DHBK 2010
1.1 Công nghệ IC khả trình
Ưu điểm
130
© DHBK 2010
1.1 Công nghệ IC khả trình
Ưu điểm
• FPGA vs Custom ASIC
FPGAs are more flexible
FPGAs are more cost effective for small quantities
ASICs have higher densities
• FPGA vs Parallel Computer
FPGAs are more cost effective
FPGAs are smaller
Parallel Computers are easier to program
131
© DHBK 2010
132
© DHBK 2010
133
© DHBK 2010
134
© DHBK 2010
135
© DHBK 2010
136
© DHBK 2010
137
© DHBK 2010
138
© DHBK 2010
139
© DHBK 2010
140
© DHBK 2010
141
© DHBK 2010
142
© DHBK 2010
Chương 2: Thiết kế dùng IC khả trình của
Xilinx và Altera
2.1 Các họ PLD của Xilinx
2.2 Cấu trúc PLD của Xilinx
2.3 Các bước thiết kế với PLD của Xilinx
2.4 Các họ PLD của Altera
2.5 Cấu trúc PLD của Altera
2.6 Các bước thiết kế với PLD của Altera
143
© DHBK 2010
144
© DHBK 2010
145
© DHBK 2010
2.1 Các họ PLD của Xilinx
A Decade of Progress
1000x
Spartan-2
XC4000 Spartan-3
1x
'91 '92 '93 '94 '95 '96 '97 '98 '99 '00 '01 '02 '03 '04
Year
Courtesy: Richard Sevcik, Xilinx
146
© DHBK 2010
147
© DHBK 2010
148
© DHBK 2010
149
© DHBK 2010
150
© DHBK 2010
151
© DHBK 2010
152
© DHBK 2010
2.2 Cấu trúc PLD của Xilinx
Slices and CLBs
• Each Virtex-II CLB contains
four slices COUT COUT
BUFT
Local routing provides BUF T
feedback between slices in the Slice S3
same CLB, and it provides
routing to neighboring CLBs Slice S2
Switch SHIFT
A switch matrix provides Matrix
access to general routing Slice S1
resources
Slice S0 Local Routing
CIN CIN
154
© DHBK 2010
up only CLR
Two independent
carry chains
155
per CLB
© DHBK 2010
LUTs
MUXF5, MUXF6,
MUXF7, MUXF8
(only the F5 and
F6 MUX are shown
in this diagram)
Carry Logic
MULT_ANDs
Sequential Elements
156
© DHBK 2010
157
© DHBK 2010
F8
MUXF7 outputs (from the CLB
above or below)
F5
Slice S3
MUXF6 combines slices S2
F6
and S3
F5
Slice S2
MUXF6 outputs
Slice S1
F5
Slice S0
F5
158
© DHBK 2010
asynchronous D PRE Q
CE
• All controls are shared within a slice
CLR
Control signals can be inverted
locally within a slice LDCPE
D PRE Q
CE
G
CLR
159
© DHBK 2010
D Q
LUT CE
A[3:0]
Q15 (cascade out)
160
© DHBK 2010
• Input path
Two DDR registers
IOB
• Output path Input
Reg DDR MUX
Two DDR registers OCK1 Reg
ICK1
Two 3-state enable Reg
DDR registers OCK2 3-state Reg
ICK2
• Separate clocks and
clock enables for I and O Reg DDR MUX
OCK1
• Set and reset signals PAD
are shared Reg
OCK2 Output
161
© DHBK 2010
163
© DHBK 2010
after configuration A0
A1
O A0
A1
SPO
LUT
164
© DHBK 2010
165
© DHBK 2010
Data_A
(18 bits) 4 x 4 signed
8 x 8 signed
18 x 18 Output
Multiplier (36 bits) 12 x 12 signed
18 x 18 signed
Data_B
(18 bits)
166
© DHBK 2010
167
© DHBK 2010
168
© DHBK 2010
• Design Flow
169
© DHBK 2010
170
© DHBK 2010
• Design tools:
Webpack ISE (miễn phí)
Thiết kế cho CPLD, FPGA
Có công cụ thiết kế dùng schematic, ngôn ngữ mô tả phần
cứng, công cụ tổng hợp, mô phỏng và vật lý
http://www.xilinx.com/ise/logic_design_prod/webpack.htm
ISE Foundation™ (không miễn phí)
chức năng tương tự như Webpack
EDK and Platform studio
Dùng để thiết kế hệ thống nhúng với FPGA
171
© DHBK 2010
Language based
refinement:
VHDL editor
172
© DHBK 2010
VHDL: Example
173
© DHBK 2010
• Synthesis process:
Check code syntax
Analyze the hierarchy of the design
Compile RTL to gate level
Create netlist of the design
Take into account the architecture of the target FPGA
• Synthesis tools:
XST (Xilinx synthesis technology)
Generate a NGC file
LeonardoSpectrum from Mentor Graphics, Inc
Synplify and Synplify Pro from Synplicity Inc.
174
© DHBK 2010
• Translate:
Translate the design netlist and constraints into (Xilinx) primitives
Input: NGC file, Output: NGD file (Native Generic Database)
• Map:
Map the primitives to the actual physic circuit of the device
Input: NGD file, Output: NCD file ( Native Circuit Description)
• Place and Route (PAR):
Place the circuits on the CLB and find a good route to connect them
Input: NCD file, Output: NCD file
175
© DHBK 2010
176
© DHBK 2010
177
© DHBK 2010
2.4 Các họ PLD của Altera
178
© DHBK 2010
2.4 Các họ PLD của Altera
• Họ Cyclone:
Cyclone III:
2007, 65 nm FPGA
Low power, low cost
Embedded memory, embedded multipliers
179
© DHBK 2010
2.4 Các họ PLD của Altera
• Họ Cyclone:
Cyclone II:
90 nm FPGA
Low power, low cost
Embedded memory, embedded multipliers
180
© DHBK 2010
2.4 Các họ PLD của Altera
• Họ Cyclone:
Cyclone:
2003, 0.13 um
Low power, low cost
Embedded memory
181
© DHBK 2010
2.4 Các họ PLD của Altera
• Họ Stratix:
Stratix III:
2007, 65 nm
Low power, high performance, high density
Embedded memory, multipliers
182
© DHBK 2010
2.4 Các họ PLD của Altera
• Họ Stratix:
Stratix II:
90 nm
high performance, high density
Embedded memory, multipliers, DSP
blocks
183
© DHBK 2010
2.4 Các họ PLD của Altera
• Họ Stratix:
Stratix:
0.13-µm
high performance, high density
Embedded memory, multipliers, DSP blocks
184
© DHBK 2010
2.4 Các họ PLD của Altera
• Họ CPLD:
Max II:
Low cost, high performance
185
© DHBK 2010
186
© DHBK 2010
187
© DHBK 2010
188
© DHBK 2010
189
© DHBK 2010
190
© DHBK 2010
191
© DHBK 2010
192
© DHBK 2010
• Software tools
193
© DHBK 2010
194
© DHBK 2010
195
© DHBK 2010
library IEEE; -- Su dung thu vien chuan IEEE
use IEEE.STD_LOGIC_1164.ALL; --Su dung tat ca cac thanh phan trong goi STD_LOGIC_1164
entity hex2led is
Port ( HEX : in std_logic_vector(3 downto 0);
LED : out std_logic_vector(6 downto 0));
end hex2led;
-- Khai bao hoat dong cua hex2Led
architecture Behavioral of hex2led is
begin
with HEX SELect
LED<= "1111001" when "0001", --1
"0100100" when "0010", --2
"0110000" when "0011", --3
"0011001" when "0100", --4
"0010010" when "0101", --5
"0000010" when "0110", --6
"1111000" when "0111", --7
"0000000" when "1000", --8
"0010000" when "1001", --9
"0001000" when "1010", --A
"0000011" when "1011", --b
"1000110" when "1100", --C
"0100001" when "1101", --d
"0000110" when "1110", --E
"0001110" when "1111", --F
"1000000" when others; --0
end Behavioral;
196
© DHBK 2010
3.1 Giới thiệu về VHDL
Ví dụ 1
• Thiết kế mạch ‘Test’ với 3 đầu vào 8-bit (In1, In2, In3)
và hai đầu ra 1 bit (Out1, Out2). Out1=‘1’ khi In1=In2
và Out2=‘1’ khi In1 = In3
Test
Compare
In1 Out1
A
EQ
B
In2
Compare
A
In3 EQ Out2
B
197 Test là một khối gồm 2 bản copy của khối compare
© DHBK 2010
3.1 Giới thiệu về VHDL
Ví dụ 1
Thiết kế khối compare dùng mạch tổ hợp
Compare
A[0] XNOR
A
B[0]
A[1] AND
EQ
B[1] EQ
B
A[7]
B[7]
198
© DHBK 2010
4.1 Giới thiệu về VHDL
Ví dụ 1
• Thiết kế khối compare dùng VHDL
‘Entity’ xác định giao diện
với bên ngoài của khối cần thiết kế
Chú ý:
-Một entity có thể có nhiều architecture, mỗi architecture là một
cách thể hiện khác nhau của cùng một chức năng
- Các Ports là vector có chiều: vào (in), ra (out), hoặc cả vào cả ra (inout)
199
© DHBK 2010
3.1 Giới thiệu về VHDL
Component và Instantiation
• Biểu diễn Test bằng VHDL
entity Test is
port( In1,In2,In3: in bit_vector(0 to 7);
Out1,Out2: out bit);
end Test;
200
- Đây là architecture miêu tả cấu trúc của entity Test
© DHBK 2010
3.1 Giới thiệu về VHDL
Cấu hình (Configuration)
• Khi một entity có nhiều architectures, ta sẽ xử dụng architecture nào?
• Làm thế nào để gắn ‘Components’ với ‘Entities’?
201
© DHBK 2010
3.1 Giới thiệu về VHDL
Khai báo Entity và Architecture
ENTITY:
entity Entity_name is
port(Signal_name: in Signal_type;
Signal_name: out Signal_type);
end Entity_name;
ARCHITECTURE:
Instance_name: Component_name
port map (Signal_list);
Instance_name: Entity_name(Architecture_name)
port map (Signal_list);
203
© DHBK 2010
3.1 Giới thiệu về VHDL
Khai báo cấu hình
CONFIGURATION:
204
© DHBK 2010
3.1 Giới thiệu về VHDL
Ví dụ 2
• Biểu diễn cổng AND bằng VHDL
A
Y
B
C
entity AND3 is
port ( A,B,C: in bit;
Y: out bit);
end AND3;
205
© DHBK 2010
3.1 Giới thiệu về VHDL
Ví dụ 2
• Biểu diễn cổng OR bằng VHDL
A
Y
B
C
-- 3-input OR gate
entity OR3 is
port ( A,B,C: in bit;
Y: out bit);
end OR3;
206
© DHBK 2010
3.1 Giới thiệu về VHDL
Ví dụ 2
• Biểu diễn cổng INV bằng VHDL
A Y
-- INV gate
entity INV is
port ( A: in bit;
Y: out bit);
end INV;
207
© DHBK 2010
3.1 Giới thiệu về VHDL
Ví dụ 3
• Thiết kế bộ MUX 2-1 dùng VHDL
A
Y
B
S
entity MUX21 is
port ( A,B,S: in bit;
Y: out bit);
end MUX21;
208
© DHBK 2010
3.1 Giới thiệu về VHDL
Ví dụ 3
A
Y
architecture Struct of MUX21 is B
signal U,V,W : bit;
component AND2 S
port ( X,Y: in bit;
Z: out bit);
end component;
component OR2 A
port ( X,Y: in bit; W
Z: out bit);
S Y
end component;
component INV U V
port ( X: in bit;
Z: out bit); B
end component;
begin
Gate1: INV port map (X=>S,Z=>U);
Gate2: AND2 port map (X=>A,Y=>S,Z=>W);
Gate3: AND2 port map (X=>U,Y=>B,Z=>V);
Gate4: OR2 port map (X=>W,Y=>V,Z=>Y);
209 end Struct;
© DHBK 2010
3.1 Giới thiệu về VHDL
Ví dụ 3
• Giả sử ta muốn sử dụng các cổng AND, OR và INV ở
ví dụ 2 trong MUX21
211
© DHBK 2010
3.1 Giới thiệu về VHDL
Sử dụng lại
• Thông thường, các bộ phận của thiết kế này có thể
được dùng lại trong các thiết kế khác
• Các sản phẩm công nghiệp thường bao gồm 95% bộ
phận dùng lại và chỉ có 5% là phải thiết kế mới
• VHDL khuyến khích dùng lại bằng khái niệm
‘Packages’
• Một ‘Package’ chứa các định nghĩa về hằng số, khai
báo component, các kiểu dữ liệu của người sử dụng,
các chương trình con viết bằng VHDL
• Package được cất ở trong ‘Library’: library thực chất
là một thư mục
212
© DHBK 2010
3.1 Giới thiệu về VHDL
Sử dụng lại
Package interface declaration:
package Package_name is
-- constants
-- user defined types
-- component declarations
-- sub programs
end Package_name;
use Library_name.Package_name.all;
213
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Các kiểu dữ liệu đã được định nghĩa
package Standard is
type Bit is (‘0’,’1’);
type Boolean is (False, True);
type Character is (--ASCII set);
type Integer is range implementation_defined;
type Real is range implementation_defined;
type Bit_vector is (--array of bits);
type String is (--array of characters);
type Time is range implementation_defined;
end Standard;
214
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Các kiểu dữ liệu đã được định nghĩa
Khai báo bit_vector, giá trị được đặt trong dấu nháy kép
constant State1: bit_vector(4 downto 0) := “00100”;
216
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Các kiểu dữ liệu đã được định nghĩa
217
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Các kiểu dữ liệu của người sử dụng
218
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Kiểu liệt kê của người sử dụng
Người sử dụng có thể định nghĩa kỉêu liệt kê như sau:
219
© DHBK 2010 PACKAGE example IS
TYPE current IS RANGE 0 TO 1000000000
UNITS
na; --nano amps
ua = 1000 na; --micro amps
ma = 1000 ua; --milli amps
a = 1000 ma; --amps
END UNITS;
TYPE load_factor IS (small, med, big );
END example;
USE WORK.example.ALL;
ENTITY delay_calc IS
PORT ( out_current : OUT current;
load : IN load_factor;
delay : OUT time);
END delay_calc;
ARCHITECTURE delay_calc OF delay_calc IS
BEGIN
delay <= 10 ns WHEN (load = small) ELSE
delay <= 20 ns WHEN (load = med) ELSE
delay <= 30 ns WHEN (load = big) ELSE
delay <= 10 ns;
out_current <= 100 ua WHEN (load = small)ELSE
out_current <= 1 ma WHEN (load = med) ELSE
out_current <= 10 ma WHEN (load = big) ELSE
out_current <= 100 ua;
220
END delay_calc;
© DHBK 2010
4.2 Tín hiệu và các kiểu dữ liệu:
Kiểu mảng array
VARIABLE X: data_bus;
VARIABLE Y: BIT;
Y := X(0);
Y := X(15);
221
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Kiểu bản ghi record
TYPE optype IS ( add, sub, mpy, div, jmp );
TYPE instruction IS
PROCESS(X)
RECORD
VARIABLE inst : instruction;
opcode : optype; VARIABLE source, dest : INTEGER;
src : INTEGER; VARIABLE operator : optype;
dst : INTEGER; BEGIN
END RECORD; source := inst.src; --Ok line 1
dest := inst.src; --Ok line 2
source := inst.opcode; --error line 3
operator := inst.opcode; --Ok line 4
inst.src := dest; --Ok line 5
inst.dst := dest; --Ok line 6
inst := (add, dest, 2); --Ok line 7
inst := (source); --error line 8
END PROCESS;
222
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Standard logic
library IEEE;
use IEEE.Std_logic_1164.All;
type std_logic is (
‘U’, -- uninitialized e.g. after power-up
‘X’, -- strongly driven unknown e.g. after setup violation
‘0’, -- strongly driven logic zero
‘1’, -- strongly driven logic one
‘Z’, -- high impedance e.g. not driven at all
‘W’, -- weakly driven unknown
‘L’, -- weakly driven logic zero
‘H’, -- weakly driven logic one
‘-’); -- don’t care
223
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Standard logic
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
PACKAGE memory IS
CONSTANT width : INTEGER := 3;
CONSTANT memsize : INTEGER := 7;
TYPE data_out IS ARRAY(0 TO width) OF std_logic;
TYPE mem_data IS ARRAY(0 TO memsize) OF data_out;
END memory;
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE WORK.memory.ALL;
ENTITY rom IS
PORT( addr : IN INTEGER;
data : OUT data_out;
cs : IN std_logic);
END rom;
224
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Standard logic
ARCHITECTURE basic OF rom IS
CONSTANT z_state : data_out := (‘Z’, ‘Z’, ‘Z’, ‘Z’);
CONSTANT x_state : data_out := (‘X’, ‘X’, ‘X’, ‘X’);
CONSTANT rom_data : mem_data :=
( ( ‘0’, ‘0’, ‘0’, ‘0’),
( ‘0’, ‘0’, ‘0’, ‘1’),
( ‘0’, ‘0’, ‘1’, ‘0’),
( ‘0’, ‘0’, ‘1’, ‘1’),
( ‘0’, ‘1’, ‘0’, ‘0’),
( ‘0’, ‘1’, ‘0’, ‘1’),
( ‘0’, ‘1’, ‘1’, ‘0’),
( ‘0’, ‘1’, ‘1’, ‘1’) );
BEGIN
ASSERT addr <= memsize
REPORT “addr out of range”
SEVERITY ERROR;
data <= rom_data(addr) AFTER 10 ns WHEN cs = ‘1’ ELSE
data <= z_state AFTER 20 ns WHEN cs = ‘0’ ELSE
data <= x_state AFTER 10 ns;
END basic;
225
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Gán tín hiệu
• Gán theo vị trí, không gán theo chỉ số của mảng
Up <= Down;
227
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Gán tín hiệu
• Có thể kết hợp hai mảng khác nhau
Nibble_busA(3)
Nibble_busA(2)
Byte_bus(7) Nibble_busA(1)
Byte_bus(6) Nibble_busA(0)
Byte_bus(5)
Byte_bus(4)
Byte_bus(3)
Byte_bus(2)
Byte_bus(1) Nibble_busB(3)
Byte_bus(0) Nibble_busB(2)
Nibble_busB(1)
Nibble_busB(0)
228
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Gán tín hiệu
• Not supported by all synthesis tools!!
229
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Tham số dùng chung (Generic)
•Dùng để truyền tham số từ entity tới các bản copy của nó
•Các bản copy có thể có các giá trị tham số khác nhau
entity General_mux is
generic (width : integer);
port ( Input : in std_logic_vector (width - 1 downto 0);
Select : in integer range 0 to width - 1;
Output : out std_logic);
end General_mux;
230
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Tham số dùng chung (Generic)
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
ENTITY test IS
GENERIC(rise, fall : TIME; load : INTEGER);
PORT ( ina, inb, inc, ind : IN std_logic;
out1, out2 : OUT std_logic);
END test;
231
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Tham số dùng chung (Generic)
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
ENTITY test IS
GENERIC(rise, fall : TIME;
GENERIC(load : INTEGER);
PORT ( ina, inb, inc, ind : IN std_logic;
PORT ( out1, out2 : OUT std_logic);
END test;
ARCHITECTURE test_arch OF test IS
COMPONENT and2
GENERIC(rise, fall : TIME := 10 NS;
GENERIC(load : INTEGER := 0);
PORT ( a, b : IN std_logic;
PORT ( c : OUT std_logic);
END COMPONENT;
BEGIN
U1: and2 GENERIC MAP(10 ns, 12 ns, 3 )
PORT MAP (ina, inb, out1 );
U2: and2 PORT MAP (inc, ind, out2 );
END test_arch;
232
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Thuộc tính (attributes)
TYPE state IS (0 TO 7);
PROCESS(x)
SUBTYPE smallreal IS REAL RANGE -1.0E6 TO 1.0E6;
VARIABLE q : real;
BEGIN
q := smallreal’LEFT; -- use of ’left returns 1.0E6
END PROCESS;
233
© DHBK 2010
3.2 Tín hiệu và các kiểu dữ liệu:
Thuộc tính (attributes)
PROCESS(a)
TYPE bit4 IS ARRAY(0 TO 3) of BIT;
TYPE bit_strange IS ARRAY(10 TO 20) OF BIT;
VARIABLE len1, len2 : INTEGER;
BEGIN
len1 := bit4’LENGTH; -- returns 4
len2 := bit_strange’LENGTH; -- returns 11
END PROCESS;
Xem “VHDL programming by example” để biết chi tiết hơn về thuộc tính
234
© DHBK 2010
3.3 Các phép toán số học và logic:
Các phép toán logic
• Các phép toán logic gồm: not, and, or, xor, nand, nor
• Thứ tự ưu tiên:
‘not’ được thực hiện đầu tiên
Các lệnh còn lại có cùng mức ưu tiên
• Các phép toán logic được dùng cho các kiểu dữ liệu
sau : bit, bit_vector, boolean, std_logic,
std_logic_vector, std_ulogic, std_ulogic_vector
• Các phép toán logic có thể được dùng với mảng:
Các mảng phải có cùng kích thước
Các phần tử của mảng tương ứng theo vị trí
235
© DHBK 2010
3.3 Các phép toán số học và logic:
Các phép toán logic
library IEEE;
use IEEE.Std_Logic_1164.All;
entity Gate is
port( A,B,C: in std_logic;
Z: out std_logic);
end Gate;
236
© DHBK 2010
3.3 Các phép toán số học và logic:
Các phép toán logic
library IEEE;
use IEEE.Std_Logic_1164.All;
entity Gate is
generic(width : integer range 0 to 31);
port( A,B,C: in std_logic_vector(width-1 downto 0);
Z: out std_logic_vector(width-1 downto 0));
end Gate;
237
© DHBK 2010
Các phép toán số học và logic:
Các phép toán so sánh
• Các phép toán so sánh gồm: <, <=, =>, >, =, /=
• Kết quả của phép so sánh là kiểu boolean
• Hai toán hạng phải có cùng kiểu dữ liêụ
• Phép toán so sánh có thể được dùng cho mảng
Mảng có thể có kích thước khác nhau!
Các phần tử của mảng sẽ được so sánh từng bit, từ trái
sang phải
Bit vector có thể được so sánh nếu như có cùng độ dài và
khi so sánh giá trị của bit vector sẽ được đổi sang số nguyên
không dấu để so sánh
238
Các phép toán so sánh
© DHBK 2010
library IEEE
use IEEE.Std_Logic_1164.All;
What is the
entity Compare is
value of Z?
port( A: in std_logic_vector(3 downto 0);
B: in std_logic_vector(0 to 4); TRUE?
Z: out boolean);
end Compare; FALSE?
240
© DHBK 2010
3.3 Các phép toán số học và logic:
Các phép toán số học
entity Add is
port ( A,B: in integer range 0 to 7;
Z: out integer range 0 to 14);
end Add;
241
© DHBK 2010
3.4 Các lệnh song song và tuần tự :
Các lệnh song song
• Tất cả các lệnh trong architecture đều được thực hiện
đồng thời (song song) giống như trong phần cứng,
các cổng logic hoạt động đồng thời
entity Concurrent is
port ( A,B,C,D: in std_logic; Schematic:
Y,Z: out std_logic);
end Concurrent;
A
architecture Struct of Concurrent is Y
B
begin
NAND1: entity NAND2 port map (A,B,Y); C
Z
NAND2: entity NAND2 port map (C,D,Z); D
end Struct;
Mạch sẽ hoạt động thế nào nếu như khai báo NAND1 sau NAND2?
242
© DHBK 2010
3.4 Các lệnh song song và tuần tự :
Các lệnh song song
entity Concurrent is
port ( A,B,C,D: in std_logic; Schematic:
Y,Z: out std_logic);
end Concurrent;
A
architecture Struct of Concurrent is Y
B
begin
NAND2: entity NAND2 port map (C,D,Z); C
Z
NAND1: entity NAND2 port map (A,B,Y); D
end Struct;
Schematic:
A
entity Concurrent is B T1
port ( A,B, D: in std_logic;
Z: out std_logic); Z
end Concurrent; D
244
© DHBK 2010
3.4 Các lệnh song song và tuần tự :
Process
• Nhiều khi phương trình tổ hợp trong một câu lệnh rất
phức tạp, ví dụ:
A
B
C
D Y
entity Complex is E
port( A,B,C,D,E,F,G,H,I,J: F S
in std_logic; G
Y,Z: out std_logic);
H
end Complex;
I Z
architecture Struct of Complex is J
begin
Y <= ((A nand B) nand (C nand D))
when (S = ‘1’) else
((E nand F) nand (G nand H));
Z <= I nand J;
end Struct;
245
© DHBK 2010
3.4 Các lệnh song song và tuần tự :
Process
• Vì vậy người ta đưa ra khái niệm process:
Một process hoạt động như một câu lệnh và được thực hiện
đồng thời với các câu lệnh khác
Bên trong một process, các lệnh được thực hiện tuần tự
theo thứ tự từ trên xuống dưới. Điều này giúp cho việc chia
nhỏ một lệnh rất phức tạp thành các lệnh đơn giản hơn.
Để truyền dữ liệu giữa các lệnh trong một process chúng ta
có thể dùng các biến tạm thời variables. Các biến này không
nhất thiết phải là một tín hiệu vật lý nào.
process sẽ được thực hiện lại mỗi khi có một sự kiện
(event) xảy ra đối với một tín hiệu (signal) nào đó trong danh
sách tín hiệu nhạy cảm (sensitivity list).
246
© DHBK 2010
3.4 Các lệnh song song và tuần tự :
Process
Cú pháp khai báo Process:
Variable_name := expression;
Gán biến :=
247
Gán tín hiệu <=
© DHBK 2010
3.4 Các lệnh song song và tuần tự :
Process
entity Complex is
port( A,B,C,D,E,F,G,H,I,J: T1 and T2 have no
in std_logic; physical meaning since
Y,Z: out std_logic); each refers to 2 different
end Complex; physical wires
249
7. Không có tín hiệu nào trong sensitivity list thay đổi, process dừng
© DHBK 2010
IF statement:
if condition then
-- sequential statements multiple IF statements:
else
-- sequential statements if condition1 then
end if; -- sequential statements
elsif condition2 then
-- sequential statements
elsif condition3 then
-- sequential statements
else
-- sequential statements
end if;
250
© DHBK 2010
CASE bit_vec IS
WHEN “00” =>
RETURN 0;
WHEN “01” =>
RETURN 1;
WHEN “10” =>
RETURN 2;
WHEN “11” =>
RETURN 3;
END CASE;
252
© DHBK 2010
for I in 0 to 3 loop
-- sequential statements
end loop;
Chú ý:
1. Không được khai báo biến dùng trong vòng for và không
được gán giá trị cho biến đó
FOR i IN 1 to 10 LOOP
i_squared(i) := i * i;
END LOOP;
253
© DHBK 2010
entity General_mux is
generic (width : integer);
port ( Input : in std_logic_vector (width - 1 downto 0);
Select : in integer range 0 to width - 1;
Output : out std_logic);
end General_mux;
254
© DHBK 2010
Cấu trúc NEXT được dùng để bỏ qua vòng lặp hiện tại để nhảy tới
vòng lặp tiếp theo
255
© DHBK 2010
Cấu trúc EXIT được dùng để thoát ra khỏi vòng lặp for
256
© DHBK 2010
PROCESS
BEGIN
WAIT UNTIL clock = ‘1’ AND clock’EVENT;
q <= d;
END PROCESS;
PROCESS
BEGIN
WAIT ON a; -- 1.
.
WAIT ON b; -- 2.
.
END PROCESS;
257
© DHBK 2010
3.5 Các cấu trúc tuần tự
Biến (Variables)
• Variable chỉ được sử dụng trong process hoặc
chương trình con
• Giá trị của variable được cập nhật ngay lập tức trong
khi giá trị của tín hiệu signal sẽ được cập nhật khi
process kết thúc
• Biến và tín hiệu có thể đựơc gán giá trị cho nhau
• Biến chỉ được dùng tạm thời trong process, nếu giá trị
của nó muốn được truy cập ngoài process ta phải gán
giá trị đó cho một tín hiệu
258
© DHBK 2010
3.5 Các cấu trúc tuần tự
Biến (Variables)
• LIBRARY IEEE;
• USE IEEE.std_logic_1164ALL;
• ENTITY mux IS
• PORT (I0, I1, I2, I3, A, B : IN std_logic;
Q : OUT std_logic);
Tìm chỗ sai trong đoạn mã !
• END mux;
259
© DHBK 2010
3.5 Các cấu trúc tuần tự
Biểu diễn sườn lên của xung nhịp
Tìm chức năng của entity What
entity What is
port (D,Clk: in std_logic;
Q: out std_logic);
end What; Since there is no ELSE part
the previous Q value has
architecture RTL of What is to be remembered for the case
begin where Clk=‘0’.
process (D, Clk) is The synthesis tool will hence
begin infer a latch instead of just
if (Clk=‘1’) then combinatorial logic!!!
Q <= D;
end if; Beware of unintended latches
end process; when ELSE parts are omitted
end RTL;
With a latch, not with a D-flip-flop!!
entity DFlipFlop is
port (D,Clk: in std_logic;
Q: out std_logic);
end DFlipFlop;
261
© DHBK 2010
3.5 Các cấu trúc tuần tự
Biểu diễn sườn lên của xung nhịp
Cách 2: Sensitivity list
entity DFlipFlop is
port (D,Clk: in std_logic;
Q: out std_logic);
end entity DFlipFlop;
262
© DHBK 2010
3.5 Các cấu trúc tuần tự
Biểu diễn Finite State Machine
Start=0
Wait
Reset Start=1 00
Out Output Start=1
Up=1 Up=0
put
logic
Up1 Down3
State 01 11
Reg CurrentState
Up3 Down1
11 01
Start Up
263
© DHBK 2010
3.5 Các cấu trúc tuần tự
Biểu diễn Finite State Machine
Start=0
entity FSM is
port ( Start, Up, Reset, Clk: in std_logic; Wait
Output: out std_logic_vector(0 to 1)); 00
Start=1 Start=1
end FSM;
Up=1 Up=0
architecture Behav of FSM is
type FSM_States is (Wait,Up1,Up2,Up3,Down1,Down2,Down3); Up1 Down3
signal CurrentState, NextState : FSM_States; 01 11
begin
OutputLogic:
process(CurrentState) is
end process; Up2 Down2
NextStateLogic: 10 10
process(CurrentState,Start,Up) is
…
end process;
StateRegister: Up3 Down1
process(NextState,Clk,Reset) is 11 01
…
end process;
end Behav;
264
© DHBK 2010
3.5 Các cấu trúc tuần tự
Biểu diễn Finite State Machine
Start=0
Wait
Start=1 00 Start=1
OutputLogic:
process(CurrentState) is Up=1 Up=0
begin
case CurrentState is Up1 Down3
when Wait => 01 11
Output <= “00”;
when Up1|Down1 =>
Output <= “01”;
when Up2|Down2 => Up2 Down2
Output <= “10”; 10 10
when Up3|Down3 =>
Output <= “11”;
end case;
end process; Up3 Down1
11 01
265
© DHBK 2010
3.5 Các cấu trúc tuần tự
Biểu diễn Finite State Machine
NextStateLogic:
process(CurrentState,Start,Up) is Start=0
begin
case CurrentState is
Wait
when Wait =>
Start=1 00 Start=1
if (Start=‘0’) then
NextState <= Wait; Up=1 Up=0
elsif (Up=‘1’) then
NextState <= Up1; Up1 Down3
else 01 11
NextState <= Down3;
end if;
when Up1 =>
NextState <= Up2; Up2 Down2
when Up2 => 10 10
NextState <= Up3;
when Up3|Down1 =>
NextState <= Wait;
when Down3 => Up3 Down1
NextState <= Down2; 11 01
when Down2 =>
NextState <= Down1;
end case;
266 end process;
© DHBK 2010
3.5 Các cấu trúc tuần tự
Biểu diễn Finite State Machine
Start=0
Wait
Start=1 00 Start=1
Up=1 Up=0
StateRegister:
process(NextState,Clk,Reset) is Up1 Down3
begin 01 11
if Reset=‘1’ then
CurrentState <= Wait;
elseif (Clk’event and Clk=‘1’) then
CurrentState <= NextState; Up2 Down2
end if; 10 10
end process;
Up3 Down1
11 01
267
© DHBK 2010
268
© DHBK 2010
270