背景:我正在尝试创建一个用于将三个矩阵相乘的行为文件。我试图通过首先查看是否可以读取输入矩阵然后输出中间矩阵来调试它。
行为文件:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
entity DCT_beh is
port (
Clk : in std_logic;
Start : in std_logic;
Din : in INTEGER;
Done : out std_logic;
Dout : out INTEGER
);
end DCT_beh;
architecture behavioral of DCT_beh is
begin
process
type RF is array ( 0 to 7, 0 to 7 ) of INTEGER;
variable i, j, k : INTEGER;
variable InBlock : RF;
variable COSBlock : RF;
variable TempBlock : RF;
variable OutBlock : RF;
variable A, B, P, Sum : INTEGER;
begin
COSBlock := (
( 125, 122, 115, 103, 88, 69, 47, 24 ),
( 125, 103, 47, -24, -88, -122, -115, -69 ),
( 125, 69, -47, -122, -88, 24, 115, 103 ),
( 125, 24, -115, -69, 88, 103, -47, -122 ),
( 125, -24, -115, 69, 88, -103, -47, 122 ),
( 125, -69, -47, 122, -88, -24, 115, -103 ),
( 125, -103, 47, 24, -88, 122, -115, 69 ),
( 125, -122, 115, -103, 88, -69, 47, -24 )
);
--Starting
wait until Start = '1';
Done <= '0';
--Read Input Data
for i in 0 to 7 loop
for j in 0 to 7 loop
wait until Clk = '1' and clk'event;
InBlock(i,j) := Din;
end loop;
end loop;
--TempBlock = COSBLOCK * InBlock
for i in 0 to 7 loop
for j in 0 to 7 loop
Sum := 0;
for k in 0 to 7 loop
A := COSBlock( i, k );
B := InBlock( k, j );
P := A * B;
Sum := Sum + P;
if( k = 7 ) then
TempBlock( i, j ) := Sum;
end if;
end loop;
end loop;
end loop;
--Finishing
wait until Clk = '1' and Clk'event;
Done <= '1';
--Output Data
for i in 0 to 7 loop
for j in 0 to 7 loop
wait until Clk = '1' and Clk'event;
Done <= '0';
Dout <= tempblock(i,j);
end loop;
end loop;
end process;
end behavioral;
测试台文件:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY lab4b_tb IS
END lab4b_tb;
ARCHITECTURE behavior OF lab4b_tb IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT DCT_beh
PORT(
Clk : IN std_logic;
Start : IN std_logic;
Din : IN INTEGER;
Done : OUT std_logic;
Dout : OUT INTEGER
);
END COMPONENT;
--Inputs
signal Clk : std_logic := '0';
signal Start : std_logic := '0';
signal Din : INTEGER;
--Outputs
signal Done : std_logic;
signal Dout : INTEGER;
-- Clock period definitions
constant Clk_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: DCT_beh PORT MAP (
Clk => Clk,
Start => Start,
Din => Din,
Done => Done,
Dout => Dout
);
-- 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
variable i, j : INTEGER;
variable cnt : INTEGER;
begin
-- hold reset state for 100 ns.
wait for 100 ns;
start <= '1';
wait for clk_period;
start <= '0';
for cnt in 0 to 63 loop
wait until clk = '1' and clk'event;
din <= cnt;
end loop;
--wait for 100 ns;
--start <= '1';
--wait for clk_period;
--start <= '0';
--for i in 0 to 63 loop
-- wait for clk_period;
--if (i < 24) then
--din <= 255;
--elsif (i > 40) then
--din <= 255;
--else
--din <= 0;
--end if;
--end loop;
wait;
end process;
END;
从我在 start = 1 时所做的事情开始,矩阵被读入输入块。在这种情况下,矩阵只填充了从 0 到 63 的唯一增量值。然后当完成 = 1 时,我输出 outblock,它是相乘后的矩阵。问题是在我的模拟中,我收到了一些应该在最终矩阵中但顺序不正确的值。例如,下面的行包含相乘矩阵 tempblock 中的第一行:
14464.000 15157.000 15850.000 16543.000 17236.000 17929.000 18622.000 19315.000
正如您在我的模拟图片中看到的那样,我得到了其中一些值,但随后信号变成了一些奇怪的大值。
我有一些疑问,也许 din(0), din(1), din(2)...din(n) 不对应于 inputblock(0,0), inputblock(0,1), inputblock(0, 2)等等。但是我彻底检查了我的行为文件,没有发现任何问题。我设计测试台的方式有问题吗?
编辑:我需要帮助输出这个
din<=0;
for i in 0 to 63 loop
wait until clk = '1' and clk'event;
if i = 0 then
Start <= '1','0' after clk_period;
end if;
if (i < 24) then
din <= 255;
elsif (i > 40) then
din <= 255;
else
din <= 0;
end if;
end loop;
我认为它与答案中的代码相似,但我遇到了同样的问题。这将如何解决?这是当前输出的图片。正确的值在那里,但只是移动了一个时钟周期。
最终编辑:自己解决了。问题在于循环边界。