2017-09-23 78 views
1

enter image description here串联STD_LOGIC到测试平台内STD_LOGIC_VECTOR在VHDL

这是我4比1 MUX的简单示意图。和我连接LOGIC到LOGIC_VECTOR时遇到问题...

这里是我的测试台代码。我只是想展示MUX的所有可能输入的性能。它编译得很好,但它不像我预期的那样工作。 我猜新声明的矢量“X”和“我”是不是与原理的实际输入链接

LIBRARY ieee; 
USE ieee.std_logic_1164.ALL; 
use ieee.std_logic_unsigned.all; 
USE ieee.numeric_std.ALL; 
LIBRARY UNISIM; 
USE UNISIM.Vcomponents.ALL; 
ENTITY MUX_SCHE_MUX_SCHE_sch_tb IS 
END MUX_SCHE_MUX_SCHE_sch_tb; 
ARCHITECTURE behavioral OF MUX_SCHE_MUX_SCHE_sch_tb IS 

    COMPONENT MUX_SCHE 
    PORT(X3 : IN STD_LOGIC; 
      X2 : IN STD_LOGIC; 
      X1 : IN STD_LOGIC; 
      X0 : IN STD_LOGIC; 
      I0 : IN STD_LOGIC; 
      I1 : IN STD_LOGIC; 
      Y : OUT STD_LOGIC); 
    END COMPONENT; 

    SIGNAL X3 : STD_LOGIC := '0'; 
    SIGNAL X2 : STD_LOGIC := '0'; 
    SIGNAL X1 : STD_LOGIC := '0'; 
    SIGNAL X0 : STD_LOGIC := '0'; 
    SIGNAL I0 : STD_LOGIC := '0'; 
    SIGNAL I1 : STD_LOGIC := '0'; 
    SIGNAL Y : STD_LOGIC; 

    ---------- New Variable ---------- 
    SIGNAL X : STD_LOGIC_VECTOR(3 downto 0); 
    SIGNAL I : STD_LOGIC_VECTOR(1 downto 0); 
    SIGNAL j : integer := 0; 
    SIGNAL k : integer := 0; 

BEGIN 

    X <= X3 & X2 & X1 & X0; 
    I <= I1 & I0; 
    UUT: MUX_SCHE PORT MAP(
     X3 => X3, 
     X2 => X2, 
     X1 => X1, 
     X0 => X0, 
     I0 => I0, 
     I1 => I1, 
     Y => Y 
    ); 

-- *** Test Bench - User Defined Section *** 
    tb : PROCESS 
    BEGIN 
    X <= "0000"; 
    I <= "00"; 
     while(j<4) loop 
      while(k<8) loop 
       X <= X + '1'; WAIT FOR 10 NS; 
      end loop; 
      I <= I + '1'; WAIT FOR 10 NS; 
     end loop; 

    END PROCESS; 
-- *** End Test Bench - User Defined Section *** 

END; 
+1

您对X和I的分配似乎是错误的方式,使DUT端口没有值。简单地删除信号X3等并将端口映射为'X => X(3),'等等 –

回答

1

由于布赖恩注意到X(和I)的分配是不正确的。

还有的情况是,X总是'X的,有两个驱动程序。并发信号分配给X和未标记过程中的分配。此外,未标记的进程将不会成功初始化X,因为在第一次赋值为“0000”和内部while循环中的第一次赋值之间没有中断该进程的中止。

你也可以注意到,没有分配给J和K这意味着你将永远不会结束内部while循环,并提供一

克服本测试平台的问题,还可能涉及简化不同的值:

library ieee; 
use ieee.std_logic_1164.all; 

entity mux_sche_tb is 
end entity mux_sche_tb; 

architecture foo of mux_sche_tb is 
    use ieee.numeric_std.all; 
    component mux_sche 
     port ( 
      x3: in std_logic; 
      x2: in std_logic; 
      x1: in std_logic; 
      x0: in std_logic; 
      i0: in std_logic; 
      i1: in std_logic; 
      y: out std_logic 
     ); 
    end component; 

    -- signal x3:  std_logic := '0'; 
    -- signal x2:  std_logic := '0'; 
    -- signal x1:  std_logic := '0'; 
    -- signal x0:  std_logic := '0'; 
    -- signal i0:  std_logic := '0'; 
    -- signal i1:  std_logic := '0'; 
    signal y: std_logic; 

    -- ---------- new variable ---------- 
    signal x: unsigned(3 downto 0); 
    signal i: unsigned(1 downto 0); 
    -- signal j: integer := 0; 
    -- signal k: integer := 0; 

