【问题标题】:VHDL Counter ones errorsVHDL 计数器错误
【发布时间】:2016-02-08 07:45:21
【问题描述】:

我已经完成了代码,它可以工作,但是,当我尝试编写测试台时,我遇到了一些麻烦。输入 x 设置为 8 位,x:IN BIT_VECTOR (N -1 DOWNTO 0)。 当我编写测试台时,我没有输入位数。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
USE ieee.std_logic_unsigned.all;

ENTITY Count_ones IS
   GENERIC (N: INTEGER := 8); -- number of bits
   PORT ( x: IN BIT_VECTOR (N -1 DOWNTO 0); y: OUT NATURAL RANGE 0 TO N);
END ENTITY ;

architecture Behavioral of Count_ones is
    TYPE count is Array (N DOWNTO 1) OF Natural;
    signal a : count;

begin

  a(0) <= 1 when (x(0) = '1')
  else
       0;
  gen: FOR i IN N-1 DOWNTO 0
  GENERATE
            a(i+1) <= (a(i)+1) when (x(i)='0')
            else
                  a(i);
END GENERATE;

y <= a(N-1);

end Behavioral;

测试台:

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;

ENTITY Count_ones_TB IS
END Count_ones_TB;

ARCHITECTURE behavior OF Count_ones_TB IS 


COMPONENT Count_ones
PORT(
     x : IN  std_logic_vector(7 downto 0);
     y : OUT  std_logic_vector(0 to 3)
    );
 END COMPONENT;

--Inputs
signal x : std_logic_vector(7 downto 0) := (others => '0');

--Outputs
signal y : std_logic_vector(0 to 3);


BEGIN

-- Instantiate the Unit Under Test (UUT)
uut: Count_ones PORT MAP (
      x => x,
      y => y
    );

stim_proc: process
begin       

        x <= "00010101";
        wait for 100 ns;    
        x <= "00001001";
        wait for 100 ns;
        x <= "11111111101"
        wait for 100ns;
  -- insert stimulus here 

  wait;
end process;

END;

错误是

实体端口 x 与组件端口的类型 std_logic_vector 不匹配 实体端口 y 与组件端口的 std_logic_vector 类型不匹配

请帮帮我,我真的想不出解决这个问题的方法。

【问题讨论】:

  • 您有三个位置的字符串文字构造不正确,使用单引号而不是双引号。这些字符串值中的第三个值太长了。 x &lt;= "00010101"; -- '00010101';x &lt;= "00001001"; -- 00001001'; 和 `x
  • 我得到了这个---实体端口x与组件端口的std_logic_vector类型不匹配,实体端口y与组件端口的std_logic_vector类型不匹配。
  • 当我尝试模拟波形时,我尝试将 std_logic_vector 更改为 std_logic,但它仍然无法正常工作。非常感谢。,
  • 您的组件声明描述了 std_logic_vector 类型的端口,但您的实体声明描述了 bit_vector 和 natural 的端口。

标签: vhdl


【解决方案1】:

您的具体问题的答案是实体中端口的类型、组件中的端口和信号的类型必须匹配。这是您的代码的link,其中包含这些错误和更多错误。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
USE ieee.std_logic_unsigned.all;

ENTITY Count_ones IS
   GENERIC (N: INTEGER := 8); -- number of bits
   PORT ( x: IN BIT_VECTOR (N -1 DOWNTO 0); y: OUT NATURAL RANGE 0 TO N);
END ENTITY ;

architecture Behavioral of Count_ones is
    TYPE count is Array (N DOWNTO 0) OF Natural;
    signal a : count;

begin

  a(0) <= 1 when (x(0) = '1')
  else
       0;
  gen: FOR i IN N-1 DOWNTO 0
  GENERATE
            a(i+1) <= (a(i)+1) when (x(i)='0')
            else
                  a(i);
END GENERATE;

y <= a(N-1);

end Behavioral;

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;

ENTITY Count_ones_TB IS
END Count_ones_TB;

ARCHITECTURE behavior OF Count_ones_TB IS 


COMPONENT Count_ones
   GENERIC (N: INTEGER := 8); -- number of bits
   PORT ( x: IN BIT_VECTOR (N -1 DOWNTO 0); 
          y: OUT NATURAL RANGE 0 TO N); 
END COMPONENT;

--Inputs
signal x : BIT_VECTOR(7 downto 0) := (others => '0');

--Outputs
signal y : natural;


BEGIN

-- Instantiate the Unit Under Test (UUT)
uut: Count_ones PORT MAP (
      x => x,
      y => y
    );

stim_proc: process
begin       

        x <= "00010101";
        wait for 100 ns;    
        x <= "00001001";
        wait for 100 ns;
        x <= "11111101";
        wait for 100ns;
  -- insert stimulus here 

  wait;
end process;

END;

但是,我必须指出,您距离尝试计算数量的目标还有很长的路要走。

因为:

  1. 我对您的代码的更正并不是唯一正确的答案。在 事实上,我的更正甚至不是一个好的答案。我只是做了 使您的代码编译和运行的最小更正。你需要 仔细考虑您的所有端口和信号的类型 设计应该是。
  2. 我的更正不会使您的代码正常工作,即计算 那些。

【讨论】:

  • 上述代码不需要提供的上下文子句。
  • 当我看到它正确时,修复很简单。它必须在for ... generate 中读取when (x(i)='1')。如果您至少列出您所做的所有更正,那就更好了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-19
  • 2015-01-28
  • 1970-01-01
  • 2015-04-04
  • 2015-04-25
  • 2020-05-13
相关资源
最近更新 更多