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