コードは次のとおりです。
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は変数であり、プロセスが実行されるたびにリセットする必要がありますが、リセットせず、その値を保存することです。シミュレーションで段階的に見てきました。2番目の問題は、入力がこのエンティティに固定されており、各clkプロセスによって変更されないにもかかわらず、x * input(正解)または0(不正解)のいずれかです。クロックを少し減らすと、正解(入力x)で停止する可能性があります私の問題は、入力とxが固定されている場合、入力xが固定されない理由です。2つ目は、プロセスが再度呼び出されたときに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;
///
テストの開始時に、入力値を挿入せずにプロセスが数回実行されることに注意してください。この場合、結果は気にしません。入力が挿入されると、この問題が発生することを話します。