More Related Content
Similar to Thiet ke-he-thong-nhung vu-duc--ngo-thietkehenhung_k60 - [cuuduongthancong.com] (20)
Thiet ke-he-thong-nhung vu-duc--ngo-thietkehenhung_k60 - [cuuduongthancong.com]
- 1. THIẾT KẾ
HỆ THỐNG NHÚNG
TS. Vu-Duc Ngo
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 2. © DHBK 2010
2
About your lecturer
• Bộ môn điện tử và kỹ thuật máy tính, ĐHBK Hà nội
Office: C9-401
Email: duc.ngovu@hust.edu.vn
• Research:
FPGA, embedded systems
Wireless Communications, Multimedia Codec
NoC
• Education:
K37 điện tử-ĐHBK Hà nội (1997)
Ph.D @KAIST
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 3. © DHBK 2010
3
Mục đích của môn học
• Nắm được quy trình thiết kế hệ thống nhúng, phần
cứng, phần mềm hệ thống nhúng
• Nắm được công nghệ IC khả trình PLD và quy trình
thiết kế hệ thống số với PLD
• Có khả năng thiết kế hệ nhúng trên FPGA sử dụng
công cụ thiết kế của Xilinx và Altera
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 4. © DHBK 2010
4
• Tài liệu tham khảo:
Slides
E-books
VHDL programming by Example 4th edition by Douglas L. Perry
Website
www.xilinx.com
www.Altera.com
Course email: thietkevoifpga@gmail.com password: hut123456
• Đánh giá
Điều kiện dự thi: hoàn thành bài tập lớn và lên lớp đầy đủ
Kiểm tra giữa kỳ (30%)
Bài tập lớn (30 %) (làm theo nhóm 4-5 sinh viên)
Thi cuối kỳ (40 %)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 5. © DHBK 2010
5
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 6. © DHBK 2010
6
PHẦN 1:
GiỚI THIỆU VỀ HỆ THỐNG NHÚNG
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 7. © DHBK 2010
7
NỘI DUNG
1. Giới thiệu về hệ thống nhúng
2. Phần cứng hệ nhúng
3. Phần mềm hệ nhúng
4. Các vấn đề trong quy trình thiết kế hệ nhúng
5. Tình hình đào tạo và phát triển hệ nhúng ở VN
6. Kết luận
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 8. © DHBK 2010
8
1. Giới thiệu về hệ thống nhúng
• Định nghĩa
• Các loại hệ thống nhúng
• Các thành phần của hệ thống nhúng
• Các đặc điểm của hệ thống nhúng
• Yêu cầu thiết kế
• Quy trình phát triển hệ nhúng
• Xu hướng phát triển
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 9. © DHBK 2010
9
1. Giới thiệu về hệ thống nhúng
• Định nghĩa
• Các loại hệ thống nhúng
• Các thành phần của hệ thống nhúng
• Các đặc điểm của hệ thống nhúng
• Yêu cầu thiết kế
• Quy trình phát triển hệ nhúng
• Xu hướng phát triển
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 11. © DHBK 2010
11
Đị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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 12. © DHBK 2010
12
Ví dụ: BMW 745i
• 2, 000, 000 LOC
• Windows CE OS
• 53 8-bit P
• 11 32-bit P
• 7 16-bit P
• Multiple Networks
*Engine
Performance
and Emission
Control
(Traction
Control)
*Safety
Systems
*Cabin Air
Quality
*Suspension
and
Braking
Control
*Steering Controls
*Entertainmen
t
*Intelligent
Transportation System
(ITS)
*Digital Car
Radio
*Lighting
*Gear
Box
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 13. © DHBK 2010
13
1. Giới thiệu về hệ thống nhúng
• Định nghĩa
• Các loại hệ thống nhúng
• Các thành phần của hệ thống nhúng
• Các đặc điểm của hệ thống nhúng
• Yêu cầu thiết kế
• Quy trình phát triển hệ nhúng
• Xu hướng phát triển
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 14. © DHBK 2010
14
Các lọai hệ thống nhúng
• Các hệ thống xử lý tín hiệu
Real-time video, set-top boxes, DVD players, medical
equipment, residential gateways
• Các hệ thống điều khiển phân tán
Network routers, switches, firewalls, mass transit systems,
elevators
• Các hệ thống “nhỏ”
Mobile phones, pagers, home appliances, toys, smartcards,
MP3 players, PDAs, digital cameras, sensors, smart badges
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 15. © DHBK 2010
15
1. Giới thiệu về hệ thống nhúng
• Định nghĩa
• Các loại hệ thống nhúng
• Các thành phần của hệ thống nhúng
• Các đặc điểm của hệ thống nhúng
• Yêu cầu thiết kế
• Quy trình phát triển hệ nhúng
• Xu hướng phát triển
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 16. © DHBK 2010
16
Các thành phần của hệ thống nhúng
Analog Digital Analog
Memory
Coprocessors
Controllers
Converters
Processor
Interface
Software
(Application Programs)
ASIC
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 17. © DHBK 2010
17
• Các phần tử tương tự
Sensors, Actuators, …
• Các phần tử số
Bộ vi xử lý, Bộ đồng xử lý, Bộ nhớ, Buses
Khối điều khiển, IC chuyên dụng (ASIC)
• Phần tử chuyển đổi
ADC, DAC
• Phần mềm
Hệ điều hành
Middleware
Các chương trình ứng dụng (MPEG-x, GSM-kernel, …)
Các thành phần của hệ thống nhúng
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 18. © DHBK 2010
18
1. Giới thiệu về hệ thống nhúng
• Định nghĩa
• Các loại hệ thống nhúng
• Các thành phần của hệ thống nhúng
• Các đặc điểm của hệ thống nhúng
• Yêu cầu thiết kế
• Quy trình phát triển hệ nhúng
• Xu hướng phát triển
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 19. © DHBK 2010
19
Các đặc điểm của hệ thống nhúng
• Chuyên dụng
Ứng dụng được định nghĩa trước
Tối ưu về giá thành, về tài nguyên phần cứng, về công
suất tiêu thụ và về hiệu năng hoạt động.
• Xử lý tín hiệu số
Tín hiệu được biểu diễn và xử lý số
• Có tính đáp ứng
Đáp ứng với những thay đổi của môi trường xung quanh
• Thời gian thực
Các công việc phải được xử lý và hoàn thành trước một
thời gian định trước
• Tính phân tán, kết nối mạng, …
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 20. © DHBK 2010
20
1. Giới thiệu về hệ thống nhúng
• Định nghĩa
• Các loại hệ thống nhúng
• Các thành phần của hệ thống nhúng
• Các đặc điểm của hệ thống nhúng
• Yêu cầu thiết kế
• Quy trình phát triển hệ nhúng
• Xu hướng phát triển
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 21. © DHBK 2010
21
Yêu cầu thiết kế
• Các thông số cơ bản
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
Size: the physical space required by the system
Performance: the execution time or throughput of the system
Power: the amount of power consumed by the system
Flexibility: the ability to change the functionality of the system without
incurring heavy NRE cost
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 22. © DHBK 2010
22
Yêu cầu thiết kế
• Các thông số cơ bản (tiếp)
Time-to-prototype: the time needed to build a working version of the
system
Time-to-market: the time required to develop a system to the point that it
can be released and sold to customers
Maintainability: the ability to modify the system after its initial release
Correctness, safety, many more
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 23. © DHBK 2010
23
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
would have highest sales
• Average time-to-market
constraint is about 8 months
• Delays can be costly
Revenues
($)
Time (months)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 24. © DHBK 2010
24
Yêu cầu thiết kế
Thiệt hại khi đưa ra thị trường chậm
• Simplified revenue model
Product life = 2W, peak at W
Time of market entry defines a
triangle, representing market
penetration
Triangle area equals revenue
• Loss
The difference between the on-time
and delayed triangle areas (shaded
region)
On-time Delayed
entry entry
Peak revenue
Peak revenue from
delayed entry
Market rise Market fall
W 2W
Time
D
On-time
Delayed
Revenues
($)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 25. © DHBK 2010
25
• Area = 1/2 * base * height
• On-time = 1/2 * 2W * W
Delayed = 1/2 * (W-D+W)*(W-D)
• Percentage revenue loss =
(D(3W-D)/2W2)*100%
• Try some examples
On-time Delayed
entry entry
Peak revenue
Peak revenue from
delayed entry
Market rise Market fall
W 2W
Time
D
On-time
Delayed
Revenues
($)
1. Lifetime 2W=52 wks, delay D=4 wks Loss =
(4*(3*26 –4)/2*262) = 22%
2. Lifetime 2W=52 wks, delay D=10 wks
Loss = (10*(3*26 –10)/2*262) = 50%
Delays are costly!
Yêu cầu thiết kế
Thiệt hại khi đưa ra thị trường chậm
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 26. © DHBK 2010
26
• 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
Amortizing NRE cost over the units results in
an additional $200 per unit
Yêu cầu thiết kế
Giá thành (cost)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 27. © DHBK 2010
27
1. Giới thiệu về hệ thống nhúng
• Định nghĩa
• Các loại hệ thống nhúng
• Các thành phần của hệ thống nhúng
• Các đặc điểm của hệ thống nhúng
• Yêu cầu thiết kế
• Quy trình phát triển hệ nhúng
• Xu hướng phát triển
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 28. © DHBK 2010
28
Quy trình phát triển hệ nhúng
Ý tưởng
Specification Phân chia HW/SW
Các phần tử phần cứng
Phần mềm
Estimation -
Exploration
Phần cứng
Phần mềm
Validation and Evaluation (area, power, performance, …)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 29. © DHBK 2010
29
1. Giới thiệu về hệ thống nhúng
• Định nghĩa
• Các loại hệ thống nhúng
• Các thành phần của hệ thống nhúng
• Các đặc điểm của hệ thống nhúng
• Yêu cầu thiết kế
• Quy trình phát triển hệ nhúng
• Xu hướng phát triển
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 30. © DHBK 2010
30
Xu hướng phát triển
1980 1985 1990 1995 2000 2005
Time
Number of transistors
1
10
100
1K
10K
100K
1M
55%/year
Exponential growth for 3 decades!
This is called „Moore‟s law‟: number of transistors
doubles every 18 months
(Gordon Moore, founder Intel Corp.)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 31. © DHBK 2010
31
Xu hướng phát triển
1960 1970 1980 1990 2000 2010
+ Communications
+ DSP
Mainframe
0.01
Compute
Power
1000
PC
1
10
Smart Things
>100 #
+ Ambient
Intelligence
1
/ human
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 32. © DHBK 2010
32
Xu hướng phát triển
Các thiết bị thông minh
Bloodgas sensor (IMEC)
Cochlear actuator(Cochlear Edegem)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 33. © DHBK 2010
33 © Emile Aarts, HomeLab, Philips
Xu hướng phát triển
Môi trường thông minh
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 34. © DHBK 2010
34
2. Phần cứng hệ nhúng
• Tổng quan
• Khối vào ra
• Khối truyền thông
• Khối xử lý
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 35. © DHBK 2010
35
2. Phần cứng hệ nhúng
• Tổng quan
• Khối vào ra
• Khối truyền thông
• Khối xử lý
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 37. © DHBK 2010
37
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)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 38. © DHBK 2010
38
• 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
Tổng quan
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 39. © DHBK 2010
39
2. Phần cứng hệ nhúng
• Tổng quan
• Khối vào ra
• Khối truyền thông
• Khối xử lý
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 40. © DHBK 2010
40
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 …
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 41. © DHBK 2010
41
Khối vào ra
Charge-Coupled Devices (CCD)
Image Sensors: Based on charge transfer to next pixel cell
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 42. © DHBK 2010
42
Khối vào ra
Biometrical Sensors
Example: Fingerprint sensor (© Siemens, VDE):
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 43. © DHBK 2010
43
Khối vào ra
Artificial eyes
© Dobelle Institute
(www.dobelle.com)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 44. © DHBK 2010
44
He looks hale, hearty, and healthy — except for the
wires. They run from the laptops into the signal
processors, then out again and across the table and
up into the air, flanking his face like curtains before
disappearing into holes drilled through his skull.
Since his hair is dark and the wires are black, it's
hard to see the actual points of entry. From a
distance the wires look like long ponytails.
© Dobelle Institute
(www.dobelle.com)
Khối vào ra
Artificial eyes
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 46. © DHBK 2010
46
2. Phần cứng hệ nhúng
• Tổng quan
• Khối vào ra
• Khối truyền thông
• Khối xử lý
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 47. © DHBK 2010
47
Khối truyền thông
Sensor/actuator busses
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 48. © DHBK 2010
48
Khối truyền thông
Sensor/Actuator Bus
Many wires less wires expensive & flexible
CNC: Computerized Numerical Control
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 49. © DHBK 2010
49
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.
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 50. © DHBK 2010
50
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 51. © DHBK 2010
51
• IEEE 802.11 a/b/g
• UMTS (Universal Mobile Telecommunications System)
Bandwidth is becoming a scarce resource.
• DECT (Digital Enhanced Cordless Telecommunications)
Standard used for wireless phones in Europe
• Bluetooth
Connect devices e.g., mobile phone and headset
Khối truyền thông
Wireless Communication
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 52. © DHBK 2010
52
2. Phần cứng hệ nhúng
• Tổng quan
• Khối vào ra
• Khối truyền thông
• Khối xử lý
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 53. © DHBK 2010
53
Khối xử lý
• IC chuyên dụng ASIC (Mpeg-2 decoder, Mp3
encoder…)
• Vi xử lý
Vi xử lý đa năng (Intel, AMD, ARM, Power PC)
Vi điều khiển
DSP
• Reconfigurable Hardware
PAL, PLA, CPLD, FPGA
• Memory
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 54. © DHBK 2010
54
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 55. © DHBK 2010
55
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 57. © DHBK 2010
57
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 58. © DHBK 2010
58
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
pointing devices and telecom processors.
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 59. © DHBK 2010
59
Họ vi điều khiển 8051
• Hiện nay có hơn 40 công ty sản xuất các loại vi
điều khiển khác nhau của họ 8051.
• Một số công ty có trên 40 version 8051.
• Các CORE 8051 có thể được tổ hợp trong các
FPGA hay ASIC.
• Trên 100 triệu vi điều khiển 8051 được bán ra mỗi
năm.
• Họ 8051 gặt hái được rất nhiều thành công và nó
cũng trực tiếp ảnh hưởng đến cấu trúc của các họ
vi điều khiển hiện nay.
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 60. © DHBK 2010
60
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 61. © DHBK 2010
61
Họ vi điều khiển 8051
§iÒu khiÓn
ng¾t
CPU
Bé
dao ®éng
Nguån
Ng¾t
Trong
Ram trong
Thanh ghi
chøc n¨ng
®Æc biÖt
128 byte
RAM
Qu¶n
lý Bus
Port
0
Port
1
Port
2
Port
3
Cæng
nèi
tiÕp
XTAL 1,2 PSEN ALE §Þa chØ
thÊp/d÷ liÖu
§Þa
chØ cao
00
7F
FF
80
C¸c ng¾t ngoµi C¸c sù kiÖn cÇn ®Õm
128 byte
ram
Më réng
trong 8032
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 62. © DHBK 2010
62
Họ vi điều khiển AVR
Thanh ghi
®iÒu khiÓn
§¬n vÞ ng¾t
§¬n vÞ SPI
UART nèi tiÕp
Timer/Counter
8 bÝt
Timer/Counter
16 bit víi
PWM
Bé ®Þnh thêi
watchdog
Bé so s¸nh
analog
15 ®-êng dÉn
vµo/ra
Bé nhí flash
1k x 16 cho
ch-¬ng tr×nh
Bé ®Õm
ch-¬ng tr×nh
Tr¹ng th¸i vµ
kiÓm tra
Bus d÷ liÖu 8 bÝt
Thanh ghi
lÖnh
Bé gi¶i
m· lÖnh
Thanh ghi
®a n¨ng
32 x 8
ALU
128 x 8
Data
SRAM
128x8
EEPROM
C¸c ®-êng ®iÒu
khiÓn
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 63. © DHBK 2010
63
PSoC
• Do hãng Cypress sản xuất
• Một loại công nghệ IC mới phát triển trong vài năm
gần đây.
• Khả năng tích hợp động các loại linh kiện số và tương
tự để tạo ra các khối số hoặc tương tự với chức năng
tuỳ thuộc người dùng.
• Kết hợp với một vi điều khiển trung tâm.
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 64. © DHBK 2010
64
Cấu trúc PSoC
• Lõi PSoC
Vi xử lý 8bit, 24MHz, 4MIPS
Flash ROM (từ 16K)
RAM (128b-2kb)
Bộ điều khiển ngắt
Bus
• Các khốI số
Flip-Flop, cổng logic
• Các khốI tương tự
Các bộ khuếch đạI thuật toán
Điện trở
Tụ điện điều khiển đóng ngắt
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 65. © DHBK 2010
65
DSP
Texas Instruments TMS320C20x
Low end consumer Fixed Point
• Series continued; typical app.: Digital camera, feature-phones, disk drives,
Point-of-Sales Terminal
• 40 MHz, 3.3-5V, 3LM
• Available as core
Selection of
peripherals:
serial comm.,
timers,...
fixed MAC
16x16+32->32
PROM
Dual access
data RAM
address
data
16
18
address
data
16
16
I/O
Loop controller
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 66. © DHBK 2010
66
DSP
Texas Instruments TMS320C24x
Low end consumer Fixed Point
• Series continued; typical app.: electrical motor control
• 50 MHz, 5V
Selection of
peripherals:
serial comm.,
timers,...
fixed MAC
16x16+32->32
PROM
Dual access
data RAM
address
data
16
16
Loop controller
8 output PWM
8 channel A/D
CAN bus
controller
watchdog
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 67. © DHBK 2010
67
Bộ nhớ
Write ability and storage permanence of memories,
showing relative degrees along each axis (not to scale).
External
programmer
OR in-system,
block-oriented
writes, 1,000s
of cycles
Battery
life (10
years)
Write
ability
EPROM
Mask-programmed ROM
EEPROM FLASH
NVRAM
SRAM/DRAM
Storage
permanence
Nonvolatile
In-system
programmable
Ideal memory
OTP ROM
During
fabrication
only
External
programmer,
1,000s
of cycles
External
programmer,
one time only
External
programmer
OR in-system,
1,000s
of cycles
In-system, fast
writes,
unlimited
cycles
Near
zero
Tens of
years
Life of
product
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 68. © DHBK 2010
68
3. Phần mềm hệ thống nhúng
• Các loại phần mềm nhúng
• Đặc điểm của phần mềm nhúng
• Hệ điều hành nhúng
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 69. © DHBK 2010
69
3. Phần mềm hệ thống nhúng
• Các loại phần mềm nhúng
• Đặc điểm của phần mềm nhúng
• Hệ điều hành nhúng
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 70. © DHBK 2010
70
Các loại phần mềm nhúng
RTOS Standard OS
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 71. © DHBK 2010
71
3. Phần mềm hệ thống nhúng
• Các loại phần mềm nhúng
• Đặc điểm của phần mềm nhúng
• Hệ điều hành nhúng
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 72. © DHBK 2010
72
•Written in high level programming languages:
• Typically in C but increasingly in Java or C++.
•The engineers that write embedded software are rarely
computer scientists
•Very stringent dependability requirements:
• human safety, consumer expectations, liability and government
regulation
•BMW recalled 15,000 7-series sedans in 2002 at an estimated
cost of $50 million.
•Very difficult to debug because of: concurrency, interrupts,
exceptions, process scheduling and hardware-in-the-loop.
Đặc điểm của phần mềm nhúng
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 73. © DHBK 2010
73
3. Phần mềm hệ thống nhúng
• Các loại phần mềm nhúng
• Đặc điểm của phần mềm nhúng
• Hệ điều hành nhúng
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 74. © DHBK 2010
74
Hệ điều hành nhúng
• Non RTOS
PalmOS: 68K Freescale, ARM9
Symbian: ARM
WindowsCE: x86, ARM, MIPS..
MAC OS X
• RTOS
VxWorks
QNX
TRON/iTRON
eCOS
• Linux
Linux is already ubiquitous
Hundreds of different devices are using it
Several variations-from „soft real time‟ to „hard real time‟
Numerous commercial + open source products: LynxOS, RTAI, Android
• Others
TinyOS CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 75. © DHBK 2010
75
The Embedded OS Market 2006
Hệ điều hành nhúng
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 76. © DHBK 2010
76
Lập trình cho PC và lập trình nhúng
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 77. © DHBK 2010
77
Lập trình cho PC và lập trình nhúng
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 78. © DHBK 2010
78
Lập trình cho PC và lập trình nhúng
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 79. © DHBK 2010
79
Lập trình cho PC và lập trình nhúng
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 80. © DHBK 2010
80
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)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 81. © DHBK 2010
81
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)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 82. © DHBK 2010
82
Mô tả hệ thống
Ý tưởng
Specification Phân chia HW/SW
Các phần tử phần cứng
Phần mềm
Estimation -
Exploration
Phần cứng
Phần mềm
Validation and Evaluation (area, power, performance, …)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 83. © DHBK 2010
83
• Các ngôn ngữ mô tả hệ thống
State Charts
SDL
Petri Nets
UML, MSC
VHDL, Verilog
SpecC, SystemC, SystemVerilog
Mô tả hệ thống
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 84. © DHBK 2010
84
Mô tả hệ thống
StateCharts: D. Harel, 1987
superstate
substates
FSM will be in exactly
one of the substates of
S if S is active
(either in A or in B or ..)
Hierarchy
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 85. © DHBK 2010
85
Mô tả hệ thống
SDL
• Specification and Description Language
Designed for specification of distributed systems.
• Defined by International Telecommunication Union
(ITU): Z.100 recommendation in 1980
• Provides textual and graphical formats.
• Like StateCharts, it is based on CFSM model of
computation; each FSM is called a process,
• It uses message passing for communications, and
supports operations on data.
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 86. © DHBK 2010
86
Mô tả hệ thống
FSMs/Processes in SDL
output
input
state
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 87. © DHBK 2010
87
Mô tả hệ thống
SDL
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 88. © DHBK 2010
88
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).
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 89. © DHBK 2010
89
Mô tả hệ thống
Petri Nets
Preconditions
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 90. © DHBK 2010
90
Mô tả hệ thống
UML (Unified Modeling Language)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 91. © DHBK 2010
91
Mô tả hệ thống
Verilog
• HW description language competing with VHDL
• Standardized:
IEEE 1364-1995 (Verilog version 1.0)
IEEE 1364-2001 (Verilog version 2.0)
• Less flexible than VHDL.
• More popular in the US (VHDL common in Europe)
module mux
(output f,
input a, b, sel);
and #5 g1 (f1, a, nsel),
g2 (f2, b, sel);
or #5 g3 (f, f1, f2);
not g4 (nsel, sel);
endmodule
a
b
f
sel
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 92. © DHBK 2010
92
Mô tả hệ thống
VHDL
• HDL = hardware description language
VHDL = VHSIC hardware description language
VHSIC = very high speed integrated circuit
• 1987: IEEE standard 1076; 1992 revision;
• Recently: VHDL-AMS models analog
entity full_adder is
port(a, b, carry_in: in Bit; -- input ports
sum,carry_out: out Bit); --output
ports
end full_adder;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 93. © DHBK 2010
93
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 94. © DHBK 2010
94
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.
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 95. © DHBK 2010
95
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)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 97. © DHBK 2010
97
Hardware/Software Co-design
[Niemann, Hardware/Software Co-Design for Data Flow Dominated Embedded Systems, Kluwer
Academic Publishers, 1998 (Comprehensive mathematical model)]
Processor
P1
Processor
P2 Hardware
Specification
Mapping
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 98. © DHBK 2010
98
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)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 99. © DHBK 2010
99
Lựa chọn phương án thiết kế
Traditional HW/SW Co-Design Flow
Design
Specification
HW/SW Partitioning
Off-Chip
Memory
Processor
Core
On-Chip
Memory
Synthesized
HW
Interface
HW
VHDL, Verilog
SW
C
Synthesis Compilation
Co-Simulation
Estimation
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 100. © DHBK 2010
100
Lựa chọn phương án thiết kế
ADL-Driven SOC Design Flow
Design
Specification
HW/SW Partitioning
HW
VHDL, Verilog
SW
C
Synthesis Compilation
Co-Simulation
Estimation ADL
Specification
P1
M1
P2
IP Library
On-Chip
Memory
Processor
Core
Synthesized
HW
Interface
Off-Chip
Memory
ADL: Architecture
Description Language
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 101. © DHBK 2010
101
Lựa chọn phương án thiết kế
ADL-driven Design Space Exploration
Memory
IP Library
Processor
IP Library
Co-processor
IP Library
Processor
Core
ADL Specification
Memory
Subsystem
Coprocessors
Verify
Failed
Obj
Application
Feedback
Success
Compiler Simulator
Obj
Application
Feedback
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 102. © DHBK 2010
102
Lựa chọn phương án thiết kế
Exploration Methodology
• Four steps
Architecture Specification
Use of Architecture Description Language (ADL)
Software Toolkit Generation
Compiler, simulator, assembler, debugger
Generation of Hardware Models (Prototypes)
Design space exploration
Find the best possible architecture for the given set of application
programs under area, power, performance constraints
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 103. © DHBK 2010
103
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 104. © DHBK 2010
104
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 105. © DHBK 2010
105
Phát triển hệ thống nhúng trên thế giới
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 106. © DHBK 2010
106
Phát triển hệ thống nhúng trên thế giới
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 107. © DHBK 2010
107
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 108. © DHBK 2010
108
Phát triển hệ thống nhúng trên thế giới
• Tỷ lệ doanh thu phần hệ nhúng trong toàn bộ sản
phẩm cuối cùng:
Telecommunications (37%)
Consumer Electronics and Intelligent Homes (41%)
Industrial Automation (22%)
Health/Medical Equipment (33%)
Automotive industry (40%)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 109. © DHBK 2010
109
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 110. © DHBK 2010
110
Phát triển hệ thống nhúng ở Việt Nam
• Video clip
• Fsoft
Outsource cho thị trường Nhật Bản và Mỹ: < 10% doanh thu từ phần
mềm
• Panasonic R&D Center in Vietnam
• Một số công ty khác: ETS, Applistar
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 111. © DHBK 2010
111
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 112. © DHBK 2010
112
Tình hình đào tạo hệ thống nhúng ở Việt Nam
• Đại học công nghệ-Đại học quốc gia Hà Nội
Lập trình phần mềm nhúng và thời gian thực
• ĐH Bách Khoa Hà Nội
Viện công nghệ thông tin và truyền thông
Thiết kế hệ nhúng
Hệ điều hành thời gian thực
Khoa Điện tử Viễn thông
Môn học:
Thiết kế hệ nhúng
Các hệ thống thời gian thực
Thiết kế hệ thống số với vi mạch khả trình
Khóa học ngắn hạn
Pclass (2 tuần)
Lab
Samsung Embedded Software
Embedded Systems and Reconfigurable Computing
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 113. © DHBK 2010
113
Tình hình đào tạo hệ thống nhúng ở Việt Nam
• Đại học Bách khoa Đà Nẵng
Chương trình tiên tiến Hệ thống nhúng (hợp tác với Porland
State University, Oregan, USA)
• Đại học Cần Thơ
Hệ thống nhúng
• Khoa Điện tử Viễn thông, ĐH KHTN- ĐH QGTPHCM
Khóa học ngắn hạn thiết kế hệ nhúng
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 114. © DHBK 2010
114
PHẦN 2:
THIẾT KẾ HỆ NHÚNG TRÊN
FPGA
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 115. © DHBK 2010
115
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 116. © DHBK 2010
116
1.1 Công nghệ IC khả trình
• Realisation as AND-OR:
F1=xy+xy‟z+x‟yz
• Realisation as OR-AND:
F1=((x‟+y‟) (x‟+y+z‟)
(x+y‟+z‟))‟
x y z
F1
x y z
F1
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 117. © DHBK 2010
117
1.1 Công nghệ IC khả trình
Programmable logic array
• PLA
And
plane
And
plane
Or
plane
Input
Output
Programmabl
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 118. © DHBK 2010
118
1.1 Công nghệ IC khả trình
Programmable logic array
• PLA
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 119. © DHBK 2010
119
1.1 Công nghệ IC khả trình
Programmable Array Logic
• PAL
And
plane
And
plane
Or
plane
Input
Output
Programmable
Fixed
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 120. © DHBK 2010
120
1.1 Công nghệ IC khả trình
Programmable Array Logic
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 121. © DHBK 2010
121
1.1 Công nghệ IC khả trình
Complex Programmable Logic Devices
• CPLD
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 122. © DHBK 2010
122
1.1 Công nghệ IC khả trình
Complex Programmable Logic Devices
• Các công nghệ lập trình
PROM: Lập trình 1 lần
EPROM, flash, EEPROM: lập trình nhiều lần
Non-volatile
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 123. © DHBK 2010
123
Ví dụ: PROM
4
2-to-4
Decoder
2
MSB
Address
2-to-4 Mux
2
LSB
Vcc Vcc Vcc Vcc
Data
Fuse
After manufacturing
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 124. © DHBK 2010
124
Ví dụ: PROM
4
2-to-4
Decoder
2
MSB
Address
2-to-4 Mux
2
LSB
Vcc Vcc Vcc Vcc
Data
After programming
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 125. © DHBK 2010
125
1.1 Công nghệ IC khả trình
Field-programmable Gate Array
• FPGA: XC40xx
CLB
CLB
CLB CLB
CLB
CLB
Long lines
SM SM SM SM
SM SM SM SM
SM SM SM SM
Routing via switching matrices
I/O I/O I/O
I/O
I/O
I/O
I/O
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 126. © DHBK 2010
126
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
LUT:
Bool-function
of 4
variables
16x1
LUT:
Bool-function
of 4
variables
FF
G
G
GQ
FF
F
F
FQ
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 127. © DHBK 2010
127
1.1 Công nghệ IC khả trình
Field-programmable Gate Array
• FPGA: Switching Matrix SM
Pass
TOR
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 128. © DHBK 2010
128
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 129. © DHBK 2010
129
1.1Công nghệ IC khả trình
Field-programmable Gate Array
• H 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/
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 130. © DHBK 2010
130
1.1 Công nghệ IC khả trình
Ưu điểm
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 131. © DHBK 2010
131
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 132. © DHBK 2010
132
Volume
Total cost
ASIC .13µ
FPGA .13µ
FPGA .09µ
ASIC .09µ
ASIC Design
Cost is much
higher
(and increasing)!!
For each technology advance,
crossover volume moves higher
1.1 FPGA vs. ASIC Cost
ASIC: High volumes needed to recover design cost
ASIC cost/part
is lower
Courtesy: Richard Sevcik, Xilinx
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 133. © DHBK 2010
133
1.2 Ứng dụng của công nghệ IC khả trình
• Aerospace & Defense
• Automotive
• Consumer
• Digital Video Technologies
• Industrial/Scientific & Medical
• Test & Measurement
• Wired Communications
• Wireless Communications
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 134. © DHBK 2010
134
1.2 Ứng dụng của công nghệ IC khả trình
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 135. © DHBK 2010
135
1.2 Ứng dụng của công nghệ IC khả trình
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 136. © DHBK 2010
136
1.2 Ứng dụng của công nghệ IC khả trình
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 137. © DHBK 2010
137
1.2 Ứng dụng của công nghệ IC khả trình
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 138. © DHBK 2010
138
1.2 Ứng dụng của công nghệ IC khả trình
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 139. © DHBK 2010
139
1.2 Ứng dụng của công nghệ IC khả trình
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 140. © DHBK 2010
140
1.2 Ứng dụng của công nghệ IC khả trình
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 141. © DHBK 2010
141
1.2 Ứng dụng của công nghệ IC khả trình
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 142. © DHBK 2010
142
1.2 Ứng dụng của công nghệ IC khả trình
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 143. © DHBK 2010
143
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 144. © DHBK 2010
144
2.1 Các họ PLD của Xilinx
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 145. © DHBK 2010
145
2.1 Các họ PLD của Xilinx
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 146. © DHBK 2010
146
2.1 Các họ PLD của Xilinx
A Decade of Progress
• 200x More Logic
Plus memory, µP
etc.
• 40x Faster
• 50x Lower Power
• 500x Lower Cost
CLB Capacity
Speed
Power per MHz
Price
Virtex &
Virtex-E
XC4000
100x
10x
1x
Spartan-2
1000x
Virtex-II &
Virtex-II Pro
Virtex-4
XC4000 &
Spartan
Spartan-3
'91 '92 '93 '94 '95 '96 '97 '98 '99 '00 '01 '02 '03 '04
Year
Courtesy: Richard Sevcik, Xilinx
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 147. © DHBK 2010
147
• Họ Virtex:
Virtex-5
2006, 1 V, 65 nm
550 MHz, low power
330,000 logic cells, DSP, PowerPC
1200 I/O pins
Virtex-4:
2004, 1.2 V, 90nm
500 MHz, low power
200.000 logic cells, DSP, PowerPC
Thay thế ASIC, ASSP
Virtex-II Pro /X
2002, 1.5 V, 130nm
400 MHz
3K to 99K logic cells + DSP, PowerPC
2.1 Các họ PLD của Xilinx
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 148. © DHBK 2010
148
• Họ Virtex:
Virtex-II
2001, 1.5 V, 150nm
300 MHz
3K to 99K logic cells
Virtex /E
1998/1999, 2.5 /1.8 V, 220 / 180 nm
150/ 200 MHz
3K to 70K logic cells
2.1 Các họ PLD của Xilinx
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 149. © DHBK 2010
149
• Họ Spartan:
Spartan-3A DSP/AN/A/E /L
2003, 1.5 V, 90nm
300 MHz
5M gates
2.1 Các họ PLD của Xilinx
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 150. © DHBK 2010
150
• CPLD- Họ Coolrunner
CoolRunner-II
1.8V, 180 nm
303 MHz
32-512 macrocells
Ultra Low power
CoolRunner-XPLA3
3.3 V
200 MHz
32-512 macrocells
Low power
2.1 Các họ PLD của Xilinx
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 151. © DHBK 2010
151
• CPLD- Họ XC9500
XC9500XV
2.5 V
250 MHz
36-288 macrocells
Low cost
XC9500XL
3.3 V
200 MHz
36-288 macrocells
Low cost
XC9500
5 V, 200 MHz
36-288 macrocells
Low cost
2.1 Các họ PLD của Xilinx
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 152. © DHBK 2010
152
2.2 Cấu trúc PLD của Xilinx
• All Xilinx FPGAs contain the same basic resources
Slices (grouped into CLBs)
Contain combinatorial logic and register resources
IOBs
Interface between the FPGA and the outside world
Programmable interconnect
Other resources
Memory
Multipliers
Global clock buffers
Boundary scan logic
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 153. © DHBK 2010
154
2.2 Cấu trúc PLD của Xilinx
Slices and CLBs
• Each Virtex -II CLB contains
four slices
Local routing provides
feedback between slices in
the same CLB, and it provides
routing to neighboring CLBs
A switch matrix provides
access to general routing
resources
CIN
Switch
Matrix
BUFT
BUF T
COUT
COUT
Slice S0
Slice S1
Local Routing
Slice S2
Slice S3
CIN
SHIFT
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 154. © DHBK 2010
155
Slice 0
LUT Carry
LUT Carry D Q
CE
PRE
CLR
D
Q
CE
PRE
CLR
2.2 Cấu trúc PLD của Xilinx
Simplified Slice Structure
• Each slice has four
outputs
Two registered outputs,
two non-registered outputs
Two BUFTs associated
with each CLB, accessible
by all 16 CLB outputs
• Carry logic runs vertically,
up only
Two independent
carry chains per CLB
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 155. © DHBK 2010
156
2.2 Cấu trúc PLD của Xilinx
Detailed Slice Structure
LUTs
MUXF5, MUXF6,
MUXF7, MUXF8
(only the F5 and
F6 MUX are shown
in this diagram)
Carry Logic
MULT_ANDs
Sequential Elements
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 156. © DHBK 2010
157
Combinatorial Logic
A
B
C
D
Z
2.2 Cấu trúc PLD của Xilinx
Look-Up Tables
• Combinatorial logic is stored in Look-Up
Tables (LUTs)
Also called Function Generators (FGs)
Capacity is limited by the number of inputs,
not by the complexity
• Delay through the LUT is constant
A B C D Z
0 0 0 0 0
0 0 0 1 0
0 0 1 0 0
0 0 1 1 1
0 1 0 0 1
0 1 0 1 1
. . .
1 1 0 0 0
1 1 0 1 0
1 1 1 0 0
1 1 1 1 1
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 157. © DHBK 2010
158
2.2 Cấu trúc PLD của Xilinx
Connecting Look-Up Tables
F5
F8
F5
F6
CLB
Slice S3
Slice S2
Slice S0
Slice S1
F5
F7
F5
F6
MUXF8 combines the two
MUXF7 outputs (from the CLB
above or below)
MUXF6 combines slices S2
and S3
MUXF7 combines the two
MUXF6 outputs
MUXF6 combines slices S0 and S1
MUXF5 combines LUTs in each slice
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 158. © DHBK 2010
159
D
CE
PRE
CLR
Q
FDCPE
D
CE
S
R
Q
FDRSE
D
CE
PRE
CLR
Q
LDCPE
G
_1
2.2 Cấu trúc PLD của Xilinx
Flexible Sequential Elements
• Either flip-flops or latches
• Two in each slice; eight in each CLB
• Inputs come from LUTs or from an
independent CLB input
• Separate set and reset controls
Can be synchronous or
asynchronous
• All controls are shared within a slice
Control signals can be inverted
locally within a slice
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 159. © DHBK 2010
160
2.2 Cấu trúc PLD của Xilinx
Shift Register LUT (SRL16CE)
• Dynamically addressable serial shift
registers
Maximum delay of 16 clock
cycles per LUT (128 per CLB)
Cascadable to other LUTs or
CLBs for longer shift registers
Dedicated connection from
Q15 to D input of the next
SRL16CE
Shift register length can
be changed asynchronously
by toggling address A
LUT
D Q
CE
D Q
CE
D Q
CE
D Q
CE
LUT
D
CE
CLK
A[3:0]
Q
Q15 (cascade out)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 160. © DHBK 2010
161
2.2 Cấu trúc PLD của Xilinx
IOB Element
• Input path
Two DDR registers
• Output path
Two DDR registers
Two 3-state enable
DDR registers
• Separate clocks and
clock enables for I and O
• Set and reset signals
are shared
Reg
Reg
DDR MUX
3-state
OCK1
OCK2
Reg
Reg
DDR MUX
Output
OCK1
OCK2
PAD
Reg
Reg
Input
ICK1
ICK2
IOB
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 161. © DHBK 2010
162
2.2 Cấu trúc PLD của Xilinx
SelectIO Standard
• Allows direct connections to external signals of varied
voltages and thresholds
Optimizes the speed/noise tradeoff
Saves having to place interface components onto your board
• Differential signaling standards
LVDS, BLVDS, ULVDS
LDT
LVPECL
• Single-ended I/O standards
LVTTL, LVCMOS (3.3V, 2.5V, 1.8V, and 1.5V)
PCI-X at 133 MHz, PCI (3.3V at 33 MHz and 66 MHz)
GTL, GTLP
and more!
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 162. © DHBK 2010
163
2.2 Cấu trúc PLD của Xilinx
Other Virtex-II Features
• Distributed RAM and block RAM
Distributed RAM uses the CLB resources (1 LUT = 16 RAM
bits)
Block RAM is a dedicated resources on the device (18-kb
blocks)
• Dedicated 18 x 18 multipliers next to block RAMs
• Clock management resources
Sixteen dedicated global clock multiplexers
Digital Clock Managers (DCMs)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 163. © DHBK 2010
164
2.2 Cấu trúc PLD của Xilinx
Distributed SelectRAM Resources
• Uses a LUT in a slice as
memory
• Synchronous write
• Asynchronous read
Accompanying flip-flops
can be used to create
synchronous read
• RAM and ROM are initialized
during
configuration
Data can be written to RAM
after configuration
• Emulated dual-port RAM
One read/write port
One read-only port
RAM16X1S
O
D
WE
WCLK
A0
A1
A2
A3
LUT
RAM32X1S
O
D
WE
WCLK
A0
A1
A2
A3
A4
RAM16X1D
SPO
D
WE
WCLK
A0
A1
A2
A3
DPRA0 DPO
DPRA1
DPRA2
DPRA3
Slice
LUT
LUT
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 164. © DHBK 2010
165
2.2 Cấu trúc PLD của Xilinx
Block SelectRAM Resources
• Up to 3.5 Mb of RAM in 18-kb
blocks
Synchronous read and write
• True dual-port memory
Each port has synchronous
read and write capability
Different clocks for each port
• Supports initial values
• Synchronous reset on output
latches
• Supports parity bits
One parity bit per eight data
bits
DIA
DIPA
ADDRA
WEA
ENA
SSRA
CLKA
DIB
DIPB
WEB
ADDRB
ENB
SSRB
DOA
CLKB
DOPA
DOPB
DOB
18-kb block SelectRAM memory
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 165. © DHBK 2010
166
2.2 Cấu trúc PLD của Xilinx
Dedicated Multiplier Blocks
• 18-bit twos complement signed operation
• Optimized to implement Multiply and Accumulate functions
• Multipliers are physically located next to block SelectRAM™ memory
18 x 18
Multiplier
Output
(36 bits)
Data_A
(18 bits)
Data_B
(18 bits)
4 x 4 signed
8 x 8 signed
12 x 12 signed
18 x 18 signed
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 166. © DHBK 2010
167
2.2 Cấu trúc PLD của Xilinx
Global Clock Routing Resources
• Sixteen dedicated global clock multiplexers
Eight on the top-center of the die, eight on the bottom-center
Driven by a clock input pad, a DCM, or local routing
• Global clock multiplexers provide the following:
Traditional clock buffer (BUFG) function
Global clock enable capability (BUFGCE)
Glitch-free switching between clock signals (BUFGMUX)
• Up to eight clock nets can be used in each clock
region of the device
Each device contains four or more clock regions
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 167. © DHBK 2010
168
2.2 Cấu trúc PLD của Xilinx
Digital Clock Manager (DCM)
• Up to twelve DCMs per device
Located on the top and bottom edges of the die
Driven by clock input pads
• DCMs provide the following:
Delay-Locked Loop (DLL)
Digital Frequency Synthesizer (DFS)
Digital Phase Shifter (DPS)
• Up to four outputs of each DCM can drive onto global
clock buffers
All DCM outputs can drive general routing
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 168. © DHBK 2010
169
2.3 Các bước thiết kế với PLD của Xilinx
CPLD/FPGA design flow
• Design Flow
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 169. © DHBK 2010
170
2.3 Các bước thiết kế với PLD của Xilinx
Design Entry
• Using schematic editor:
Works well with small designs: 5k to 10 k gates
Schematic can be compiled to HDL
• Using HDL (Hardware Description Language)
VHDL, Verilog
Others: Abel
Works with large design: > 100 k gates
• Using State Editor:
Mostly for controller
FSM can be compiled to HDL
• Higher level design language
System C: C based
Ocapi-xl: C and C++ based
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 170. © DHBK 2010
171
2.3 Các bước thiết kế với PLD của Xilinx
Design Entry
• 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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 171. © DHBK 2010
172
Schematic diagram: example
Language based
refinement:
VHDL editor
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 173. © DHBK 2010
174
2.3 Các bước thiết kế với PLD của Xilinx
Design Synthesis
• 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.
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 174. © DHBK 2010
175
2.3 Các bước thiết kế với PLD của Xilinx
Design Implementation
• 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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 175. © DHBK 2010
176
2.3 Các bước thiết kế với PLD của Xilinx
Xilinx device programming
• Create a bitstream to program the device
• Input: NCD file, Output: bit file
• Programming tools:
Download software + download cable
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 176. © DHBK 2010
177
2.3 Các bước thiết kế với PLD của Xilinx
Design verification
• Mô phỏng chức năng với behavioral simulation
• Mô phỏng về thời gian với timing simulation
• Kiểm tra phần cứng
• Verification tools:
ModelSim
ChipScope Pro
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 177. © DHBK 2010
178
2.4 Các họ PLD của Altera
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 178. © DHBK 2010
179
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 179. © DHBK 2010
180
2.4 Các họ PLD của Altera
• Họ Cyclone:
Cyclone II:
90 nm FPGA
Low power, low cost
Embedded memory, embedded multipliers
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 180. © DHBK 2010
181
2.4 Các họ PLD của Altera
• Họ Cyclone:
Cyclone:
2003, 0.13 um
Low power, low cost
Embedded memory
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 181. © DHBK 2010
182
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 182. © DHBK 2010
183
2.4 Các họ PLD của Altera
• Họ Stratix:
Stratix II:
90 nm
high performance, high density
Embedded memory, multipliers, DSP
blocks
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 183. © DHBK 2010
184
2.4 Các họ PLD của Altera
• Họ Stratix:
Stratix:
0.13-µm
high performance, high density
Embedded memory, multipliers, DSP blocks
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 184. © DHBK 2010
185
2.4 Các họ PLD của Altera
• Họ CPLD:
Max II:
Low cost, high performance
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 185. © DHBK 2010
186
2.5 Cấu trúc PLD của Altera
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 186. © DHBK 2010
187
2.5 Cấu trúc PLD của Altera
• Logic array block (LAB): 10 Logic elements(LE)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 187. © DHBK 2010
188
2.5 Cấu trúc PLD của Altera
• Logic element (LE)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 188. © DHBK 2010
189
2.5 Cấu trúc PLD của Altera
• Global clock and PLL
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 189. © DHBK 2010
190
2.5 Cấu trúc PLD của Altera
• IOE structure
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 190. © DHBK 2010
191
2.6 Các bước thiết kế với PLD của Altera
FPGA design flow
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 191. © DHBK 2010
192
2.6 Các bước thiết kế với PLD của Altera
CPLD design flow
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 192. © DHBK 2010
193
2.6 Các bước thiết kế với PLD của Altera
• Software tools
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 193. © DHBK 2010
194
Chương 3. Ngôn ngữ mô tả phần cứng VHDL
3.1 Giới thiệu về VHDL
3.2 Tín hiệu và các kiểu dữ liệu
3.3 Các phép toán số học và logic
3.4 Các lệnh song song và tuần tự
3.5 Các cấu trúc tuần tự
3.6 Chương trình con
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 194. © DHBK 2010
195
3.1 Giới thiệu về VHDL
• VHDL = VHSIC Hardware Description Language
• VHSIC = Very High Speed Integrated Circuit
• Là ngôn ngữ lập trình dùng để mô tả hoạt động của
hệ thống số
• Được quy định trong chuẩn IEEE 1076 từ năm 1983
• Các ngôn ngữ mô tả phần cứng khác:
Verilog
Abel
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 195. © DHBK 2010
196
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;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 196. © DHBK 2010
197
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
In1
In2
In3
Test
Out1
Out2
Compare
A
B
EQ
Compare
A
B
EQ
Test là một khối gồm 2 bản copy của khối compare
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 197. © DHBK 2010
198
A
B
EQ
Compare
3.1 Giới thiệu về VHDL
Ví dụ 1
A[0]
B[0]
A[1]
B[1]
A[7]
B[7]
EQ
XNOR
AND
Thiết kế khối compare dùng mạch tổ hợp
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 198. © DHBK 2010
199
4.1 Giới thiệu về VHDL
Ví dụ 1
• Thiết kế khối compare dùng VHDL
- -Eight bit comparator
entity Compare is
port(A,B: in bit_vector(0 to 7);
EQ: out bit);
end Compare;
architecture Behav1 of Compare is
begin
EQ <= „1‟ when (A=B) else „0‟;
end Behav1;
„Entity‟xác định giao diện
với bên ngoài của khối cần thiết kế
đầu vào và ra được gọi là port
„Architecture‟ miêu tả hoạt động
và cấu trúc bên trong 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)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 199. © DHBK 2010
200
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;
architecture Struct1 of Test is
component Comparator is
port(X,Y: in bit_vector(0 to 7);
Z: out bit);
end component;
begin
Compare1: Comparator port map (X=>In1, Y=>In2, Z=>Out1);
Compare2: Comparator port map (X=>In1,Y=>In3,Z=>Out2);
end Struct1;
2 bản copy của cùng một
component
„Comparator‟
Chú ý:
- Hai bản comparator chạy song song với nhau !!!
- Đây là architecture miêu tả cấu trúc của entity Test
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 200. © DHBK 2010
201
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‟?
-- Configuration information: architecture selection
-- and component-entity binding
configuration Build1 of Test is
for Struct1
for Compare1: Comparator use entity Compare(Behav1)
port map (A => X, B => Y, EQ => Z);
end for;
for others: Comparator use entity Compare(Behav1)
port map (A => X, B => Y, EQ => Z);
end for;
end for;
end Build1;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 201. © DHBK 2010
202
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:
architecture Architecture_name of Entity_name is
Khai báo các tín hiệu cục bộ;
Khai báo các components;
begin
Các câu lệnh;
end Architecture_name;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 202. © DHBK 2010
203
3.1 Giới thiệu về VHDL
Khai báo component
COMPONENT:
component Component_name is
port( Signal_name: in Signal_type;
Signal_name: out Signal_type);
end component;
Khai báo copy của COMPONENT :
Instance_name: Component_name
port map (Signal_list);
Hoặc cách thứ 2, copy trực tiếp:
Instance_name: Entity_name(Architecture_name)
port map (Signal_list);
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 203. © DHBK 2010
204
3.1 Giới thiệu về VHDL
Khai báo cấu hình
CONFIGURATION:
configuration Config_name of Entity_name is
for Architecture_name
for Instance_name: Component_name use entity
Entity_name(Architecture_name)
port map (Signal_list);
end for;
end for;
end Config_name;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 204. © DHBK 2010
205
3.1 Giới thiệu về VHDL
Ví dụ 2
• Biểu diễn cổng AND bằng VHDL
A
B
C
Y
-- 3-input AND gate
entity AND3 is
port ( A,B,C: in bit;
Y: out bit);
end AND3;
architecture RTL of AND3 is
begin
Y <= „1‟ when ((A=„1‟) and (B=„1‟) and (C=„1‟)) else „0‟;
end RTL;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 205. © DHBK 2010
206
3.1 Giới thiệu về VHDL
Ví dụ 2
• Biểu diễn cổng OR bằng VHDL
A
B
C
Y
-- 3-input OR gate
entity OR3 is
port ( A,B,C: in bit;
Y: out bit);
end OR3;
architecture RTL of OR3 is
begin
Y <= „0‟ when ((A=„0‟) and (B=„0‟) and (C=„0‟)) else „1‟;
end RTL;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 206. © DHBK 2010
207
3.1 Giới thiệu về VHDL
Ví dụ 2
• Biểu diễn cổng INV bằng VHDL
-- INV gate
entity INV is
port ( A: in bit;
Y: out bit);
end INV;
architecture RTL of INV is
begin
Y <= „1‟ when (A=„0‟) else „0‟;
end RTL;
A Y
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 207. © DHBK 2010
208
3.1 Giới thiệu về VHDL
Ví dụ 3
• Thiết kế bộ MUX 2-1 dùng VHDL
A
S
B
Y
entity MUX21 is
port ( A,B,S: in bit;
Y: out bit);
end MUX21;
architecture Behav of MUX21 is
begin
Y <= A when (S=„1‟) else B;
end Behav;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 208. © DHBK 2010
209
architecture Struct of MUX21 is
signal U,V,W : bit;
component AND2
port ( X,Y: in bit;
Z: out bit);
end component;
component OR2
port ( X,Y: in bit;
Z: out bit);
end component;
component INV
port ( X: in bit;
Z: out bit);
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);
end Struct;
3.1 Giới thiệu về VHDL
Ví dụ 3
A
S
B
Y
A
S
B
Y
U V
W
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 209. © DHBK 2010
210
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
configuration Use3InputGates of MUX21 is
for Behav
end for;
for Struct
for Gate1:INV use entity INV(RTL)
port map (A=>X,Y=>Z);
end for;
for All:AND2 use entity AND3(RTL)
port map (A=>X,B=>Y,C=>‟1‟,Y=>Z);
end for;
for Gate4:OR2 use entity OR3(RTL)
port map (A=>X,B=>Y,C=>‟0‟,Y=>Z);
end for;
end for;
end Use3InputGates;
Entities
A
B
C
Y
A Y
Components
X
Y
Z
X Z
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 210. © DHBK 2010
211
3.1 Giới thiệu về VHDL
Tạo Testbench
• Testbench là entity dùng để mô phỏng và kiểm tra
thiết kế
MUX21
A
B
Y
S
entity Testbench is
end Testbench;
Testbench không có port
architecture BehavTest of Testbench is
Signal In1,In2,Select,Out : bit;
begin
mux21_copy: entity MUX21(Behav) port map (In1, In2, Select, Out);
Thu: process is
begin
In1<=„0‟;In2<=„1‟;Select<=„0‟; wait for 20 ns;
Select<=„1‟; wait for 20 ns;
In1<=„1‟;In2<=„0‟; wait for 20 ns;
...
end process;
end BehavTest;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 211. © DHBK 2010
212
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 212. © DHBK 2010
213
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;
How to use a package?
use Library_name.Package_name.all;
…
U1: entity Package_name.Entity_name(Architecture_name);
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 213. © DHBK 2010
214
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;
Bit, Boolean và Character là kiểu dữ liệu liệt kê
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 214. © DHBK 2010
215
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
Ví dụ về khai báo các kiểu số nguyên:
type Year is range 0 to 99;
type Memory_address is range 65535 downto 0;
Ví dụ về khai báo các kiểu số thực
type Probability is range 0.0 to 1.0;
type Input_level is range -5.0 to 5.0;
Khai báo bit_vector, giá trị được đặt trong dấu nháy kép
constant State1: bit_vector(4 downto 0) := “00100”;
Kiểu chuỗi String là một chuỗi ký tự characters; giá trị của nó
được đặt trong dấu nháy kép
constant Error_message: string
:= “Unknown error: ask your poor sysop for help”;
MSB, bit 4 LSB
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 215. © DHBK 2010
216
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
ARCHITECTURE test OF test IS
BEGIN
PROCESS(X)
VARIABLE a : INTEGER;
BEGIN
a := 1; --Ok 1
a := -1; --Ok 2
a := 1.0; --error 3
END PROCESS;
END test;
ARCHITECTURE test OF test IS
SIGNAL a : REAL;
BEGIN
a <= 1.0; --Ok 1
a <= 1; --error 2
a <= -1.0E10; --Ok 3
a <= 1.5E-20; --Ok 4
a <= 5.3 ns; --error 5
END test;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 216. © DHBK 2010
217
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
Kiểu Time là kiểu vật lý:
type Time is range implementation_defined
units
fs;
ps = 1000 fs;
ns = 1000 ps;
us = 1000 ns;
ms = 1000 us;
sec = 1000 ms;
min = 60 sec;
hr = 60 min;
end units;
Primary unit:
resolution limit
Secondary units
Được sử dụng rất nhiều trong chạy mô phỏng
wait for 20 ns;
constant Sample_period: time := 2 ms;
constant Clock_period: time := 50 ns;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 217. © DHBK 2010
218
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
Người sử dụng có thể định nghĩa kiểu vật lý như sau:
type Length is range 0 to 1E9
units
um;
mm = 1000 um;
m = 1000 mm;
km = 1000 m;
mil = 254 um;
inch = 1000 mil;
foot = 12 inch;
yard = 3 foot;
end units;
Primary unit:
resolution limit
Metric secondary units
Imperial secondary units
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 218. © DHBK 2010
219
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:
type FSM_states is (reset, wait, input, calculate, output);
constant reset: bit_vector := “10000”;
constant wait: bit_vector := “01000”;
constant input: bit_vector := “00100”;
constant calculate: bit_vector := “00010”;
constant output: bit_vector := “00001”;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 219. © DHBK 2010
220
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;
END delay_calc;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 220. © DHBK 2010
221
4.2 Tín hiệu và các kiểu dữ liệu:
Kiểu mảng array
type 1D_array is array (1 to 10) of integer;
type 2D_array is array (5 downto 0, 1 to 10) of real;
TYPE data_bus IS ARRAY(0 TO 31) OF BIT;
VARIABLE X: data_bus;
VARIABLE Y: BIT;
Y := X(0);
Y := X(15);
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 221. © DHBK 2010
222
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
RECORD
opcode : optype;
src : INTEGER;
dst : INTEGER;
END RECORD;
PROCESS(X)
VARIABLE inst : instruction;
VARIABLE source, dest : INTEGER;
VARIABLE operator : optype;
BEGIN
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;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 222. © DHBK 2010
223
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 223. © DHBK 2010
224
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;
3.2 Tín hiệu và các kiểu dữ liệu:
Standard logic
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 224. © DHBK 2010
225
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;
3.2 Tín hiệu và các kiểu dữ liệu:
Standard logic
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 225. © DHBK 2010
226
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
signal Down: std_logic_vector (3 downto 0);
signal Up: std_logic_vector (0 to 3);
Up <= Down;
Phương án nào sau đây là phương án đúng?
Up(0)
Up(1)
Up(2)
Up(3)
Down(3)
Down(2)
Down(1)
Down(0)
OR
Up(0)
Up(1)
Up(2)
Up(3)
Down(0)
Down(1)
Down(2)
Down(3)
Tương ứng theo vị trí
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 226. © DHBK 2010
227
3.2 Tín hiệu và các kiểu dữ liệu:
Gán tín hiệu
• Có thể gán biến cho một phần của mảng
• Chú ý chiều (to hoặc downto) phải giống nhau trong
các phép khai báo
signal Bus: std_logic_vector (7 downto 0);
signal A: std_logic_vector (0 to 3);
Câu lệnh nào sau đây đúng?
Bus(0 to 3) <= A;
Bus <= A;
Bus(3 downto 0) <= A;
Bus(5 downto 4) <= A(0 to 1);
Chiều bus không giống như khai báo
Kích thứơc mảng khác nhau
OK! Bus(3) is driven by A(0)
OK! Bus(5) is driven by A(0)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 227. © DHBK 2010
228
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
signal Byte_bus: std_logic_vector(7 downto 0);
signal Nibble_busA, Nibble_busB: std_logic_vector(3 downto 0);
Byte_bus <= Nibble_busA & Nibble_busB;
Byte_bus(7)
Byte_bus(6)
Byte_bus(5)
Byte_bus(4)
Byte_bus(3)
Byte_bus(2)
Byte_bus(1)
Byte_bus(0)
Nibble_busA(3)
Nibble_busA(2)
Nibble_busA(1)
Nibble_busA(0)
Nibble_busB(3)
Nibble_busB(2)
Nibble_busB(1)
Nibble_busB(0)
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 228. © DHBK 2010
229
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!!
signal X,Y,Z,T: std_logic_vector(3 downto 0);
signal A,B,C: std_logic;
X <= (A,B,C,C); -- correspondence by position
Y <= (3 => A, 1 downto 0 => C, 2 => B);
Z <= (3 => A, 2 => B, others => C);
T <= (others => „0‟); -- initialization irrespective of width of T
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 229. © DHBK 2010
230
3.2 Tín hiệu và các kiểu dữ liệu:
Tham số dùng chung (Generic)
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;
•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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 230. © DHBK 2010
231
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;
ARCHITECTURE test_arch OF test IS
COMPONENT AND2
GENERIC(rise, fall : TIME; load : INTEGER);
PORT ( a, b : IN std_logic;
c : OUT std_logic);
END COMPONENT;
BEGIN
U1: AND2 GENERIC MAP(10 ns, 12 ns, 3 )
PORT MAP (ina, inb, out1 );
U2: AND2 GENERIC MAP(9 ns, 11 ns, 5 )
PORT MAP (inc, ind, out2 );
END test_arch;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 231. © DHBK 2010
232
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;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 232. © DHBK 2010
233
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);
4 thuộc tính (attributes) được định nghĩa sẵn
_ T‟LEFT, which returns the left bound of a type or subtype
_ T‟RIGHT, which returns the right bound of a type or subtype
_ T‟HIGH, which returns the upper bound of a type or subtype
_ T‟LOW, which returns the lower bound of a type or subtype
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;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 233. © DHBK 2010
234
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 234. © DHBK 2010
235
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í
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 235. © DHBK 2010
236
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;
architecture Logical of Gate is
begin
Z <= A and not(B or C);
end Logical;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 236. © DHBK 2010
237
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;
architecture Logical of Gate is
begin
Z <= A and not(B or C);
end Logical;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 237. © DHBK 2010
238
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 238. © DHBK 2010
239
Các phép toán so sánh
library IEEE
use IEEE.Std_Logic_1164.All;
entity Compare is
port( A: in std_logic_vector(3 downto 0);
B: in std_logic_vector(0 to 4);
Z: out boolean);
end Compare;
architecture Relational of Compare is
begin
Z <= TRUE when A<B else FALSE;
end Relational;
entity Testbench
end entity Testbench;
architecture Build1 of Testbench is
signal A: std_logic_vector(3 downto 0) := “1110”;
signal B: std_logic_vector(0 to 4) := “10111”;
signal Z: boolean;
begin
DUT: entity Compare(Relational)
port map (A => A, B => B, Z => Z);
end Build1;
What is the
value of Z?
TRUE?
FALSE?
1110
is compared to
1011
by bit position
from left to
right;
in the 2nd
position
A(2) > B(1)
hence (A<B)
is FALSE
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 239. © DHBK 2010
240
3.3 Các phép toán số học và logic:
Các phép toán số học
• Các phép toán số học gồm: +, -, *, /, ** (exponential),
abs (absolute value), mod (modulus), rem (remainder)
• Các phép toán này dùng cho kiểu số nguyên và số
thực (trừ mod and rem không dùng cho số thực),
không dùng cho kiểu bit vector
• Cả hai toán hạng phải có cùng kiểu dữ liệu và có thể
có dải giá trị khác nhau
• Một biến kiểu vật lý (ví dụ: time) có thể nhân với một
số nguyên và một số thực, kết quả sẽ vẫn là kiểu vật
lý
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 240. © DHBK 2010
241
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;
architecture Behav of Add is
begin
Z <= A + B;
end Behav;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 241. © DHBK 2010
242
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;
Y,Z: out std_logic);
end Concurrent;
architecture Struct of Concurrent is
begin
NAND1: entity NAND2 port map (A,B,Y);
NAND2: entity NAND2 port map (C,D,Z);
end Struct;
A
B
C
D
Y
Z
Schematic:
Mạch sẽ hoạt động thế nào nếu như khai báo NAND1 sau NAND2?
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 242. © DHBK 2010
243
entity Concurrent is
port ( A,B,C,D: in std_logic;
Y,Z: out std_logic);
end Concurrent;
architecture Struct of Concurrent is
begin
NAND2: entity NAND2 port map (C,D,Z);
NAND1: entity NAND2 port map (A,B,Y);
end Struct;
A
B
C
D
Y
Z
Schematic:
Mạch vần hoạt động như cũ!!!
3.4 Các lệnh song song và tuần tự :
Các lệnh song song
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 243. © DHBK 2010
244
3.4 Các lệnh song song và tuần tự :
Các lệnh song song
A
B
D
Z
Schematic:
T1
entity Concurrent is
port ( A,B, D: in std_logic;
Z: out std_logic);
end Concurrent;
architecture Struct of Concurrent is
signal T1: std_logic;
begin
NAND2: entity NAND2 port map (T1,D,Z);
NAND1: entity NAND2 port map (A,B,T1);
end Struct;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 244. © DHBK 2010
245
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ụ:
entity Complex is
port( A,B,C,D,E,F,G,H,I,J:
in std_logic;
Y,Z: out std_logic);
end Complex;
architecture Struct of Complex is
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;
A
B
C
D
E
F
G
H
S
Y
I
J
Z
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 245. © DHBK 2010
246
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).
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 246. © DHBK 2010
247
3.4 Các lệnh song song và tuần tự :
Process
Cú pháp khai báo Process:
Process_name: process (sensitivity_list) is
-- variable declarations;
begin
-- sequential commands
end process;
Cú pháp khai báo biến:
variable Variable_name: type;
Cú pháp gán giá cho một biến:
Variable_name := expression;
Gán biến :=
Gán tín hiệu <=
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 247. © DHBK 2010
248
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:
in std_logic;
Y,Z: out std_logic);
end Complex;
architecture Struct of Complex is
begin
Y_process: process (A,B,C,D,E,F,G,H,S) is
variable T1,T2: std_logic;
begin
if (S=„1‟) then
T1 := A nand B;
T2 := C nand D;
else
T1 := E nand F;
T2 := G nand H;
end if;
Y <= T1 nand T2;
end process;
Z <= I nand J;
end Struct;
A
B
C
D
E
F
G
H
S
Y
I
J
Z
T1 and T2 have no
physical meaning since
each refers to 2 different
physical wires
T1 T2
Sensitivity list
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 248. © DHBK 2010
249
• Xét ví dụ sau:
Example: process (A,B,M) is
begin
Y <= A;
M <= B;
Z <= M;
end process;
1. Giả thiết B có giá trị mới B‟
2. Process Example được thực hiện. Các tín hiệu ra được ghi nhớ:
Y‟ <= A; M‟ <= B‟; Z‟ <= M;
Giá trị M cũ !!! M chỉ nhận
giá trị mới ở cuối process
3. Process Example tạm dừng
Y, M và Z nhận các giá trị mới Y‟, M‟, Z‟.
4. Vì M ở trong sensitivity list, process Example lại đựơc thực hiện
5. Process Example thực hiện: Y” <= A; M” <= B‟; Z” <= M‟;
6. Y, M and Z nhận giá trị mới Y”, M”, Z”.
7. Không có tín hiệu nào trong sensitivity list thay đổi, process dừng
3.4 Các lệnh song song và tuần tự :
Process
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 249. © DHBK 2010
250
3.5 Các cấu trúc tuần tự
• Các cấu trúc tuần tự chỉ được sử dụng trong process
và chương trình con!!!
• Các cấu trúc tuần tự bao gồm: IF, CASE, FOR, NEXT,
EXIT, WAIT, ASSERT
IF statement:
if condition then
-- sequential statements
else
-- sequential statements
end if;
multiple IF statements:
if condition1 then
-- sequential statements
elsif condition2 then
-- sequential statements
elsif condition3 then
-- sequential statements
else
-- sequential statements
end if;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 250. © DHBK 2010
251
3.5 Các cấu trúc tuần tự
case Expression is
when Value_1 =>
-- sequential statements
when Value_2 =>
-- sequential statements
-- etc.
end case;
Example: process (A,B,C,X) is
begin
case X is
when 0 to 4 =>
Z <= B;
when 5 =>
Z <= C;
when 7 | 9 =>
Z <= A;
when others =>
Z <= „0‟;
end case;
end process;
Yêu cầu:
1. Tất cả các trường hợp
phải đựơc xác định
2. Giá trị value phải là hằng số
và phải biết khi thiết kế
3. Giá trị phải có cùng kiểu với
expression
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 251. © DHBK 2010
252
3.5 Các cấu trúc tuần tự
TYPE vectype IS ARRAY(0 TO 1) OF BIT;
VARIABLE bit_vec : vectype;
CASE bit_vec IS
WHEN “00” =>
RETURN 0;
WHEN “01” =>
RETURN 1;
WHEN “10” =>
RETURN 2;
WHEN “11” =>
RETURN 3;
END CASE;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 252. © DHBK 2010
253
3.5 Các cấu trúc tuần tự
for I in 0 to 3 loop
-- sequential statements
end loop;
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 đó
Chú ý:
FOR i IN 1 to 10 LOOP
i_squared(i) := i * i;
END LOOP;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 253. © DHBK 2010
254
3.5 Các cấu trúc tuần tự
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;
architecture Behav of General_mux is
begin
Selector: process (Input, Select) is
begin
for I in 0 to width-1 loop
if Select=I then
Output <= Input(I);
end if;
end loop;
end process;
end Behav;
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 254. © DHBK 2010
255
3.5 Các cấu trúc tuần tự
PROCESS(A, B)
CONSTANT max_limit : INTEGER := 255;
BEGIN
FOR i IN 0 TO max_limit LOOP
IF (done(i) = TRUE) THEN
NEXT;
ELSE
done(i) := TRUE;
END IF;
q(i) <= a(i) AND b(i);
END LOOP;
END PROCESS;
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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- 255. © DHBK 2010
256
3.5 Các cấu trúc tuần tự
Cấu trúc EXIT được dùng để thoát ra khỏi vòng lặp for
PROCESS(a)
variable int_a : integer;
BEGIN
int_a := a;
FOR i IN 0 TO max_limit LOOP
IF (int_a <= 0) THEN -- less than or
EXIT; -- equal to
ELSE
int_a := int_a -1;
q(i) <= 3.1416 / REAL(int_a * i); -- signal
END IF; -- assign
END LOOP;
y <= q;
END PROCESS;
CuuDuongThanCong.com https://fb.com/tailieudientucntt