EDA技術與VHDL第一部分 VHDL語句_第1頁
EDA技術與VHDL第一部分 VHDL語句_第2頁
EDA技術與VHDL第一部分 VHDL語句_第3頁
EDA技術與VHDL第一部分 VHDL語句_第4頁
EDA技術與VHDL第一部分 VHDL語句_第5頁
已閱讀5頁,還剩58頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、第第1 1部分部分 一一 順序語句順序語句 1.1 賦值語句賦值語句 信號賦值語句信號賦值語句 變量賦值語句變量賦值語句 1.2 if語句語句 1.3 case語句語句 選擇值選擇值 |選擇值選擇值 單個普通數(shù)值,如單個普通數(shù)值,如6。 數(shù)值選擇范圍,如數(shù)值選擇范圍,如(2 to 4)(2 to 4),表示取值為,表示取值為2 2、3 3或或4 4。 并列數(shù)值,如并列數(shù)值,如3 3 5 5,表示取值為,表示取值為3 3或者或者5 5。 混合方式,以上三種方式的混合?;旌戏绞剑陨先N方式的混合。 【例【例1】 library ieee; use ieee.std_logic_1164.all;

2、 entity mux41 is port (s4,s3, s2,s1 : in std_logic; z4,z3, z2,z1 : out std_logic); end mux41; architecture activ of mux41 is signal sel : integer range 0 to 15; begin process (sel ,s4,s3,s2,s1 ) begin sel= 0 ; - 輸入初始值輸入初始值 if (s1 =1) then sel = sel+1 ; elsif (s2 =1) then sel = sel+2 ; elsif (s3 =1)

3、then sel = sel+4 ; elsif (s4 =1) then sel = sel+8 ; else null; - 注意,這里使用了空操作語句注意,這里使用了空操作語句 end if ; z1=0 ; z2=0; z3=0; z4 z1 z2 z3 z4 out1 out1 out1 out1 result result - a、b相等相等 if (a = b) then result = x01; else result - a、b不相等不相等 if (a /= b) then result = x01; else result 10 ; - 當當a大于大于10時跳出循環(huán)時跳出

4、循環(huán) end loop l2; . 一順序語句一順序語句 1.4 loop語句語句 (2) for_loop語句,語法格式如下:語句,語法格式如下: loop標號:標號: for 循環(huán)變量,循環(huán)變量,in 循環(huán)次數(shù)范圍循環(huán)次數(shù)范圍 loop 順序語句順序語句 end loop loop標號標號; 一順序語句一順序語句 1.4 loop語句語句 【例【例4】 library ieee; use ieee.std_logic_1164.all; entity p_check is port ( a : in std_logic_vector (7 downto 0); y : out std_lo

5、gic ); end p_check; architecture opt of p_check is signal tmp :std_logic ; begin process(a) begin tmp =0; for n in 0 to 7 loop tmp = tmp xor a(n); end loop ; y = tmp; end process; end opt; 一順序語句一順序語句 1.4 loop語句語句 【例【例5】 signal a, b, c : std_logic_vector (1 to 3); . for n in 1 to 3 loop a(n) = b(n) a

6、nd c(n); end loop; 此段程序等效于順序執(zhí)行以下三個信號賦值操作:此段程序等效于順序執(zhí)行以下三個信號賦值操作: a(1)=b(1) and c(1); a(2)=b(2) and c(2); a(3)f); s3 : b(k+8) := 0; k := k+1; next loop l_y ; next loop l_x ; . 一順序語句一順序語句 1.6 exit語句語句 exit; - 第一種語句格式第一種語句格式 exit loop標號;標號; - 第二種語句格式第二種語句格式 exit loop標號標號 when 條件表達式;條件表達式; - 第三種語句格式第三種語句

