數位系統導論

Download Report

Transcript 數位系統導論

數位邏輯設計
VHDL
大綱



2
VHDL Overviews
VHDL 基本架構
訊號定義
Sheau-Huey Chen
2020/4/26
VHDL
Overviews
What is VHDL?


4
VHDL:Very High Speed Integrated Circuit
Hardware Description Language
一種硬體描述的語言,用來描述你構想的硬
體設計
Sheau-Huey Chen
2020/4/26
VHDL歷史背景



5
1983年,美國國防部為了開發高速戰機中的
積體電路而制定的體體描述語言。
1987年由 IEEE國際組織正式制定成 IEEE
1076標準,又稱VHDL’87。
1993年再次更新,成為IEEE 1164標準,又
稱VHDL’93。
Sheau-Huey Chen
2020/4/26
VHDL
基本架構
VHDL基本設計觀念

VHDL程式可分成兩部分:
1. entity:描述電路外觀(宣告外部接腳)
2. architecture:描述內部特性
architecture OR2_ARCH1 of OR2 is
entity OR2 is
port (A,B: in STD_LOGIC ;
Y:out STD_LOGIC);
end OR2;
begin
Y <= A or B;
end OR2_ARCH1;
A
7
Y
B
Sheau-Huey Chen
A
B
Y
2020/4/26
VHDL基本設計
-- 註解說明
 ;指令結束
 library xxx; 宣告定義庫
use xxx.yyy;的預設定義
 程式中的大小寫是一樣
 <= 將右邊訊號傳給左邊
 可以讓關鍵字用小寫,變數和參數用大寫,
這樣程式看起來比較清楚

8
Sheau-Huey Chen
2020/4/26
Example1
--The IEEE standard 1164 package
library IEEE;
註
解
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
固定標頭,照抄就好
use IEEE.std_logic_unsigned.all;
entity OR2 is
port (A,B: in STD_LOGIC;
entity 定義接腳
Y:out STD_LOGIC);
end OR2;
architecture OR2_ARCH1 of OR2 is
begin
architecture 描述內
容
Y <= A or B;
9
end OR2_ARCH1;
Sheau-Huey Chen
2020/4/26
entity
entity ENTITY_NAME is
port (
A,B: in STD_LOGIC;
Y: out STD_LOGIC );
end ENTITY_NAME;
這裡別寫錯囉~
A
ENTITY
_NAME
B
Y
PORT_NAME: port_mode PORT_TYPE
10
Sheau-Huey Chen
2020/4/26
entity
PORT_NAME: port_mode PORT_TYPE



11
PORT_NAME:自己命名,但不可和其他變
數重複
port_mode:in、out、inout
PORT_TYPE:BIT、STD_LOGIC、
BIT_VECTOR、STD_LOGIC_VECTOR、
UNSIGNED…etc.
Sheau-Huey Chen
2020/4/26
architecture
architecture ARCHI_NAME of ENTITY_NAME is
begin
A
Y <= A or B
Y
B
end ARCHI_NAME;
12
Sheau-Huey Chen
2020/4/26
architecture
signal
signal指令是宣告電路內部自行使用的訊號
 沒有傳送到外部,也不能在entity中的port上
宣告
S0
A
 不需要寫in、out、inout
B
Example:
C
signal S0:STD_LOGIC;
SI
signal S1:STD_LOGIC;

13
Sheau-Huey Chen
Y
2020/4/26
VHDL
訊號定義
訊號定義
邏輯訊號
BIT
0,1
 STD_LOGIC
‘X’ -- 浮接不定
‘0‘ -- 低位
‘1’ -- 高位
‘Z’ -- 高阻抗
‘w’ --弱浮接
‘L’ --弱低位
‘H’ --弱高位
‘-’ --don’t care

15
Sheau-Huey Chen
2020/4/26
訊號定義
邏輯訊號
 BIT_VECTOR與STD_LOGIC_VECTOR
Example:
signal A:STD_LOGIC_VECTOR(3 downto 0);
signal B:STD_LOGIC_VECTOR(0
to 3);
B <= A;
A3
 邏輯常數
A2
‘0’、 ‘1’、”10” 訊號合併
A1
A0
Example:
CLK
B <= ‘0’&’1’&”10”
16
Sheau-Huey Chen
B0
B1
B2
B3
2020/4/26
訊號定義
數值訊號
 INTEGER:可做數值運算,不能做邏輯處理
Example:
signal C:INTERGER;
 UNSIGNED:可做數值運算,也可以做邏輯處理
Example:
signal D:UNSIGNED(3 downto 0);
17
Sheau-Huey Chen
2020/4/26
訊號定義


18
邏輯處理
邏輯運算: not, and, or, nand, xor, xnor
比較運算: =, /=, <, <=, >, >=
數值運算
數值運算:sign +, sign -, abs, +, -, *
比較運算: =, /=, <, <=, >, >=
Sheau-Huey Chen
2020/4/26
VHDL
基本邏輯閘
AND 使用方法
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
entity AND_arch is
port(
a, b: in STD_LOGIC;
Y :out STD_LOGIC);
end AND_arch;
a
b
Y
architecture dataflow of AND_arch is
begin
Y <=a and b;
end dataflow;
20
Sheau-Huey Chen
2020/4/26
OR 使用方法
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
entity OR_arch is
port(
a, b: in STD_LOGIC;
Y :out STD_LOGIC);
end OR_arch;
a
b
Y
architecture dataflow of OR_arch is
begin
Y <=a or b;
end dataflow;
21
Sheau-Huey Chen
2020/4/26
NOT 使用方法
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
entity NOT_arch is
port(
a: in STD_LOGIC;
Y :out STD_LOGIC);
end NOT_arch;
a
Y
architecture dataflow of NOT_arch is
begin
Y <= not a;
end dataflow;
22
Sheau-Huey Chen
2020/4/26
XOR 使用方法
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
entity XOR_arch is
port(
a, b: in STD_LOGIC;
Y :out STD_LOGIC);
end XOR_arch;
a
b
Y
architecture dataflow of XOR_arch is
begin
Y <= a xor b;
end dataflow;
23
Sheau-Huey Chen
2020/4/26
Modeling



24
Dataflow – Concurrent: gate level
表示方法
Structure – Concurrent: 使用hierarchical
架構來描述內部的components
Behavioral – Sequential: algorithm level
表示方法
Sheau-Huey Chen
2020/4/26
Architecture / Dataflow Model
Dataflow Modeling by
boolean equations assignments
conditional assignments (When-Else, With-Select-When)
n2
b
sell
a
x
n1
n3
Architecture dataflow_modeling of example is
signal n1, n2, n3 : std_logic; --宣告內部訊號
begin
x <= n2 OR n3;
n2 <= b AND sell;
n3 <= n1 AND a;
n1 <= NOT sell;
-- x <= (a AND (NOT sel1)) OR (b AND sel1);
end example;
Structure

26
Concurrent:
使用hierarchical架構來描述內部的
components
Sheau-Huey Chen
2020/4/26
Architecture / Structural Model
Instantiation Statement
Structural Modeling
Architecture structural_modeling of one_bit_half_adder is
begin
X1: XOR2 Port Map ( Z0 => sum, A0 => a, A1 => b );
A1: AND2 Port Map ( Z0 => cout, A0 => a, A1 => b );
-- A1: AND2 Port Map (
cout,
a,
b );
end structural_modeling;
Library Symbol: AND2
A0
Z0
A1
a
b
sum
X1
A0
A1
A1
Z0
cout
Entity AND2 is Port (
Z0 : out std_logic;
A0 : in std_logic;
A1 : in std_logic );
END AND2;
Behavioral

