我有一个 64 位长的向量 A,我希望输出 B 等于 3,而 A 为 30-35,其他地方为零。我有点想不出测试平台来循环遍历向量 A。我尝试了几种不同的方法,但只得到数组的 1/5 来提供任何输出。这是我在没有语法/编译错误的情况下所能得到的。
主要代码
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.ALL;
entity ent is
port(A:in std_logic_vector(5 downto 0);
B:out std_logic_vector(3 downto 0));
end ent;
architecture arch_ent of ent is
begin
with A select
B <= "0011" when "011110",
"0011" when "011111",
"0011" when "100000",
"0011" when "100001",
"0011" when "100010",
"0011" when "100011",
"0000" when others;
end arch_ent;
测试平台
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity tb is
end tb;
architecture arch_tb of tb is
component ent
port(A:in std_logic_vector(5 downto 0);
B:out std_logic_vector(3 downto 0));
end component;
signal A_tb: std_logic_vector(5 downto 0);
signal B_tb: std_logic_vector(3 downto 0);
begin
uut: entity ent port map(A=>A_tb, B=>B_tb);
tb: process
constant period: time := 20ns;
begin
for i in A_tb'range loop
A_tb <= std_logic_vector(to_unsigned(i,6));
wait for period;
assert (B_tb = "0011")
report "test failed" severity error;
end loop;
wait;
end process;
end arch_tb;
最后我试图绘制出这样的波形: http://i10.photobucket.com/albums/a142/blargonblop/wave.png
其中 A 将变为 63,并且每个输出都是其从 30-35 到其他地方的 0 的正确值
最佳答案
你用来指定'tests'数量的循环参数是A_tb'range,恰好是5 downto 0,或者6个tests,i依次赋值为5,4,3,2,1和0。
您想指定 i in 0 to 2**A-tb'length-1
或 i in 0 to 63
以获得所有 64 个可能的 A_tb 'binary'值(value)观。
(A_tb'length = 6, 2**
6-1 = 63,其中**
为求幂运算符,2的6次方减1等于63 )
我在您的测试台中发现了两个语法错误,20ns,其中标准要求 20 和 ns 之间有一个空格:
constant period: time := 20 ns;
实体 ent 应该只是 ent(你有一个组件声明 ent)或实体 work.ent 而不需要组件声明:
uut: ent port map(A=>A_tb, B=>B_tb);
或
uut: entity work.ent port map(A=>A_tb, B=>B_tb);
并且与 Russell 的回答保持一致,除了通过通过并行逻辑(复制)解开循环迭代的综合之外,循环中没有隐含的逻辑复制。并非所有循环语句都旨在作为综合目标。
测试台通常不会综合,用于为可能用作综合目标的 VHDL 模型编写测试(如您的情况)。
关于loops - vhdl比较向量输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22949629/