7、格式 一順序語句一順序語句 1.6 exit語句語句 【例【例8】 signal a, b : std_logic_vector (1 downto 0); signal a_less_then_b : boolean; . a_less_then_b = false ; - 設初始值設初始值 for i in 1 downto 0 loop if (a(i)=1 and b(i)=0) then a_less_then_b b exit ; elsif (a(i)=0 and b(i)=1) then a_less_then_b = true ; - a b exit; else null;

8、 end if; end loop; - 當當 i=1時返回時返回loop語句繼續(xù)比較語句繼續(xù)比較 一順序語句一順序語句 1.7 wait語句語句 wait; - 第一種語句格式第一種語句格式 wait on 信號表;信號表; - 第二種語句格式第二種語句格式 wait until 條件表達式;條件表達式; - 第三種語句格式第三種語句格式 wait for 時間表達式;時間表達式; - 第四種語句格式,超時等待語句第四種語句格式,超時等待語句 一一 順序語句順序語句 1.7 wait語句語句 【例【例9】 signal s1,s2 : std_logic; . process begin .

9、 wait on s1,s2 ; end process ; 一順序語句一順序語句 1.7 wait語句語句 【例【例10】 (a) wait_until結構結構 (b) wait_on結構結構 . loop wait until enable =1; wait on enable; . exit when enable =1; end loop; 一順序語句一順序語句 1.7 wait語句語句 wait until 信號信號=value ; - (1) wait until 信號信號event and 信號信號=value; - (2) wait until not 信號信號stable a

10、nd 信號信號=value; - (3) wait until clock =1; wait until rising_edge(clock) ; wait until not clockstable and clock =1; wait until clock =1 and clockevent; 一一 順序語句順序語句 1.7 wait語句語句 【例【例11】 process begin wait until clk =1; ave = a; wait until clk =1; ave = ave + a; wait until clk =1; ave = ave + a; wait u

11、ntil clk =1; ave = (ave + a)/4 ; end process ; 一一 順序語句順序語句 1.7 wait語句語句 【例【例12】 process begin rst_loop : loop wait until clock =1 and clockevent; - 等待時鐘信號等待時鐘信號 next rst_loop when (rst=1); - 檢測復位信號檢測復位信號rst x = a ; - 無復位信號,執(zhí)行賦值操作無復位信號,執(zhí)行賦值操作 wait until clock =1 and clockevent; - 等待時鐘信號等待時鐘信號 next rs

12、t_loop when (rst=1); - 檢測復位信號檢測復位信號rst y = b ; - 無復位信號,執(zhí)行賦值操作無復位信號,執(zhí)行賦值操作 end loop rs 【例【例13】 library ieee; use ieee.std_logic_1164.all; entity shifter is port ( data : in std_logic_vector (7 downto 0); shift_left: in std_logic; shift_right: in std_logic; clk: in std_logic; reset : in std_logic; mod

13、e : in std_logic_vector (1 downto 0); qout : buffer std_logic_vector (7 downto 0) ); end shifter; architecture behave of shifter is signal enable: std_logic; begin process begin wait until (rising_edge(clk) ); -等待時鐘上升沿等待時鐘上升沿 if (reset = 1) then qout qout qout qout null; end case; end if; end proces

14、s; end behave; 一順序語句一順序語句 1.8 return語句語句 返回語句返回語句return有兩種語句格式有兩種語句格式: return; - 第一種語句格式第一種語句格式 return 表達式;表達式; - 第二種語句格式第二種語句格式 一順序語句一順序語句 1.8 return語句語句 【例【例14】 procedure rs (signal s , r : in std_logic ; signal q , nq : inout std_logic) is begin if ( s =1 and r =1) then report forbidden state : s

15、 and r are quual to 1; return ; else q = s and nq after 5 ns ; nq tmp := rega and regb ; when 101 = tmp := rega or regb ; when 110 = tmp := not rega ; when others = null ; end case ; 二二 并行語句并行語句 并行信號賦值語句并行信號賦值語句(concurrent signal assignments)(concurrent signal assignments)。 進程語句進程語句(process statemen

16、ts)(process statements)。 塊語句塊語句(block statements)(block statements)。 條件信號賦值語句條件信號賦值語句(selected signal assignments)(selected signal assignments)。 元件例化語句元件例化語句(component instantiations)(component instantiations),其中包括類屬配置語句。,其中包括類屬配置語句。 生成語句生成語句(generate statements)(generate statements)。 并行過程調用語句并行過程調用

