首页 文章

各种类型的VHDL数组串联

提问于
浏览
-1

我正在做一些本科研究,涉及一些VHDL编码,我几乎没有经验 . 我遇到了一些问题并希望得到一些帮助:

我需要读入一个信号(“std_logic_vectors”数组),并对其执行逻辑移位 . 我的想法是将一个0的数组连接到一个包含输入相关部分的数组 . 这就是我所做的:

Library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use work.SignalGen.all;

entity Shifter is
  Port ( xsig_in : in SignalGen;
         shift : in  integer;
         clk : in STD_LOGIC;
         x_out1 : out  SignalGen;
         x_out2 : out SignalGen);
end Shifter;

architecture Behavioral of Shifter is
type x_in_type is array (0 to (1024-shift) of std_logic_vector;
type zeroes_type is array(0 to shift) of std_logic_vector;
signal x_shifted: SignalGen;
signal x_in : x_in_type := xsig_in(1024 downto shift); -- This is line 37
signal zeroes : zeroes_type := (others => (others => '0')); 

begin

process(clk)
begin

   x_shifted <= zeroes & x_in; -- This is line 49

end process;

end Behavioral;

知道SignalGen的类型很重要,所以这是我的声明:

type SignalGen is array (0 to 1024) of STD_LOGIC_VECTOR(15 downto 0);

所以你可以看到,我创建了一个类型“zeroes_type”,它是所需班次的长度 . 它用于生成填充零的信号“零” . x_in也是x_in_type类型,它是输入信号的长度减去移位量,并且被初始化为信号减去移出的值 .

当我尝试将它们连接在一起时,我得到以下错误:

Line 37: Indexed name is not a x_in_type

Line 49: found '0' definitions of operator "&", cannot determine exact     overloaded matching definition for "&"

行号包含在代码发布中的注释中 . 我几个小时以来一直在修补这个部分,我试图做的事情都无法解决 .

如果有人能够对这个问题有所了解,或者给我一个更好的方法来做我想做的事情,我将非常感激!谢谢!

1 回答

  • 1

    我认为你离你需要的地方很远 . 就区域而言,这不是一个有效的实现:你将有16,000个触发器 . 但是,这个解决方案应该更接近您需要的位置:

    Library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    use work.SignalGen.ALL;  
    
    entity Shifter is
      Port ( xsig_in : in SignalGen;
             shift   : in  integer;
             clk     : in STD_LOGIC;
             x_out1  : out SignalGen;
             x_out2  : out SignalGen);
    end Shifter;
    
    architecture Behavioral of Shifter is
    begin
    
    process(clk)
      variable V : SignalGen;
    begin
      if rising_edge(clk) then
        V := xsig_in;
        for I in 1 to xsig_in'RIGHT loop
          if I <= shift then
            V := "0000000000000000" & V(0 to xsig_in'RIGHT-1); 
          end if;
        end loop;
        x_out1 <= V;
      end if;
    end process;
    
    end Behavioral;
    

    http://www.edaplayground.com/x/8AQ

    变量,循环和连接在进行移位时通常很有用,如我在示例中所示 . 当你完成换档时,你可以跳出循环(使用 exit )但是我的经验你可能会得到更多的逻辑,即:

    if I <= shift then
          V := "0000000000000000" & V(0 to xsig_in'RIGHT-1); 
        else
          exit;
        end if;
    

    您的代码中存在许多错误 . 虽然,我确信你会在发布答案时向我学习一些东西,这里有一些关于你所看到的错误的解释:

    type x_in_type is array (0 to (1024-shift)) of std_logic_vector;
    

    你错过了一个右手括号,这一行依赖于你使用VHDL 2008,因为内部维度是不受约束的 . 但即便如此,无论如何,您无法根据非静态数量( shift )定义类型 .

    signal x_in : x_in_type := xsig_in(1024 downto shift);
    

    在数组受限制的情况下,您需要跳过外部维度来约束内部维度 . 在VHDL 2008中,您可以跳过这样的约束维度:

    signal x_in : x_in_type := xsig_in(open)(1024 downto shift);
    

相关问题