loops - vhdl比较向量输出

标签 loops testing vector vhdl

我有一个 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-1i 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/

相关文章:

Python:如何迭代文本文件中行中的特定列

r - 优化 R 中的循环

ruby-on-rails - 无法访问类 nil Rails 4 的对象

testing - 为另一个操作系统重新编译软件时要测试什么?

c++ - 优化用 fftw_malloc() 分配的两个 std::vector<std::complex<float>> 的逐元素乘积

c++ - 如何使用循环将 vector 插入队列<vector<int>>?

python - 以特定方式迭代多维数组

string - 测试字符串是否包含文字星号

sql - 做性能测试时如何避免出现SQL Server的 "rebuild statistics"?

r - 在 R 中有效地创建向量的困惑