17、語句(concurrent procedure calls)(concurrent procedure calls)。 參數(shù)傳遞映射語句參數(shù)傳遞映射語句 端口說明語句端口說明語句 二二 并行語句并行語句 并行語句在結構體中的使用格式如下:并行語句在結構體中的使用格式如下: architecture 結構體名結構體名 of 實體名實體名 is 說明語句說明語句 begin 并行語句并行語句 end architecture 結構體名結構體名 二二 并行語句并行語句 2.1 并行信號賦值語句并行信號賦值語句 1. 簡單信號賦值語句簡單信號賦值語句 賦值目標賦值目標 = 表達式表達式 archite

18、cture curt of bc1 is signal s1, e, f, g, h : std_logic ; begin output1 = a and b ; output2 = c + d ; g = e or f ; h = e xor f ; s1 = g ; end architecture curt; 二二 并行語句并行語句 2.1 并行信號賦值語句并行信號賦值語句 2. 條件信號賦值語句條件信號賦值語句 賦值目標賦值目標 = 表達式表達式 when 賦值條件賦值條件 else 表達式表達式 when 賦值條件賦值條件 else . 表達式表達式 ; 2. 條件信號賦值語句條件

19、信號賦值語句 【例【例16】 entity mux is port ( a,b,c : in bit ; p1,p2 : in bit ; z : out bit ); end; architecture behv of mux is begin z = a when p1 = 1 else b when p2 = 1 else c ; end; 二二 并行語句并行語句 二二 并行語句并行語句 2.1 并行信號賦值語句并行信號賦值語句 2. 條件信號賦值語句條件信號賦值語句 圖圖1 例例16的的rtl電路圖電路圖 二二 并行語句并行語句 2.1 并行信號賦值語句并行信號賦值語句 3. 選擇信號

20、賦值語句選擇信號賦值語句 with 選擇表達式選擇表達式 select 賦值目標信號賦值目標信號 = 表達式表達式 when 選擇值選擇值 表達式表達式 when 選擇值選擇值 . 表達式表達式 when 選擇值;選擇值; 【例【例17】 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity decoder is port ( a, b, c : in std_logic; data1,data2 : in std_logic; dataout : out std_logic );

21、end decoder; architecture concunt of decoder is signal instruction : std_logic_vector(2 downto 0) ; begin instruction = c with instruction select dataout = data1 and data2 when 000 , data1 or data2 when 001 , data1 nand data2 when 010 , data1 nor data2 when 011 , data1 xor data2 when 100 , data1 xno

22、r data2 when 101 , z when others ; end concunt ; 二二 并行語句并行語句 2.1 并行信號賦值語句并行信號賦值語句 3. 選擇信號賦值語句選擇信號賦值語句 . with selt select muxout = a when 0|1 , - 0或或1 b when 2 to 5 , - 2或或3,或,或4或或5 c when 6 , d when 7 , z when others ; . 二二 并行語句并行語句 2.2 實體說明語句實體說明語句 entity 實體名實體名 is generic ( 參數(shù)名:數(shù)據(jù)類型參數(shù)名:數(shù)據(jù)類型 ); por

