【问题标题】:VHDL: converting an std_logic_vector to an integer (works in simulation, not practice)VHDL:将 std_logic_vector 转换为整数(在模拟中工作,而不是实践)
【发布时间】:2015-04-29 08:48:40
【问题描述】:

过去两天我一直在与这个问题作斗争。在这种情况下,我希望 data_out 发送“111”,看看整个内存是如何被“1”填充的。我将显示代码,然后使问题更精确:

entity tile_library is
  Port (
    data_out : out std_logic_vector(2 downto 0);
    data_in : in std_logic_vector(5 downto 0);
    clk : in std_logic);

end tile_library;

architecture Behavioral of tile_library is

type memory_type is array (0 to 63) of std_logic_vector(255 downto 0);
signal memory : memory_type := (others=> (others=>'1'));
signal something_to_convert : std_logic_vector(5 downto 0) := "000000";


begin
  process(clk) begin
  if rising_edge(clk) then
    if memory(to_integer(unsigned(data_in)))(5) = '1' then
      data_out <= "111";
    else
      data_out <= "000";
    end if;

  end if;
end process;


end Behavioral;

如果我替换

    if memory(to_integer(unsigned(data_in)))(5) = '1' then

    if memory(to_integer(unsigned(something_to_convert)))(5) = '1' then

我的 nexys 3 卡上的输出是“111”。

这让我相信 data_in 不是它应该的样子。

因此,我向您展示了在我的测试中生成 data_in 到 tile_library 的代码:

entity tile_memory is
  Port (
    data_out : out std_logic_vector(5 downto 0);
    clk : in std_logic);

end tile_memory;

architecture Behavioral of tile_memory is

begin
  process(clk)
  begin
   if rising_edge(clk) then
     data_out <= "000000";

   end if;
  end process;

end Behavioral;

为了进一步混淆,我可以补充一点,根据模拟if memory(to_integer(unsigned(data_in)))(5) = '1' then 和 @ 我得到完全相同的输入和输出信号(也是正确的,“111”) 987654326@。当我在我的 Nexys 3 卡上运行它时;但是,它们会产生不同的结果。

我在这里做错了什么?

【问题讨论】:

  • 这一行:signal memory : memory_type := (others=&gt; (others=&gt;'1')); 包含内存的预初始化,在综合中可能不支持。出于诊断目的,为什么不直接发送data_in 而不必担心它可能是什么?
  • 如果不替换,您没有指出输出是什么。 @BrianDrummond 指出的情况更糟。您的内存类型 memory_type 被初始化为 std_logic_vector 的所有 '1' 的所有 256 个元素,这是所有 64 个位置的元素类型。除非您有某种方式将不同的值写入内存,否则它可以被优化掉。从字面上看,data_in 是不是无关紧要,而且它也可能在综合中被优化掉,它总是全 0。

标签: vhdl fpga


【解决方案1】:

没有错

signal memory : memory_type := (others=> (others=>'1'));

在赛灵思软件中,它一直对我有用。

我建议使用chipscope 并在您要查看的信号上放置一个keep/mark_debug 属性,因为正如其他人指出的那样,它将被优化。但这并不意味着您应该得到错误的结果。

data_out 对于第一个时钟周期应该是“000”(由于 Xilinx 综合假设),然后对于连续的时钟周期应该是“111”。

如果综合把它塞进去,我的猜测是它不喜欢将 ram 操作作为 if 语句的一部分(我个人以前从未见过它)。尝试将其从 if 语句中取出(如下所示)。这不应该是必需的,但 XST 在识别内存/乘数等方面可能相当敏感。

您也可以查看合成后的原理图/仿真,但我建议先使用chipscope。

entity tile_library is
  Port (
    data_out : out std_logic_vector(2 downto 0);
    data_in : in std_logic_vector(5 downto 0);
    clk : in std_logic);

end tile_library;

architecture Behavioral of tile_library is

type memory_type is array (0 to 63) of std_logic_vector(255 downto 0);
signal memory : memory_type := (others=> (others=>'1'));
signal something_to_convert : std_logic_vector(5 downto 0) := "000000";
signal memory_read_data : std_logic_vector(255 downto 0);

begin
  memory_read_data <= memory(to_integer(unsigned(data_in)));
  process(clk) begin
  if rising_edge(clk) then
    if memory_read_data(5) = '1' then
      data_out <= "111";
    else
      data_out <= "000";
    end if;

  end if;
end process;


end Behavioral;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    相关资源
    最近更新 更多