這裏是一個級聯全加器的通用代碼。Vhdl通用fulladder代碼
問題是,fulladder的結果出現一個事件延遲(我的意思是當我改變input1 & inputs2出現以前輸入的結果)。我知道,如果我在沒有進程的情況下編寫代碼,這種延遲不會發生,但是我需要編寫一個通用的fulladder,並且沒有辦法編寫沒有進程和for循環的通用代碼。
所以我問是否有人可以幫助我修復代碼,以便輸出結果毫不遲疑地顯示結果!
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
entity adders is
generic(
numberOfInputs : Integer := 4
); port(
enable : in std_logic;
cin : in std_logic;
inputs1 : in std_logic_vector(numberOfInputs-1 downto 0);
inputs2 : in std_logic_vector(numberOfInputs-1 downto 0);
outputs : out std_logic_vector(numberOfInputs downto 0)
);
end entity adders;
architecture Generic_Adder of adders is
signal Couts:std_logic_vector(numberOfInputs downto 0);
signal temp1:std_logic_vector(numberOfInputs-1 downto 0);
signal temp2:std_logic_vector(numberOfInputs-1 downto 0);
signal temp3:std_logic_vector(numberOfInputs-1 downto 0);
begin
temp2<=inputs1;
temp3<=inputs2;
couts(0)<= cin;
Sum:process(temp2,temp3,cin,enable,Couts) is
begin
for count in 0 to numberOfInputs-1 loop
temp1(count) <= (temp2(count) xor temp3(count));
outputs(count) <= Couts(count) xor temp1(count);
Couts(count+1) <= (temp2(count) and temp3(count)) or(couts(count) and temp1(count));--cout(count) is the previuos cout becuase the first cout is cin
end loop;
end process;
outputs(numberOfInputs) <= Couts(numberOfInputs);
end Generic_Adder;
或者如果他們正在使用一個新的編譯器:'process(all)'。另外在靈敏度列表中不需要'cin'和'enable'。我不確定如果他們想要實際使用「使能」位並保持輸出,他們如何在沒有鎖存器的情況下編寫它。 – 2015-03-31 14:08:35
你也可以用'temp1'作爲變量而不是信號。在這種情況下,它不一定是一個向量,在簡單的std_logic中就可以。 – 2015-03-31 14:26:37
在輸出中沒有延遲,但輸出(1)和輸出(2)未知(u)!! ??我該如何解決? – user2988239 2015-03-31 15:25:27