28
Sequential: algorithm level 表示方法
Sheau-Huey Chen
2020/4/26
Architecture / Behavioral Model





Process Statement
Behavioral Modeling
用來描述 sequential events 的 process
是包含在 ARCHITECTURE 裡面的
ARCHITECTURE 可以包含數個 PROCESS statements.
PROCESS statements 有 3個 parts:
– Sensitivity list :


–
PROCESS :

–
包含 PROCESS的內部訊號(signal)
當內部訊號在sensitivity list改變其值的時候,process是正在進
行的
用來描述behavior
BEGIN - END PROCESS statement:

描述PROCESS 的 beginning & ending
Architecture / Behavioral Model
Simple example of PROCESS
a
mux: PROCESS (a, b, s) -- the sensitivity list
b
BEGIN
s
if ( s = ‘0’ ) then
x <= a;
else
-- define the process section
x <= b;
end if;
END PROCESS mux;
x
Here the process ‘mux’ is sensitive to signals ‘a’,‘b’ and ‘s’.
Whenever signal ‘a’ or ‘b’ or ‘s’ changes value, the statements
inside the process will be evaluated
軟體安裝

31
請自行下載安裝
Sheau-Huey Chen
2020/4/26
Example



32
安裝
Next->Next->Next->Next->Finish
開啟
Direct VHDL->DirectVHDL PE
使用
File->New (請先打檔名)
Sheau-Huey Chen
2020/4/26
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
entity CH1 is
port
(XC0:in STD_LOGIC;
XA0:out STD_LOGIC );
end CH1;
architecture CH1_AR of CH1 is
begin
XA0<=XC0;
end CH1_AR;
Simulate
按 Simulate
按完之後,會出現一個視窗,請看下方視窗。
34
Sheau-Huey Chen
2020/4/26
Input
force XC0 0,1 100 -repeat 200(請按Enter)
run 800(請按Enter)
35
Sheau-Huey Chen
2020/4/26
Wave Form
檢視waveform report
Debug->Waveform Report
★這題練習是把XC0的訊號傳給XA0,
所看到的Waveform Report的
XC0與XA0應該要是一樣的。
36
Sheau-Huey Chen
2020/4/26
練習: 2 Bits Input Half Adder
inA
ai
addR
inB
in
C
ci
bi
37
Sheau-Huey Chen
car
R
2020/4/26
2 Bits Input Half Adder
Library 自己設
entity halfadder3bit is
port (inA, inB ,inC : IN BIT;
addR, carR : OUT BIT);
end helfadder3bit;
-- 2 bits input halfadder
-- result addR and carry bit carR
ARCHITECTURE dataflow_HA3b of helfadder3bit is
signal ai, bi, ci : bit;
BEGIN
ai <= (inA XOR inB);
addR <= (ai XOR inC);
bi <= (inA AND inB);
ci <= (ai AND inC);
carR <= (bi OR ci);
END dataflow_HA3b;
Simulate
按 Simulate
按完之後,會出現一個視窗
39
Sheau-Huey Chen
2020/4/26
force 的使用方式
force [inB 輸入_名稱]
[0,1 表示先零後一]
[100 表示開始定義的時間點]
[-repeat 表示要重複值] [表示改變值的時間點]
41
Sheau-Huey Chen
2020/4/26
Waveform Report
從Debug選項當中可以由 Waveform Report 對照每個輸入及結果
42
Sheau-Huey Chen
2020/4/26
檢視 Waveform report
43
Sheau-Huey Chen
2020/4/26
4-Bits Adder
44
Sheau-Huey Chen
2020/4/26
Half Adder
45
Sheau-Huey Chen
2020/4/26
Full Adder
46
Sheau-Huey Chen
2020/4/26
Full Adder
47
Sheau-Huey Chen
2020/4/26
4-Bits Adder
48
Sheau-Huey Chen
2020/4/26
4-Bits Adder
49
Sheau-Huey Chen
2020/4/26