1 / 130

VHDL

VHDL. Introduction. 數位電路的設計方法,在早期由於電路比較簡單,且電路合成的工具較不完整,早期都是使用 gate-level 的方式用圖形介面 , 就所需之邏輯閘 、 正反器一個個畫在電路圖上 。 需要花相當的時間設計的輸入 由於邏輯閘相當多 , 會增加出錯機會即將來維護上的困難 。 V ery High Speed ICs H ardware D escription L anguage ( VHDL ). VHDL 程式基本架構. Library / Package 宣告區. Entity 宣告區. Generic 定義

bracha
Télécharger la présentation

VHDL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VHDL

  2. Introduction • 數位電路的設計方法,在早期由於電路比較簡單,且電路合成的工具較不完整,早期都是使用gate-level的方式用圖形介面,就所需之邏輯閘、正反器一個個畫在電路圖上。 • 需要花相當的時間設計的輸入 • 由於邏輯閘相當多,會增加出錯機會即將來維護上的困難。 • Very High Speed ICs Hardware Description Language (VHDL)

  3. VHDL程式基本架構

  4. Library/ Package 宣告區 Entity宣告區 Generic 定義 Port 定義 Architecture 描述區 BEGIN Component宣告 Signal宣告 Description statements VHDL程式基本架構

  5. VHDL程式基本架構 • VHDL模型檔(****.vhd) -- VHDL Design Unit 檔案說明 LIBRARY ieee; USE ieee.std_logic_1164.all; ENTITY e-name IS --port declaration PORT ( P-name: mode type; ); END ENTITY e-name;

  6. VHDL程式基本架構 ARCHITECTURE a-name OF e-name IS --component declration COMPONENT ….. END COMPONENT.. ; --signal declaration SIGNAL s-name: type; BEGIN --Concurrent statements; (設計內容) END ARCHITECTURE a-name;

  7. VHDL程式範例 library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity IC7400 is Port ( a1,a2,b1,b2,c1,c2,d1,d2 : in std_logic; ao : out std_logic; bo : out std_logic; co : out std_logic; do : out std_logic); end IC7400; architecture a of IC7400 is begin ao <= not (a1 and a2); bo <= not (b1 and b2); co <= not (c1 and c2); do <= not (d1 and d2); end a;

  8. Library … 宣告物件所存放之地方 1、LIBRARY • 宣告user引用之物件所存放之地方 (library) …… IEEE 。一般, Simulator會對Library事先建立一個”對照表” , 存於 **.ini 檔中 。此”對照表” 包括已事先設定(預設)之library及 其對映到磁 牒中之實際位置

  9. USE … 開啟 library中之package 2、USE 。開啟library中之package,以便使用宣告與定義過 的物件 。Package 用來宣告、定義一些VHDL中 可使用的物件 (Objects) 。物件包括:TYPE,Sub-program(Function, Procedure), CONSTANT, Deferred constant等 【語法】: USELib-name .package-name.all;.

  10. USE ------- • Compile時, 物件引用之package順序 (1) 預設之library package (2) 宣告之library package。 • Library與Use宣告之效力僅及於該Design unit (Entity)

  11. ENTITY … 設計單元 (DESIGN unit) 定義 • 設計(DESIGN)定義 : Design- unit name 與 external介面 (ports) ……… 相當於元件外型(name & pins)

  12. 註解 (Comment) • hyphen ’--‘ 開頭,直到 Carriage-return 為止。 善用註解: 。VHDL design 檔最好加上適當之header; 註明: design unit, file name, function, modules Called, limitation, author , revision number and date。 [範例]: -- Design unit : y_func -- File name : y_func.vhd -- Function : Y(a,b,c)=Σ(1,3,6,7)=(not A and C) or (A and B) -- limitation : No -- Author : MS-Shiau -- Department of Electronics ,Feng-Chia University -- Revision : V.1 12/31/2001

  13. PORT (埠) • 相當於 …….. IC: pins , system : external interface signals [語法]: PORT( p1-name : modetype ; p2-name : modetype ; … pN-name : modetype );

  14. Oen INOUT Ien IN OUT BUFFER PORT ---- mode • IN , OUT , INOUT , BUFFER IN :只可由單體外之信號驅動 OUT :可multi-driven , 不可 feed-in (不可驅動單體內之信號). BUFFER: (與OUT似,但可feed-in內驅; 因不可多驅,一般較少用) INOUT:全部PORTs均如此宣告會使程式可讀性降低

  15. Architecture 1、ARCHITECTURE 。 Design-unit設計內容: 功能描述 【語法】: ARCHITECTURE a-name OF e-name IS SIGNAL s-name: type ; ----- declaration BEGIN Concurrent Statements (功能描述) ; END Architecture a-name ;

  16. 描述風格(Description styles) 1、典型的描述風格(Description styles) (1)Structural : 元件及其連接情形;Netlist 方式 (包括:Component.VHDL檔 , 及Design-unit中 Component 宣告, Component 啟動instantiation) (2)Behavior : Process 方式, Function or Procedure方式 (包括: Sequential (timing順序安排) statements) (3)Data-flow : Boolean 方式之concurrent signal assignments (信號data處理,傳輸,方向。並時性, 以Boolean函式指定信號值)

  17. Description styles運用

  18. DATA TYPE

  19. 資料物件 • VHDL中的物件使用前須事先宣告其「類別」與「資料型態」 【語法】: 類別 資料物件名稱 : 資料型態 := 初始值 ; • 初始值 (Initial value): All signals have an initial value when simulation begins. 。User defined : in the declaration (Ex :=‘0’ ) 。Default :the 1’st (left) value that appeared in type declaration ※Initial value assignment is ignored in H/W synthesis. 。Way for synthesis: Global (Power-on ) reset

  20. 物件類別 類別(Class): (1)port, Signal: 。Circuit-connection (Wire名稱or正反器狀態) 。Driver is scheduled by queue: ie. Means they have time-delay) (2)Constant : 。代表一個固定值的identifier; 增加可讀性與可維護性. 。不可於程式執行中更改其值。 (3)Variable: 。只限於process or副程式中使用. 。不代表實際wire or 狀態, Local-storage operation 。其值於程式執行中可更改。 (Updated immediately, no delay) (4)檔案(File): 代表工作環境中之檔案,可有效地協助電路模擬之執行。

  21. 型態 語法: TYPE型態名稱 IS ……………………… • 機定(Default): 在Standard package 與IEEE package中已預先定義者。 • 自訂(User): 在User package中 or VHDL design unit中的Architecture與Begin間宣告者。

  22. 典型標準之Types定義( STANDARD ) • Package STANDARD Type Booleanis (false,true); Type Bitis (‘0’,’1’); Type Characteris ( ‘A’,..,‘0’,…等 ); Type severity_levelis (note, warning, error, fail); Type integerisrange -2147483648 to 2147483647; Type realisrange -1.7014110e+38 to 1.7014110e+38; Type timeis range-9223372036854775807to 9223372036854775807 Units fs; Ps = 1000 fs; ns = 1000 ps; us = 1000 ns; ms = 1000 us; sec = 1000 ms; min = 60 s; hr = 60 min; End units; Subtypenaturalis integer range0 to integer’high; SubtypePositiveis integer range 1 to integer’high; Typestringis array (positive range<>) of character; Typebit_vectoris array (natural range<>) of bit; Function now return time;

  23. 典型標準之Types定義 ( std_logic_1164 ) • Typestd_ulogic is (‘U’,’X’, ‘0’,’1’, ‘Z’,’W’, ‘L’,’H’,’-’ ); Function resolved (s: std_ulogic_vector) return std_ulogic; Subtypestd_logic is resolved std_ulogic; • Type std_ulogic_vector is array (natural range <>)of std_ulogic; Type std_logic_vector is array (natural range <>)of std_logic; • Function “and” … ----- Include : “and”, “nand” , “or”, “nor” , “xor”, “not” . • ----- Conversion Function: Function to_Bit … ; to_Bitvector , to_stdulogic ; to_stdulogicvector ; to_stdlogicvector ; 函式呼叫 參數傳遞

  24. 典型標準之Types定義( std_logic_arith ) • 1992 Synopsys inc. • Type Unsigned is array (natural range <> ) of std_logic; Type Signed is array (natural range <>) of std_logic; • Functions: (1)arithmetics: “+”, “-”, “*”, (2)Relation: “<”, “>”, “=”, “>=”, “=<”, “/=”, (3)shift: SHL (arg,count) , SHR (arg,count), • Conversion Function: CONV_integer ; CONV_SIGNED(arg,size) ; CONV_UNSIGNED… CONV_std_logic_vector(arg,size) Note: std_與signed/unsigned純為 type “Cast” conversion : B<=Unsigned(A) ; Signed (A) ; ----- A std_logic A<=std_logic_vector(B) ; ----- B Signed or unsigned

  25. 純量型(scale) --- Integer 1、Integer:(default-defined) TYPE integer IS range ____________ ; 。 32- 位元, 範圍: -(231) ~ +(231-1) 。必要時可自行宣告範圍以減小合成之後電路的Size [語法]:User-defined integer (range spec. use integer) TYPE my_integer IS RANGE range_low TO range_hi; TYPE my_integer IS RANGE range_hi DOWNTO range_low; TYPE my_integer IS RANGE <>; Note: <> --無限制(unconstrained) (物件宣告時再定)

  26. 純量型(scale) --- Real 2、Real: (range spec. use real) TYPE real IS range ………… ; 。數字須有小數點: -1.0 e38 ~ +1.01e38 ; [範例]: Signal A: real ; A<= 2.5E-15;

  27. 純量型(scale) --- Physical Type • Physical Data Type TYPE time IS Range <> --基本單位範圍指定 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; TYPE distance IS Range 0 TO 231-1 Units nm; um=1000 nm; mm=1000 um; cm=10 mm; m=1000 mm; Km=1000 m; END units;

  28. 陣列型(Array)資料型態 • 陣列型(Array) …… 或稱 “矩陣” 。其元素由同一種之資料型態組合而成的複合式資料型態 • [語法]: • TYPEary_nameIS ARRAY(起迄範圍)OF元素類態; • 機定:一維陣列, • 起迄範圍: 低 To 高 ;高DOWNTO 低 ;Integer < > …..unconstrained array • Note: Standard unconstrained array 為 Bit_vector 與 String • TYPEary_nameIS ARRAY(d_1_range , … , d_n_range) OF 元素型態; • Note :多維陣列 ; 起迄範圍/維 個別元素之指定;ary_name (integer)

  29. 陣列型(Array)資料型態 【例】: VHDL STANDARD package 中 Bit_vector ……. Bit之一維陣列 TYPE bit_vector IS ARRAY (natural <>) OF bit; 【例】: 一維陣列型態宣告 TYPE byte IS ARRAY (7 downto 0) OF bit; TYPE word IS ARRAY (31 downto 0) OF bit; TYPE Memory_name IS ARRAY (0 to 4096) OF word;

  30. 陣列型(Array)資料型態 [範例]: 多維陣列型態宣告 ROM_ LUT: -- 定義ROM_look-up-table之格式型態( 8X4 之陣列) TYPE Rom_block IS ARRAY (0 TO 7, 0 TO 3) OF BIT; -- 宣告物件:ROM_LUT與 設定其初始值 CONSTANT ROM_LUT : Rom_block := ( ( ‘0’, ‘1’, ‘1’, ‘0’ ), ( ‘0’, ‘1’, ‘1’, ‘0’ ), ( ‘0’, ‘1’, ‘0’, ‘1’ ), ( ‘0’, ‘0’, ‘0’, ‘0’ ), ( ‘0’, ‘1’, ‘1’, ‘0’ ), ( ‘1’, ‘0’, ‘1’, ‘0’ ), ( ‘0’, ‘1’, ‘1’, ‘0’ ), ( ‘1’, ‘1’, ‘1’, ‘1’ ) );

  31. 陣列型(Array)資料型態 • 2-Dimension Array type declaration 【範例】:定義一個 記憶容量為 1232 之ROM資料表Type 【Method-1】:1-D of 1D TYPE word IS ARRAY(31 downto 0) of bit; TYPE ROM_TABLE IS ARRAY(11 downto 0) of word; 【Method-2】:2D-directly TYPE ROM_TABLE IS ARRAY(11 downto 0 , 31 downto 0) of bit ;

  32. OPERATOR

  33. 分類

  34. 運算優先順序 優先權可用”小括號”定優先順序

  35. 邏 輯 運 算 • 邏輯運算子: AND, NAND, OR, NOR, NOT, XOR, XNOR • 邏輯運算中NOT優先權最高,其他優先權一樣。 必要時可用小括號定優先順序。 • 在IEEE Library中定義邏輯運算值是以查表方式實現 【Example】 -- truth table for "and" function CONSTANT and_table : stdlogic_table := ( -- ---------------------------------------------------- -- | U X 0 1 Z W L H - | | -- ---------------------------------------------------- ( 'U', 'U', '0', 'U', 'U', 'U', '0', 'U', 'U' ), -- | U | ( 'U', 'X', '0', 'X', 'X', 'X', '0', 'X', 'X' ), -- | X | ( '0', '0', '0', '0', '0', '0', '0', '0', '0' ), -- | 0 | ( 'U', 'X', '0', '1', 'X', 'X', '0', '1', 'X' ), -- | 1 | ( 'U', 'X', '0', 'X', 'X', 'X', '0', 'X', 'X' ), -- | Z | ( 'U', 'X', '0', 'X', 'X', 'X', '0', 'X', 'X' ), -- | W | ( '0', '0', '0', '0', '0', '0', '0', '0', '0' ), -- | L | ( 'U', 'X', '0', '1', 'X', 'X', '0', '1', 'X' ), -- | H | ( 'U', 'X', '0', 'X', 'X', 'X', '0', 'X', 'X' ) -- | - | ); FUNCTION "and" ( l : std_ulogic; r : std_ulogic ) RETURN UX01 IS BEGIN RETURN (and_table(l, r)); END "and";

  36. 關係運算子 • Scalar object 關係運算子為“Overload” function 會傳回一個 Boolean 值(True/False) FUNCTION “>” (L: operand_type ; R: operand_ type ) RETURN BOOLEAN; • (Standard 與IEEE.std_logic_1164 package沒有包含) 使用時: USE IEEE.NUMERIC_STD; 物件需為integer, Signed 與Unsigned型態 A: std_logic_vector SIGNED(A) 使用在Std_logic物件型態

  37. 四則運算子 • 加減運算 1、Integer 型態 。沒有MSB進位處理 。 欲有MSB進位處理, 可採Signed – extension方式 (1)轉換: Signed(A) 或 Unsigned(A) ; A整數 (2) 用‘&’ operator 多串一位 ,來儲存MSB進位, 正數: ‘0’&B 負數: ‘1’&B

  38. 四則運算子 2、Std_logic_vector 型態 • 需先將 std_logic_vector 化為 Signed or Unsigned 型態.  既可做邏輯運算處理也可做數值計算 • 物件Unsigned與Signed宣告, 一律以 downto定出數列大小 • 需使用 下列packages (1) Synopsis: Std_logic_arith (2) IEEE: Numeric_std 【範例】:Addition -- AIN,BIN:8-BIT_std Result <= (‘0’&unsigned(AIN)+(‘0’&unsigned(B(IN))+Cin ; Cout <= Result (8) Note: & 與 + 優先權相同,故加上小括號處理優先順序。

  39. 四則運算子 3、Bit_vector 型態 • Bit_vector 型態:用 unsigned處理 • 使用時: (1)用Numeric_BIT package , (2)轉換:將 bit_vector 作unsigned處理; (3)最後將結果再 bit_vector化 【範例】: Sum <= bit_vector( unsigned(AIN) + unsigned(BIN));

  40. SLL(a, 2) 移出之位元:漏失 移出之位元:漏失 移走之位元:補 ‘0’ 移走之位元:補 ‘0’ 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 1 1 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 SRL(a, 2) 移位/旋轉運算子…… IEEE.Numeric_std • 亦為“Overload function”, 於1076_1993 (1076.3 , Numeric_std)加入 • 適用於任何一維陣列,type為Signed , unsigned 邏輯移位 語法:Function 呼叫 SLL (arg , N) SRL (arg , N) 其中: Arg: signed or unsigned N: integer

  41. ROL(A, 2) 1 1 1 1 0 1 0 1 1 0 1 0 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 1 0 ROR(A, 2) 移位/旋轉運算子 …… IEEE.Numeric_std 語法:Function 呼叫 ROL (arg , N) ROR (arg , N) 其中: Arg: signed or unsigned N: integer

  42. SLA 2 移出之位元:漏失 移走之位元:補LSB SRA 2 1 1 1 1 0 1 1 0 1 0 0 1 1 0 0 1 1 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 移出之位元:漏失 移走之位元:補 MSB 移位/旋轉運算子 算數移位

  43. 移出之位元 :漏失 移走之位元 :補‘0’ 1 1 1 1 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 0 1 1 0 1 1 1 0 1 1 0 1 SHR(AIN,2) SHL (AIN,2) 移出之位元 :漏失 移走之位元 :補 MSB 移位運算子 …… std_logic_std • SYNOPSYS package : std_logic_arith Signed extension (符號延伸)觀念之移位 SHL & SHR • 完全採正常FUNCTION呼叫方式使用,實際上非Operator SHR(A, N) ; -- A:signed or unsigned , N:unsigned

  44. 範例: 移位/旋轉運算子 • 【範例】:SYNOPSYS • LIBRARY IEEE; • USE ieee.std_logic_1164.all; • USE Std_logic_arith.all; -------------- Package • ENTITY Exp_SSHFT IS • PORT(AIN: IN std_logic_vector(3 downto 0); • BoutL: OUT std_logic_vector(7 downto 0); • BoutR: OUT std_logic_vector(7 downto 0); • Ncount : in std_logic_vector(1 downto 0)) • END ENTITY EXP_SSHFT; • ARCHITECTURE A OF EXP_SSHFT IS • BEGIN • BoutL <= SHL( unsigned(AIN) , unsigned(Ncount)); • BoutR <= SHR(unsigned(AIN) , unsigned(Ncount)); • ----正常FUNCTION呼叫 • END A;

  45. Signal Assignment

  46. Signal Assignment 特性 • Signal Assignment : 兩端之Signal type均須一致 Signal A<=B; ---有延遲現象 Variable A:=B ; ---Variable只能用在Process or 副程式中. • 簡單型 • 條件型 (1) assign When…Else (2) IF …Then assign ; Elsif… Then assign ; End IF; 具排它性,具優先性(愈前愈優先) • 選擇型 (1)With sel_name Select assign when… , assign when others ; (2)Case sel_name Is When… =>assign; End Case; Note:sel_name所有的 ”值” 均須考慮,故使用others

  47. Multiple-driven Signal • How do we determine the state of this wire • Rule to determine: resolution function Driver A What value ? What value ? Driver B 21 MUX with tri-state output (Resolved Signal)

More Related