【问题标题】:VHDL signal assignment leads to uninitialized stateVHDL 信号分配导致未初始化状态
【发布时间】:2013-11-10 08:29:24
【问题描述】:

我正在用 VHDL 实现两个数字相乘(以无符号 2 的补码形式)的 Booth 算法。不幸的是,我的 VHDL 很差,无法弄清楚我哪里出错了。

问题:在逐步完成模拟时,我注意到当我分配了一个将“1011”的值设置为 y,信号 mult 得到“0UUU”。我不明白为什么会这样。这是我的代码:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

-- x, y are the n bit numbers to be multiplied.
-- The Algorithm :
-- U = 0, prev_bit = 0;
-- for i = 1 to n do
-- if start of a string of 1's in Y then U = U - X
-- if end of a string of 1's in Y then U = U + X
-- Arithmetic right shift UV
-- Circular right shift Y and copy Y(0) to prev_bit

entity booth is 
  generic(N : natural := 4);
  port(
    x, y : in std_logic_vector(N-1 downto 0);
    result : out std_logic_vector(2*N-1 downto 0);
    clk : in std_logic 
  );
end booth;

architecture booth_arch of booth is
  --temp is equivalent to UV where UV is the result.
  signal temp : std_logic_vector(2*N-1 downto 0) := (others => '0');
  --prev_bit to compare for starting and ending of strings of 1's.
  signal prev_bit : std_logic := '0';
  signal mult : std_logic_vector(N-1 downto 0);

  begin 
    process(x, y)
      begin
        mult <= y;
        prev_bit <= '0';
        for i in 0 to N-1 loop  
          if(mult(0) = '1' and prev_bit = '0') then   --start of a string of 1's
            temp(2*N-1 downto N) <= std_logic_vector(unsigned(temp(2*N-1 downto N)) + unsigned(not(x)) + 1);
          elsif(mult(0) = '0' and prev_bit = '1') then --end of a string of 1's
            temp(2*N-1 downto N) <= std_logic_vector(unsigned(temp(2*N-1 downto N)) + unsigned(x));
          end if;      
        prev_bit <= mult(0);
        mult(N-2 downto 0) <= mult(N-1 downto 1);   --circular right shift y.
        mult(N-1) <= prev_bit;
        temp(2*N-2 downto 0) <= temp(2*N-1 downto 1);  --arithmetic right shift temp.
       end loop; 
       result <= temp; 
  end process;     
end booth_arch;

P.S : clk 信号在这里是多余的。我还没用过。

【问题讨论】:

    标签: vhdl


    【解决方案1】:

    如果您的端口和内部信号未签名,请先声明它们unsigned。至少您使用的是正确的 numeric_std 库。使用强类型系统而不是与之对抗!

    然后您可能需要在每次乘法开始时初始化Temp(就像您已经为Mult, Prev_Bit 所做的那样),而不是在模拟开始时初始化一次。目前,Temp 似乎有可能包含来自先前乘法的陈旧值(例如 UUUU * UUUU)。

    第三,您告诉我们您分配给Y 的内容,但我们还不知道您分配给X 的内容,据我所知,它仍然可能是UUUU

    编写一个最小的 VHDL 测试台并将其添加到问题中将是获得进一步帮助的好方法 - 或者更有可能是自己发现问题的真正原因!

    【讨论】:

      【解决方案2】:

      除了 Brian 的 cmets:您在同一个组合过程中读取和写入信号 mult。除非你的真的知道你在做什么,否则你不应该这样做。综合后,你会得到与你的模拟器所做的不对应的东西。

      此外,您应该知道,您分配给mult 的值(在您的流程的第一行中)在流程完成并开始新的迭代之前不会可见。在 VHDL 语言中,我们说新值在一个 delta 周期之后可用。

      【讨论】:

      • 真的知道你在做什么”你的意思是:我们记住 mult 信号在我们读取它时仍然保持旧值,即使我们分配一个新的价值吗?我也是初学者...
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-23
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-09
      • 1970-01-01
      相关资源
      最近更新 更多