下面是代碼:VHDL代碼作用奇怪(小的代碼,其中,可變保持其值並且犯規重置)
entity main is
port(input:in unsigned(99 downto 0);
clk:in std_logic;
output:out unsigned(99 downto 0)
);
end main;
architecture Behavioral of main is
begin
process(clk)
variable x:unsigned(99 downto 0):=X"27c8a94a6fb72a00000000000";
begin
if(clk'event and clk='1') then
x:=(x*input);// this line is a problem!!
output<=x;
x:=X"27c8a94a6fb72a00000000000";// i have to rest x manually :S
end if;
end process;
end Behavioral;
第一個問題是X雖然一個變量,並應重置每個時間進程運行它不'並保存它的價值!我已經在模擬中一步一步地看到它。 第二個問題是雖然輸入固定到這個實體,並且不會因每個時鐘進程而改變x或者是x *輸入(正確答案)或者0(錯誤答案) 到時候我的時鐘停止滴答停止在0答案,if我減少時鐘一點它可能會停止在正確的答案(這是輸入* x) 我的問題是爲什麼輸入* x不固定,如果輸入和x是固定的,第二個是爲什麼x不重置時再次調用過程從其敏感度列表中)。 這裏是測試代碼:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
use IEEE.numeric_std.all;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY test IS
END test;
ARCHITECTURE behavior OF test IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT main
PORT(
input : IN unsigned(99 downto 0);
clk : IN std_logic;
output : OUT unsigned(99 downto 0)
);
END COMPONENT;
--Inputs
signal input : unsigned(99 downto 0) := (others => '0');
signal clk : std_logic := '0';
--Outputs
signal output : unsigned(99 downto 0);
-- Clock period definitions
constant clk_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: main PORT MAP (
input => input,
clk => clk,
output => output
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 100 ns;
input<=X"000000000000000000000000F";
--input<="000000000001";
wait for clk_period*10;
-- insert stimulus here
wait;
end process;
END;
///
注意,在實驗開始的過程中沒有插入輸入值多次運行,在這種情況下,我不關心結果,我在插入輸入時發生此問題。
可悲的是並非如此,因爲我在模擬器中一步一步的簡歷看成爲「E1」(corrwct答案)然後sudeenly就變成0?E1 * E1不爲零時,我不爲什麼發生這種情況,我通過inializing其重置每個運行x值我改變碼本: 過程(CLK) 變量x:無符號(99 DOWNTO 0); 開始 如果(clk'event並且clk = '1'),那麼 X:=(輸入); x:=(x * x); output <= x; end if; 結束過程; 結束行爲; – 2013-03-14 16:17:17
您發佈的代碼中沒有「cv」,因此我無法理解此評論。進一步的「000F」*「xxxxxxx_x000_0000_0000」不可能等於「e1」。我的答案中有一個錯誤(現在正在編輯),但它不會影響我推薦的前進方向。 – 2013-03-14 16:28:46