Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 比较矢量输出_Loops_Testing_Vector_Vhdl - Fatal编程技术网

Loops 比较矢量输出

Loops 比较矢量输出,loops,testing,vector,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:

我有一个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;
IEEE库;
使用IEEE.STD_LOGIC_1164.all;
使用IEEE.NUMERIC_STD.ALL;
实体ent是
端口(A:标准逻辑向量(5到0);
B:输出标准逻辑向量(3到0);
结束耳鼻喉科;
耳鼻喉科的建筑拱门是
开始
选择
B A_tb,B=>B_tb);
tb:过程
恒定周期:时间:=20ns;
开始
对于i,在A_tb'范围循环中

A_tb您真的不应该为此使用for循环。因为VHDL中的循环用于复制逻辑,而不是多次执行某些操作。在您的测试台上尝试以下操作:

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_时钟:标准逻辑:='0';
信号r_索引:无符号(5到0):=(其他=>0');
开始

r_CLOCK用于指定“测试”数量的循环参数是一个_tb”范围,恰好是5到0,或者六个测试,i依次被分配为5、4、3、2、1和0

您希望在0到2**A-tb'length-1中指定
i,或在0到63中指定
i,以获取所有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);

与Russell的答案一致,循环中没有隐含的逻辑复制,除了通过并行逻辑分解循环迭代的合成(复制)。并非所有的循环语句都打算作为合成目标


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

首先,循环在测试台上很好,很常见@Russell的评论适用于RTL代码。你可以调整他的方法来解决这个问题,让它发挥作用。您需要使用64作为sentinel(结束)值,然后进行测试结束检查。请记住,您所做的最重要的事情是代码的可读性。测试用例通常从流程的顶部到底部运行一次

除了@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; 
ieee库;
使用ieee.std_logic_1164.all;
使用ieee.numeric_std.all;
使用ieee.numeric\u std\u unsigned.all;
实体结核是
结束结核病;
tb的体系结构是
恒定周期:时间:=20ns;
...
开始
...
tb:过程
变量错误计数:
开始
对于0到2**A-tb'长度为1的i中的i

A_tb=30,我确实看到了一些时钟想法的例子,这肯定是有意义的,但我认为我需要一个循环来检查输出的每一位,这样它就知道什么时候是它需要的值。啊,我总是一个粗心的错误。我对组件的使用不太熟悉。我一直在搜索尝试几种方法,这是少数几个可以编译的方法之一。顺便说一句,我修改了循环范围(0到2**A-tb'length-1中的I),修改了您的报告语句(report integer'image(I)&“test failed”),以显示除30到35之外的I和0到63。您可以颠倒断言表达式(B_tb/=“0011”)中的含义,只获取30到35的报告。你用的是什么VHDL工具,它不关心20到ns之间的空间?好的,再花一两个小时,它就可以工作了。非常感谢!顺便说一句,我使用的是Aldec学生版
uut: entity work.ent port map(A=>A_tb, B=>B_tb);
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;