23、t ( 端口表端口表 ); end entity 實體名實體名; 二并行語句二并行語句 2.3 參數(shù)傳遞說明語句參數(shù)傳遞說明語句 generic( 常數(shù)名常數(shù)名 : 數(shù)據(jù)類型數(shù)據(jù)類型 : 設定值設定值 ;常數(shù)名常數(shù)名 : 數(shù)據(jù)類型數(shù)據(jù)類型 : 設定值設定值 ) ; 二并行語句二并行語句 7.2.3 參數(shù)傳遞說明語句參數(shù)傳遞說明語句 【例【例18】 library ieee; use ieee.std_logic_1164.all; entity andn is generic ( n : integer ); -定義類屬參量及其數(shù)據(jù)類型定義類屬參量及其數(shù)據(jù)類型 port(a : in std_

24、logic_vector(n-1 downto 0);-用類屬參量限制矢量長度用類屬參量限制矢量長度 c : out std_logic); end; architecture behav of andn is begin process (a) variable int : std_logic; begin int := 1; for i in alength - 1 downto 0 loop -循環(huán)語句循環(huán)語句 if a(i)=0 then int := 0; end if; end loop; c 2) - 參數(shù)傳遞映射語句,定義類屬變量,參數(shù)傳遞映射語句,定義類屬變量,n賦值為賦值為

25、2 port map (a(0)=d1,a(1)=d2,c=q1); u2: andn generic map (n =5) - 定義類屬變量,定義類屬變量,n賦值為賦值為5 port map (a(0)=d3,a(1)=d4,a(2)=d5, a(3)=d6,a(4)=d7, c=q2); end; 二二 并行語句并行語句 2.4 參數(shù)傳遞映射語句參數(shù)傳遞映射語句 generic map(類屬表類屬表) 【例【例20】 library ieee; -待例化元件待例化元件 use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; us

26、e ieee.std_logic_unsigned.all; entity addern is port (a, b: in std_logic_vector; result: out std_logic_vector); end addern; architecture behave of addern is begin result = a + b; end; 二二 并行語句并行語句 7.2.4 參數(shù)傳遞映射語句參數(shù)傳遞映射語句 generic map(類屬表類屬表) 【例【例21】 library ieee; -頂層設計頂層設計 use ieee.std_logic_1164.all;

27、use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity adders is generic(msb_operand: integer := 15; msb_sum: integer :=15); port(b: in std_logic_vector (msb_operand downto 0); result: out std_logic_vector (msb_sum downto 0); end adders; architecture behave of adders is component adde

28、rn port ( a, b: in std_logic_vector; result: out std_logic_vector); end component; signal a: std_logic_vector (msb_sum /2 downto 0); signal twoa: std_logic_vector (msb_operand downto 0); begin twoa twoa, b = b, result = result); u2: addern port map (a=b(msb_operand downto msb_operand/2 +1), b=b(msb_

29、operand/2 downto 0), result = a); end behave; 二并行語句二并行語句 2.4 參數(shù)傳遞映射語句參數(shù)傳遞映射語句 圖圖2 例例21的的rtl電路圖電路圖 二二 并行語句并行語句 2.5 端口說明語句端口說明語句 port ( 端口名端口名 : 端口模式端口模式 數(shù)據(jù)類型數(shù)據(jù)類型 ; 端口名端口名 : 端口模式端口模式 數(shù)據(jù)類型數(shù)據(jù)類型 ) ; 2.6 塊語句結構塊語句結構 塊標號塊標號 : block (塊保護表達式塊保護表達式) 接口說明接口說明 類屬說明類屬說明 begin 并行語句并行語句 end block 塊標號塊標號 ; 【例【例22】 .

30、 entity gat is generic(l_time : time ; s_time : time ) ; - (參數(shù)傳遞)類屬說明(參數(shù)傳遞)類屬說明 port (b1, b2, b3 : inout bit) ; - 結構體全局端口定義結構體全局端口定義 end entity gat ; architecture func of gat is signal a1 : bit ; - 結構體全局信號結構體全局信號 a1定義定義 begin blk1 : block - 塊定義,塊標號名是塊定義,塊標號名是blk1 generic (gb1, gb2 : time) ; - 定義塊中的局

