我有一个VHDL问题:对于一项家庭作业,我们必须为我们的VHDL设计电路编写一个带有断言的测试台。我们应该为for比较器测试每个信号组合。我想用for循环来解决这个问题,就像这样:
architecture ts of testbench is
signal a: std_logic_vector(3 downto 0) := "0000";
signal b: std_logic_vector(3 downto 0) := "1011";
signal c1, c0: std_logic := '0';
begin
TEST: entity forBitVergleicher port map(a, b, c1, c0);
for i in 0 to 2**n loop
k for k in 0 to 2**n loop
a <= std_logic_vector(i); b <= std_logic_vector(k);
assert(unsigned(a) > unsigned(b) and (c1 = '0' or c0 =
'1') and (c1 = '0' and c0 = '0') and (c1 = '1' and c0 =
'0'))
report "error";
assert(unsigned(b) > unsigned(a) and (c1 = '1' and c0 =
'0' or c1 = '0' and c0 = '0' or c1 = '1' and c0 = '0'))
report "error";
assert(a = b and ((c1 = '1' and c0 = '1') or (c1 /= c0)))
report "error";
首先,我在Python中测试了这个想法(用于循环等),以检查它是否有效(确实有效)。好吧,现在我不知道为什么我的VHDL代码不起作用。我有很多错误报告,这些报告在我看来是没有道理的。 有任何想法吗?
COMP96错误COMP96_0329:“生成的语句必须具有标签。” “ testbench.vhd” 18 3 COMP96错误COMP96_0019:“预期关键字'generate'。” “ testbench.vhd” 18 22 COMP96错误COMP96_0661:“不允许使用一系列不同的逻辑运算符进行表达。括号中的子表达式包含and或or,xor和xnor运算符。” “ testbench.vhd” 28 9 COMP96错误COMP96_0016:“预期设计单元声明。” “ testbench.vhd” 35 4
如果您需要我提供整个VHDL代码的链接: https://www.edaplayground.com/x/4c2n
答案 0 :(得分:-1)
您不能在进程(或函数/过程)之外使用for ... loop
。您应该将for ... loop
放入进程(或函数/过程)中,或使用for ... generate
循环。
但是,如果您使用for ... generate
循环(在进程外部),则请注意该循环必须具有标签(如错误消息之一所述)。例如:
loop_label : for i in 0 to 2**n generate
...
end generate;
在您的特定情况下,建议您在进程内部使用for ... loop
(最后使用wait
语句)。
您的代码还有很多其他问题,但这至少将帮助您克服第一个错误。
要研究的其他一些问题:
n
尚未定义。k for k in ...
应该是for k in ...
0 to 2**n
将循环2 ** n + 1次。您可能需要0 to 2**n-1
。std_logic_vector(i)
和std_logic_vector(k)
是非法的。您可能需要std_logic_vector(to_unsigned(i, 4))
等。severity
。例如,assert <something> report "error" severity failure;
您的缩进不正确,这会使您更容易出错。您的循环应该像这样缩进:
for i in 0 to 2**n-1 loop
for k in 0 to 2**n-1 loop
a <= std_logic_vector(to_unsigned(i, 4));
b <= std_logic_vector(to_unsigned(k, 4));
...
end loop;
end loop;
<a> and <b> or <c>
是没有意义的,将被编译器拒绝。您是说(<a> and <b>) or <c>
还是<a> and (<b> or <c>)
。重要的是要了解您想要的并适当地加上括号。