begin 

    -- x <= x3 & x2 & x1 & x0; 
    -- i <= i1 & i0; 

uut: 
    mux_sche 
     port map (
      x3 => x(3), 
      x2 => x(2), 
      x1 => x(1), 
      x0 => x(0), 
      i0 => i(0), 
      i1 => i(1), 
      y => y 
     ); 

tb: 
    process 
    begin 
    -- x <= "0000"; 
    -- i <= "00"; 
     wait for 10 ns; -- show initial state 
     for j in 0 to 3 loop 
      I <= to_unsigned(j, 2); 
      for k in 0 to 15 loop 
       X <= to_unsigned(k, 4); 
       wait for 10 ns; 
      end loop; 
     end loop; 
     wait; 
     -- while(j < 4) loop 
     --  while(k < 8) loop 
     --   x <= x + '1'; 
     --   wait for 10 ns; 
     --  end loop; 
     --  i <= i + '1'; 
     --  wait for 10 ns; 
     -- end loop; 

    end process; 
end architecture; 

而不是while循环语句中使用while循环迭代方案。 布赖恩的分配X的元素的建议扩展到I,并且只提供一个分配给任一元素,以消除多个驱动程序。

使包中的ieee.numeric_std中的声明可见的use子句移动到允许分析原始体系结构的体系结构(并且它是允许在Synopsys软件包中找到声明的use子句ieee.std_logic_unsigned被移动到它的体系结构声明区域)。

for循环迭代器是在循环语句迭代方案中隐式声明的变量,并将其默认类型的整数转换为无符号X和I.

未签名的X和I的元素与mux_sche的std_logic正式端口具有相同的基本类型,并且可以用作实际值(正如Brian所建议的那样)。

提供必须提供Minimal, Complete and Verifiable example兼容mux_sche:

library ieee; 
use ieee.std_logic_1164.all; 

entity mux_sche is 
    port (
     X3: in std_logic; 
     X2: in std_logic; 
     X1: in std_logic; 
     X0: in std_logic; 
     I0: in std_logic; 
     I1: in std_logic; 
     Y: out std_logic 
    ); 
end entity; 

architecture foo of mux_sche is 

begin 
    process (X3, X2, X1, X0, I0, I1) 
    variable I: std_logic_vector (1 downto 0); 
    begin 
     I := TO_X01(I1 & I0); 
     case I is 
      when "00" => 
       Y <= TO_X01(X0); 
      when "01" => 
       Y <= TO_X01(X1); 
      when "10" => 
       Y <= TO_X01(X2); 
      when "11" => 
       Y <= TO_X01(X3); 
      when others => 
       Y <= 'X'; 
     end case; 
    end process; 
end architecture; 

如果是这样的测试设计前分析和测试平台进行了分析,阐述和模拟,我们结束了:

changed.png

显示没有X's并增加了X和I.

这个测试台版本依赖于numeric_std包to_unsigned自然范围整数的转换,注意到X和我有循环迭代方案隐式声明中指定的范围。

是否可以使用原始测试台?不适用于j和k的阈值测试。什么将发生是k将经过8次迭代之后J到4次迭代打算:

enter image description here

使用而具有信号迭代循环比使用具有可变迭代循环强硬一点。

0

有在你的代码的两个问题:第一,X <= X3 & X2 & X1 & X0;会连接到X3X0分配结果X 。在tb的过程中,您再次分配到X,创建通常称为“多个驱动程序”的内容,即。代码的多个部分驱动(可能不同)值到相同的信号。在编写良好的VHDL代码中,这很少是您想要的。

VHDL通过使用分辨率函数处理多个驱动程序:将函数应用于驱动到信号的所有值,然后将其输出写入信号;请参阅this以了解所使用的分辨率表。

我反对使用解决类型stronly建议,如std_logicstd_logic_vector,去他们的悬而未决的吊坠std_ulogicstd_ulogic_vector(注意u);如果你已经使用过这些,那么在阐述过程中就会发现你的错误。

第二,如评论中所述,X3X0从未被分配任何值,保留为U