31、部類屬參量定義塊中的局部類屬參量 generic map (gb1 = l_time,gb2 = s_time); - 局部端口參量設定局部端口參量設定 port (pb : in bit; pb2 : inout bit ); - 塊結構中局部端口定義塊結構中局部端口定義 port map (pb1 = b1, pb2 = a1 ) ; - 塊結構端口連接說明塊結構端口連接說明 constant delay : time := 1 ms ; - 局部常數(shù)定義局部常數(shù)定義 signal s1 : bit ; - 局部信號定義局部信號定義 begin s1 = pb1 after delay ;

32、 pb2 = s1 after gb1, b1 after gb2 ; end block blk1 ; end architecture func ; 二二 并行語句并行語句 2.6 塊語句結構塊語句結構 【例【例23】 . b1 : block signal s1: bit ; begin s1 = a and b ; b2 : block signal s2: bit ; begin s2 = c and d ; b3 : block begin z = s2 ; end block b3 ; end block b2 ; y = s1 ; end block b1 ; . 【例【例24

33、】 library ieee; use ieee. std_logic_1164.all; entity f_adder is port ( ain, bin , cin : in std_logic; sum, cout : out std_logic ); end f_adder; architecture e_ad of f_adder is signal so1, co1, co2 : std_logic; begin h_adder1 : block -半加器半加器u1 begin process( ain,bin ) begin so1=not(ain xor (not bin);

34、 co1= ain and bin; end process; end block h_adder1; h_adder2: block -半加器半加器u2 signal so2 : std_logic; begin so2 = not(so1 xor (not cin) ; co2=so1 and cin ; sum=so2; end block h_adder2; or2 : block -或門或門u3 begin process (co2, co1) begin cout 連接端口名,連接端口名,.) ; 二二 并行語句并行語句 2.8 生成語句生成語句 標號:標號: for 循環(huán)變量循環(huán)

35、變量 in 取值范圍取值范圍 generate 說明說明 begin 并行語句并行語句 end generate 標號標號 ; 或或 標號:標號: if 條件條件generate 說明說明 begin 并行語句并行語句 end generate 標號標號 ; 二二 并行語句并行語句 表達式表達式 to 表達式表達式 ; - 遞增方式,如遞增方式,如1 to 5 表達式表達式 downto 表達式表達式 ; - 遞減方式,如遞減方式,如5 downto 1 【例【例25】 . component comp port (x : in std_logic ; y : out std_logic );

36、 end component ; signal a :std_logic_vector(0 to 7); signal b :std_logic_vector(0 to 7); . gen : for i in arange generate u1: comp port ma (x=a(i),y=b(i); end generate gen, . 2.8 生成語句生成語句 二二 并行語句并行語句 圖圖4 生成語句產(chǎn)生的生成語句產(chǎn)生的8個相同的電路模塊個相同的電路模塊 comp inputoutput comp inputoutput comp inputoutputa0b0 a1b1 a7b7

37、 . . . 2.8 生成語句生成語句 二二 并行語句并行語句 【例【例26】 library ieee; use ieee.std_logic_1164.all; entity latch is port( d,ena : in std_logic; q : out std_logic ); end entity latch ; architecture one of latch is signal sig_save : std_logic; begin process (d, ena) begin if ena = 1 then sig_save = d ; end if ; q = si

38、g_save ; end process ; end architecture one; 2.8 生成語句生成語句 【例【例27】 library ieee; use ieee.std_logic_1164.all; entity sn74373 is port (d : in std_logic_vector( 8 downto 1 ); oen ,g : in std_logic; q : out std_logic_vector(8 downto 1); end entity sn74373; architecture two of sn74373 is signal sigvec_sa

39、ve : std_logic_vector(8 downto 1); begin process(d, oen, g , sigvec_save) begin if oen = 0 then q = sigvec_save; else q = zzzzzzzz; end if; if g = 1 then sigvec_save = d; end if; end process; end architecture two; architecture one of sn74373 is component latch port ( d, ena : in std_logic; q : out s

40、td_logic ); end component; signal sig_mid : std_logic_vector( 8 downto 1 ); begin gelatch : for inum in 1 to 8 generate latchx : latch port map(d(inum),g,sig_mid(inum); end generate; q = sig_mid when oen = 0 else zzzzzzzz; -當當oen=1時,時,q(8)q(1)輸出狀態(tài)呈高阻態(tài)輸出狀態(tài)呈高阻態(tài) end architecture one; 【例【例28】 library ie

41、ee; use ieee.std_logic_1164.all; entity d_ff is port ( d, clk_s : in std_logic ; q : out std_logic ; nq : out std_logic ); end entity d_ff; architecture a_rs_ff of d_ff is begin bin_p_rs_ff : process(clk_s) begin if clk_s = 1 and clk_sevent then q = d; nq = not d; end if; end process; end architectu

42、re a_rs_ff; library ieee; use ieee.std_logic_1164.all; entity cnt_bin_n is generic (n : integer := 6); port (q : out std_logic_vector (0 to n-1); in_1 : in std_logic ); end entity cnt_bin_n; architecture behv of cnt_bin_n is component d_ff port(d, clk_s : in std_logic; q, nq : out std_logic); end co

43、mponent d_ff; signal s : std_logic_vector(0 to n); begin s(0) = in_1; q_1 : for i in 0 to n-1 generate dff : d_ff port map (s(i+1), s(i), q(i), s(i+1); end generate; end architecture behv; 二二 并行語句并行語句 fd11 d0 q0 fd11 d0 q0 fd11 d0 q0 nqnq nq clkclkclk i=n-1i=0i=1 s(n) s(2) s(1) s(0) qn-1q1q0 圖圖5 6 位

44、二進制計數(shù)器原理圖位二進制計數(shù)器原理圖 2.8 生成語句生成語句 二二 并行語句并行語句 2.9 report語句語句 【例【例29】 library ieee; use ieee.std_logic_1164.all; entity rsff2 is port ( s, r : in std_logic; q, qf : out std_logic ); end rsff2; architecture bhv of rsff2 is begin p1: process(s,r) variable d : std_logic; begin if r = 1 and s = 1 then rep

45、ort both r and s is 1; -報告出錯信息報告出錯信息 elsif r = 1 and s = 0 then d := 0; elsif r = 0 and s = 1 then d := 1 ; end if; q = d; qf = not d; end process; end bhv; 二二 并行語句并行語句 2.10 斷言語句斷言語句 assert assert report report severity severity ; note(通報)(通報)報告出錯信息,可以通過編譯報告出錯信息,可以通過編譯 warning(警告)(警告)報告出錯信息,可以通過編譯報告

46、出錯信息,可以通過編譯 error(錯誤)(錯誤)報告出錯信息,暫停編譯報告出錯信息,暫停編譯 failure(失敗)(失?。﹫蟾娉鲥e信息,暫停編譯報告出錯信息,暫停編譯 表表1 預定義錯誤等級預定義錯誤等級 二二 并行語句并行語句 1. 順序斷言語句順序斷言語句 【例【例30】 p1: process(s,r) variable d : std_logic; begin assert not (r=1and s=1) report both r and s equal to 1 severity error; if r = 1 and s = 0 then d := 0; elsif r =

47、 0 and s = 1 then d := 1 ; end if; q = d; qf = not d; end process; 2.10 斷言語句斷言語句 2. 2. 并行斷言語句并行斷言語句 【例【例31】 library ieee; use ieee.std_logic_1164.all; entity rsff2 is port(s, r : in std_logic; q,qf : out std_logic); end rsff2; architecture bhv of rsff2 is begin process(r,s) begin assert not (r=1and

48、s=1) report both r and s equal to 1 severity error; end process; process(r,s) variable d : std_logic := 0; begin if r=1 and s=0 then d :=0; elsif r=0 and s=1 then d :=1; end if; q = d ; qf = not d ; end process; end ; 三三 屬性描述與定義語句屬性描述與定義語句 1. 信號類屬性信號類屬性 (not clockstable and clock =1) (clockevent and clock =1

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論