2013-10-25 67 views
0

我有一个名为amux的数组,我想在数组内保存整数倍的信号A。下面的伪代码给出了一个想法:用信号值的整数倍填充一个数组

amux(0) <= "00001101"; 
amux(1) <= amux(0); 

.... 

amux(n) <= amux(n-1); 

我完整的代码看起来是这样的:

-- n is 4 and m is 3, amux is an array, mzeros is 0's 
regA: process(clk) 
variable r : integer := 2**m; 
begin 
    if rising_edge(clk) then 
     if ld_a = '1' then 
      amux(0) <= std_logic_vector(to_unsigned((0),n*m+m)); 
      amux(1) <= mzeros & A; 

      for i in 2 to r-1 loop 
       if (i mod 2) = 0 then 
        amux(i) <= amux(i/2)(n*m+m-2 downto 0) & '0'; 
       else 
        amux(i) <= std_logic_vector(unsigned(amux(i-1))+unsigned(amux(1))); 
       end if; 
      end loop; 

     end if; 
    end if; 

结束进程雷加;

我目前的实现输出所有“00000000”,除了amux(0)。我的方法有什么问题?

+1

需要更多的上下文:发布一个小的完整的可编译示例。 –

+0

只是猜测,但听起来像你期望的“00001101”波及到所有amux(1).. amux(n)。然而,这不是'<='在VHDL中的工作方式,因为在下一个模拟周期之前,用'<='指定给amux(0)的值是不可见的,所以分配给amux(1)使用当前“old”)amux(0)的值,它可能全是“00000000”,并且对于其余的amux分配类似。 –

+0

我想要保存数组中信号A的整数倍数 – hassicho

回答

0

如果我们正确地理解了您的话,问题是您不能在一个过程中立即使用一个信号的值,然后再对它进行分配。分配的值只有在过程完成后才可用。如果这是你想要做的,你可以使用一个变量来达到这个目的。变量的值立即更新。

你想要的东西下面的代码示例应接近:

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

entity array_loader is 
    generic (
     N: integer := 4; 
     M: integer := 3; 
     DATA_WIDTH: integer := N * M + M; 
     ARRAY_DEPTH: integer := 2**M 
    ); 
    port (
     clk: in std_logic; 
     ld_a: in std_logic; 
     A: in unsigned(DATA_WIDTH-1 downto 0) 
    ); 
end; 

architecture rtl of array_loader is 
    type amux_type is array (0 to ARRAY_DEPTH-1) of unsigned(DATA_WIDTH-1 downto 0); 
    signal amux: amux_type; 

begin 
    regA: process(clk) 
     variable multiple: unsigned(DATA_WIDTH-1 downto 0); 
    begin 
     if rising_edge(clk) then 
      if ld_a then 
       multiple := to_unsigned(0, multiple); 
       amux(0) <= multiple; 

       for i in 1 to amux'high loop 
        multiple := multiple + A; 
        amux(i) <= multiple; 
       end loop; 
      end if; 
     end if; 
    end process; 
end; 

请注意,上面的代码是有效的VHDL-2008只;在较早版本中,ld_a必须明确与“1”进行比较,并且不可能使用常规常量NM来计算后续泛型的值。

+0

你明白了我的观点。这对我帮助很大。非常感谢你! – hassicho

+0

得到的结果很好,不幸的是代码示例有四个语义错误,N和M在声明DATA_WIDTH和ARRAY_DEPTH时不可用,ld_a不是布尔值,to_unsigned被滥用。 (这个问题显示为与较新问题相关)。 – user1155120

+0

@ user1155120我编辑了这个问题,提到这些是VHDL-2008的特性。 – rick