我写了这个简单的过程。它应该累加 ((ba)/n)*yi 项,其中 yi 是每个时钟周期更新的输入,然后输出总和的结果。
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity Integrator is
Port ( a : in STD_LOGIC_VECTOR(7 downto 0);
b : in STD_LOGIC_VECTOR(7 downto 0);
n : in STD_LOGIC_VECTOR(7 downto 0);
yi : in STD_LOGIC_VECTOR (15 downto 0);
start : in std_logic;
clk : in std_logic;
output : out signed (15 downto 0);
done : out STD_LOGIC);
end Integrator;
architecture Integrator_arch of Integrator is
signal do : std_logic;
signal i : unsigned(7 downto 0);
signal tmp1, tmp2, tmp3, res : signed(15 downto 0);
begin
process(clk)
begin
if(clk'event and clk='1') then
if(start='1') then
do <= '1';
i <= (others=>'0');
done <= '0';
res <= (others=>'0');
elsif(do='1' and done='0') then
if(i=unsigned(n)) then
output <= res;
do <= '0';
done <= '1';
else
tmp1 <= resize(signed(b)-signed(a),16);
tmp2 <= resize(tmp1/signed(n),16);
tmp3 <= resize(tmp2*signed(yi),16);
res <= res + tmp3;
i <= i+1;
end if;
end if;
end if;
end process;
end Integrator_arch;
这是测试台:
architecture Behavioral of Integrator_Testbench is
signal start : std_logic;
signal clk, done : std_logic;
signal yi : std_logic_vector(15 downto 0);
signal O : signed(15 downto 0);
begin
uut: entity work.integrator(integrator_arch)
port map(a=>"11111110", b=>"00000010", n=>"00000100", yi=>yi
,start=>start, clk=>clk, done=>done, output=>O);
process
begin
clk<='0';
start<='1';
wait for 200ns;
clk<='1';
wait for 200ns;
start<='0';
clk<='0';
yi<=x"0003";
wait for 200ns;
clk<='1';
yi<=x"0003";
wait for 200ns;
clk<='0';
yi<=x"0001";
wait for 200ns;
clk<='1';
yi<=x"0001";
wait for 200ns;
clk<='0';
yi<=x"0000";
wait for 200ns;
clk<='1';
yi<=x"0000";
wait for 200ns;
clk<='0';
yi<=x"0002";
wait for 200ns;
clk<='1';
yi<=x"0002";
wait for 200ns;
clk<='0';
yi<=x"0000";
wait for 200ns;
clk<='1';
yi<=x"0000";
wait for 200ns;
clk<='0';
yi<=x"0000";
wait for 200ns;
clk<='1';
yi<=x"0000";
wait for 200ns;
end process;
end Behavioral;
但问题是,当我运行行为模拟时,输出总是报告为未知(红色 X)。更奇怪的是,它在调试会话中运行得非常好,并且通过运行逐行调试会话,我能够得到正确的输出,即 x"0006"!!!
经过两个小时的尝试寻找问题后,我终于决定问。特别是因为它运行得很好,并且在逐行调试中输出了正确的结果,所以我不知道为什么模拟一直在起作用。
非常感谢您的时间。
