2013-10-28 52 views
0

我是一個vhdl newbie.i爲只用AND和OR門的全加器寫了編碼。我創建了一個測試臺來測試我的代碼,並將它配置爲激發A,B和Cin的八種邏輯組合。當我運行模擬波形是正確的輸入,但總結出(H在我的情況)顯示只是「U」。任何想法請。VHDL全加器測試臺輸出U

library ieee; 
use ieee.std_logic_1164.all; 

--This program describes behaviour of a full adder constructed using 
-- AND and OR gates. It employs component method which describes behaviour of 
--AND,OR and NOT gates and use them to build the final object 


--Entity description of the full adder 
    entity full_add is 
    port (a,b,c:IN BIT; h:OUT BIT); 
    end entity full_add; 

--Description the 3 input And Gate 

    entity And2 is 
    port (j,k,l:in BIT; m:out BIT); 
    end entity And2; 

    architecture ex1 of And2 is 
    begin 
    m <= (j AND k AND l); 
    end architecture ex1; 

    --Description of the four input OR gate 

    entity Or2 is 
    port (d,e,f,g:IN BIT; h:OUT BIT); 
    end entity Or2; 

    architecture ex1 of Or2 is 
    begin 
    h <= (d or e or f or g); 
    end architecture ex1; 

--Description of the NOT gate 

entity Not1 is 
port(x:in BIT; y:out BIT); 
end entity Not1; 

architecture ex1 of Not1 is 
begin 
y <= not x; 
end architecture ex1; 

--Components and wiring description 

architecture netlist of full_add is 
signal s,u,v,s2,u2,v2,w2:BIT; 
begin 
g1:entity WORK.Not1(ex1) port map(a,s); 
g2:entity WORK.Not1(ex1) port map(b,u); 
g3:entity WORK.Not1(ex1) port map(c,v); 
g4:entity WORK.And2(ex1) port map(s,u,c,s2); 
g5:entity WORK.And2(ex1) port map(s,b,v,u2); 
g6:entity WORK.And2(ex1) port map(a,u,v,v2); 
g7:entity WORK.And2(ex1) port map(a,b,v,w2); 
g8:entity WORK.Or2(ex1) port map (s2,u2,v2,w2,h); 

end architecture netlist; 
+0

如何讓一個完整的加法器只有一個輸出?我認爲一個完整的加法器有一個總和和一個進位? – GregHNZ

+0

請張貼測試臺,因爲這樣可以複製您的問題,從而更容易進行調試。順便說一句。你不需要創建一個模塊來獲得'not operation';所以g1可以寫成's <=不是a'等。 –

+0

Morten關於「不」的觀點是有效的,但同樣適用於「和」和「或」。我認爲這裏的重點是學習結構化編碼,而不是優化解決方案。 –

回答

1

你將不得不調試實現:這將是一個很好的使用模擬器的練習!

你看到「H」的值爲'U',但你還不知道爲什麼。跟蹤H的所有驅動程序:在發佈的代碼中,我只能看到一個來自輸入S2,U2,V2,W2的驅動程序。

在模擬器中,將這些信號添加到Wave窗口並重新運行模擬:其中一個卡在'U'上嗎?如果是這樣,請追蹤該信號以找出原因。如果它們都具有有效值,則指向其他驅動「U」的信號到信號H.

瞭解模擬器的「驅動程序」命令(即查找和閱讀手冊!)以識別驅動H,和他們的價值在給定的時間。 (隱藏給我們)測試平臺中可能有一個驅動程序。如果是這樣,請更改其驅動值(可能使用H <= 'Z';"分配)並重新運行模擬。從本質上講:學習和練習基本的模擬調試技巧:其中一種技能很可能解決問題。用你從他們身上學到的東西來編輯問題:如果問題依然存在,這些結果將更接近它。