首页 > 解决方案 > 如何使用存储在 BRAM 中的数据初始化 STD_LOGIC_VECTOR(15 down to 0) 数组

问题描述

我在 BRAM 中有一些滤波器系数,这些系数需要写入数组来执行卷积。我使用类型创建了一个数组并将其分配给一个信号。该信号我已将端口映射到 BRAM 的 DATA_OUT。它给出了一个错误“期望 STD_LOGIC_VECTOR”

我尝试使用 for 循环将数据写入数组。它会导致错误“索引不是 STD_LOGIC_VECTOR”

我的类型声明

TYPE coeff_pipe IS ARRAY(0 TO 15) OF std_logic_vector(7 downto 0);
Signal coeff:coeff_pipe;

我的for循环是这样的

for i in 0 to  loop
    coeff(i) <= data_out_BRAM(i);   end loop;

帮助我对代码进行适当的更改以使其正常工作

标签: vhdl

解决方案


您可以在编码语言 (C) 和硬件描述语言 (VHDL) 中混合使用for 循环行为。在编码语言中,如果您编写一个for 循环,处理器将按顺序(一个接一个)依次执行循环的内容多次。在 HDL 中,for 循环用于多次实例化具有不同输入/输出的相同电路。for 循环中没有时间概念。

在您的情况下,您必须使用顺序过程并增加您的 BRAM 地址:

process(clk, rst)
begin

  if rst = '1' then
    addr_BRAM     <= (others => '0');
    addr_BRAM_d   <= (others => '0');
    ram_init_en   <= '1';
    ram_init_en_d <= '0';
    coeff         <= (others => (others => '0'));
  elsif rising_edge(clk) then

    addr_BRAM_d   <= addr_BRAM  ; -- Delay of 1 clk cycle 
    ram_init_en_d <= ram_init_en; -- Delay of 1 clk cycle

    -- Init done
    if addr_BRAM = x"1111" then
      ram_init_en <= '0';
    end if;

    -- Increment BRAM address
    if ram_init_en = '1' then
      addr_BRAM  <= std_logic_vector(unsigned(addr_BRAM) + 1);
    end if;

    -- Get data one cycle after set address because a BRAM doesn't answer instant, it answers in one clk cycle. 
    if ram_init_en_d = '1' then
      coeff(to_integer(unsigned(addr_BRAM_d))) <= data_out_BRAM;
    end if;    

  end if;

end process;

推荐阅读