基於VHDL語言的全加器的設計

基於VHDL語言的全加器的設計

全加器可以由兩個半加器和一個或門連接而成,這樣得到的半加器電路稱爲頂層文件。
設計原理圖如下:
在這裏插入圖片描述
下面全加器的設計採用層次結構的VHDL程序設計方法,採用元件例化語句。

  1. 工程文件名與頂層文件(全加器)文件名一樣;
  2. 把全加器、半加器、或門的vhdl文件都要包含到工程中;
  3. 在全加器文件中聲明半加器、或門爲元件;
  4. 然後例化三個元件:兩個半加器和一個或門。
  5. 軟件說明:ModelSimSetup-13.1.0.162,QuartusSetup-13.1.0.162。

建立工程:

第一步:打開Quartus軟件。

第二步:點擊New Project Wizard -> next.

第三步:選擇工程文件的存放位置,輸入工程名 -> next -> next。

第四步:在family欄選擇芯片型號-Cyclone IV E,在Name欄選擇EP4CE115F29C7,選擇完之後點擊next。(如果不進行硬件調試時,此處默認即可)

第五步:檢查工程有沒有建錯,點擊完成。如下圖:
在這裏插入圖片描述

程序設計:

全加器頂層文件設計:

   --文件名:adder.vhd 應與工程名保持一致:
    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    entity adder is	
        port(ain,bin,cin:in std_logic;
    	 cout,sum:out std_logic);
    end adder;
    architecture fd1 of adder is
    component h_adder
    	--半加器原件聲明
    	port(a,b:in std_logic;
    	co,so:out std_logic);
    end component;
    component or2a
    	--聲明或門原件
    	port(a,b:in std_logic;
    	c:out std_logic);
    end component;
    signal d,e,f:std_logic;
    begin
    	u1:h_adder port map(a=>ain,b=>bin,co=>d,so=>e);--半加器原件例化
    	u2:h_adder port map(a=>e,b=>cin,co=>f,so=>sum);--半加器原件例化
    	u3:or2a port map(a=>d,b=>f,c=>cout);--半或門原件例化
    end fd1;

對半加器原件進行實例化:

   --文件名:h_adder.vhd
    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    entity h_adder is
       port(a,b:in std_logic;
    		co,so:out std_logic);
    end h_adder;
    architecture fh1 of h_adder is
    begin
    	so<=NOT(a XOR (NOT b));
    	co<= a AND b;
    end fh1;

對或門原件進行實例化:

  --文件名:or2a.vhd
    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    
    entity or2a is
    	port(a,b:in std_logic;
       c:out std_logic);
    end or2a;
    architecture one of or2a is
    begin
    	c<=a OR b;
    end one;

文件仿真(這裏採用modelsim仿真波形):

  1. 選擇File-> New -> Verification/Debugging Files ->University Program VWF。
    在這裏插入圖片描述
    2.打開測試文件。(右鍵點擊添加端口,對輸入信號初始化,賦值。)

在這裏插入圖片描述
3.仿真結果:
在這裏插入圖片描述

邏輯電路圖:

顯示編譯成功後,選擇菜單欄 Tools –>Netlist Viewers –>RTL Viewer 顯示邏輯電路圖
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章