繁体   English   中英

vhdl比较向量输出

[英]vhdl comparing vector output

我有一个向量A,它的长度为64位,我希望输出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

用于指定“测试”数量的循环参数是A_tb'范围,恰好是5到0,或6个测试,i依次被分配为5,4,3,2,1和0。

您想要i in 0 to 2**A-tb'length-1指定i in 0 to 2**A-tb'length-1i in 0 to 63指定i in 0 to 2**A-tb'length-1以获取所有64个可能的A_tb'binary'值。

(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);

而且,与罗素的答案保持一致,除了通过综合(通过并行化逻辑(复制)解开循环迭代)的合成之外,循环中没有隐含的逻辑复制。 并非所有循环语句都旨在用作综合目标。

测试台通常不进行合成,而是用于编写可能用作合成目标的VHDL模型的测试(如您的情况)。

您确实不应该为此使用for循环。 VHDL中的for循环用于REPLICATE LOGIC,而不是多次执行操作。 在测试台上尝试以下操作:

signal r_CLOCK : std_logic := '0';
signal r_INDEX : unsigned(5 downto 0) := (others => '0');

begin

  r_CLOCK <= not r_CLOCK after period/2;

  process (r_CLOCK)
  begin
    if rising_edge(r_CLOCK) then
      r_INDEX <= r_INDEX + 1;
    end if;
  end process;

现在,只需将r_INDEX转换为std_logic_vector并将其传递给您的ent组件。

首先,循环在测试平台中是正常的并且很常见。 @Russell的注释适用于RTL代码。 您可以采用他的方法来解决此问题并使之起作用。 您将需要使用64作为前哨(结束)值,然后结束测试。 请记住,尽管您要做的最重要的事情是代码的可读性。 测试用例通常一次从流程的顶部到底部运行。

除了@DavidKoontz提供的建议之外,您的循环还有一些问题。 特别,

  • 当您期望B为0时,不应检查您的断言。
  • 使用numeric_std_unsigned(需要VHDL-2008编译开关)将简化转换。
  • 保持错误计数,以便最后报告通过或失败。
  • 将常量保持在体系结构或程序包中

因此,修改后的代码为:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.numeric_std_unsigned.all;

entity tb is
end tb;

architecture arch_tb of tb is
  constant period: time := 20 ns;
...
begin
...

tb: process 
  variable ErrorCount : 
begin
  for i in i in 0 to 2**A-tb'length-1
    A_tb <= to_slv(i,6);
    wait for period;
    if i >= 30 and i <= 35 then 
      if B_tb /= 3 then 
        ErrorCount := Error Count + 1 ; 
        report "B_tb = " & to_string(B_tb) & "  Expecting: 0011" severity ERROR ; 
      end if; 
    else 
      if B_tb /= 0 then 
        ErrorCount := Error Count + 1 ; 
        report "B_tb = " & to_string(B_tb) & "  Expecting: 0000" severity ERROR ; 
      end if; 
  end loop;   
  if ErrorCount = 0 then 
    report "Test Passed" severity NOTE ; 
  else
    report "Test FAILED.  There were " & to_string(ErrorCount) & " Errors " severity NOTE; 
  end if; 
  std.env.stop(0) ; -- testbench stops here
end process; 

请注意,有关使用(或禁止使用)numeric_std_unsigned的规则不适用于测试平台。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM