代码之家  ›  专栏  ›  技术社区  ›  Seung Jin Lee

在VHDL测试台内将STD\U逻辑连接到STD\U逻辑矢量

  •  2
  • Seung Jin Lee  · 技术社区  · 7 年前

    enter image description here

    这是我的测试台代码。我只想展示多路复用器在所有可能输入下的性能。它编译得很好,但没有像我预期的那样工作。

    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;
    
    2 回复  |  直到 7 年前
        1
  •  1
  •   user1155120 user1155120    7 年前

    正如Brian所指出的,对X(和I)的赋值是不正确的。

    还有一种情况是,X始终都是X,有两个驱动因素。对X的并发信号分配和未标记过程中的分配。此外,未标记的进程将无法成功初始化X,因为在第一次分配到“0000”和内部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循环。 Brian关于分配X元素的建议扩展到了I,并且只为其中一个元素提供了一个分配,从而消除了多个驱动因素。

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

    无符号X和I的元素与mux\u sche的std\u逻辑形式端口具有相同的基类型,可以用作实际值(正如Brian建议的那样)。

    提供一个 Minimal, Complete and Verifiable example 必须提供兼容的mux\U SCH:

    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\u std包到自然范围整数的无符号转换,注意X和I的范围在循环迭代方案隐式声明中指定。

    可以使用原始测试台吗?没有对j和k进行阈值测试。将发生的是,k将经历8次迭代,然后j将经历4次迭代:

    enter image description here

    将while循环与信号迭代器结合使用比将for循环与变量迭代器结合使用要困难一些。

        2
  •  0
  •   rainer    7 年前

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

    :将函数应用于驱动到信号的所有值,然后将其输出写入信号;看见 this 对于使用的分辨率表。

    我强烈建议不要使用解析类型,例如 std_logic std_logic_vector 去找他们悬而未决的悬案 std_ulogic std_ulogic_vector (注意 u

    第二,正如评论中提到的那样, X3 从未分配任何值,将其保留为 U