【发布时间】:2018-02-28 09:53:14
【问题描述】:
我有一个用 VHDL 编写的非常简单的“程序”
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std;
entity Xand is
generic(width : integer:=8);
port( clk : in std_logic;
A,B : in std_logic_vector(width-1 downto 0);
C : out std_logic_vector(width-1 downto 0)
);
end Xand;
architecture Behavioral of Xand is
begin
C<= A and B;
end Behavioral;
我的实际测试台如下所示:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
use ieee.numeric_std.all;
ENTITY Xand_tb IS
--generic(width : integer);
END Xand_tb;
ARCHITECTURE behavior OF Xand_tb IS
COMPONENT Xand IS
generic(width : integer);
port( clk : in std_logic;
A,B : in std_logic_vector(width-1 downto 0);
C : out std_logic_vector(width-1 downto 0)
);
end COMPONENT;
signal width : integer := 8;
-- inputs
signal clk : std_logic := '0';
signal A, B : std_logic_vector(width-1 downto 0) := (others => '0');
--Outputs
signal C : std_logic_vector(width-1 downto 0);
constant period : time := 10 ns;
BEGIN
-- instantiate the Unit Under Test (UUT)
uut: Xand generic map (width => 8)
PORT MAP (
clk => clk,
A => A,
B => B,
C => C
);
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 100 ns;
wait for period*10;
for i in 0 to 2**width loop
A <= std_logic_vector( unsigned(A) + 1 );
for j in 0 to 2**width loop
B <= std_logic_vector( unsigned(B) + 1 );
wait for period;
end loop;
for j in 0 to width loop
B(j) <= '0';
end loop;
wait for period;
end loop;
wait;
end process;
END;
很遗憾我得到了错误(当我想用 --vcd=xand.vcd 模拟它时)。
ghdl:error: overflow detected
from: process work.xand_tb(behavior).stim_proc at Xand_tb.vhd:57
ghdl:error: simulation failed
B(j) <= '0'; 行不工作。据我了解,A 和 B 是具有 8 位的向量。所以我想用来自 [0,256) 的不同 A 和 B 值来测试我的 Xand 程序。可悲的是,我不知道如何使向量 B 等于 0 与循环不同的方式,这是行不通的。
有人可以解释一下我的 generic() 是做什么的吗?
【问题讨论】:
-
您需要驱动输入信号。您是否尝试过这样做,如果是,出了什么问题?
-
您的问题是什么?您是否正在寻找像 Modelsim 或 GHDL 这样的仿真工具? “不清楚你在问什么。”
-
@scary_jeff 我想我做到了,编辑了我的问题。你介意再看一遍吗?
-
你定义
B : in std_logic_vector(width-1 downto 0);。然后循环j in 0 to width,所以j将在某个时候成为width。因此,您分配的B(width)超出范围... -
离题了,但是关于“to”这个词:通常不清楚范围是包括还是不包括最终数字。您实际上应该写“直到并包括”,但这在编程中是不切实际的。