【问题标题】:Dynamic Arrray Size in VHDLVHDL 中的动态数组大小
【发布时间】:2015-05-25 04:22:51
【问题描述】:

我想使用数组的动态范围,因此使用“N”将传入的矢量信号转换为整数。使用特定的传入端口“Size”会给我一个错误,而固定向量会产生完美的输出。

architecture EXAMPLE of Computation is

signal size :std_logic_vector (7 downto 0);

process (ACLK, SLAVE_ARESETN) is

variable N: integer:=conv_integer  ("00000111") ;  ---WORKING

--variable N: integer:=conv_integer  (size) ; -- Not working
type memory is array (N downto 0 ) of std_logic_vector (31 downto 0 ); 

variable RAM :memory; 

进行此类编码的唯一原因是向 FPGA 发送尽可能多的数据。因为我需要在 vivado 中通过 DMA 将数据从 DDR 发送到自定义 IP 可能超过 100 MB。如果我试图以上述错误的方式实施,请指导我。

【问题讨论】:

    标签: vhdl ram xilinx vivado


    【解决方案1】:

    你不能在 VHDL 中做到这一点。你的代码会生成什么样的硬件?如果你不知道,合成器也不会。

    做这种事情的方法是将N设置为你想要支持的最大值,并在你的逻辑中使用size来适当地控制你的逻辑。在没有更多信息的情况下很难给出更多的指针,但例如,您可以使用计数器来寻址您的 ram,并在大于 size 时将其重置。

    更新

    这是一个反例。您必须确保size 在运行时不会发生变化,否则它将进入未知状态。真正的设计应该具有重置状态以确保正确的行为。

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    
    entity example is
    port (
        clk : std_logic;
        rst : in std_logic;
        size : in unsigned(7 downto 0);
        wr : in std_logic;
        din : in std_logic_vector(31 downto 0)
    );
    end entity;
    
    architecture rtl of example is
        signal counter : unsigned(7 downto 0);
    
        type ram_t is array(0 to 255) of std_logic_vector(31 downto 0);
        signal ram : ram_t;
    begin
    
        RAM_WR: process(clk)
        begin
            if rising_edge(clk) then
                if rst = '1' then
                    counter <= (others => '0');
                else
                    if wr = '1' then
                        ram(to_integer(counter)) <= din;
    
                        if counter = size then
                            counter <= (others => '0');
                        else
                            counter <= counter + 1;
                        end if;
                    end if;
                end if;
            end if;
        end process RAM_WR;
    
    end architecture rtl;
    

    【讨论】:

    • 是的。我已经考虑过为这个问题制作一个计数器,但你能举个例子来使用计数器来寻址 ram 。
    • 我写的如下。它给了我这个错误:正式的 没有实际或默认值。类型整数不是数组类型,不能被索引。 if (S_AXIS_TVALID = '1') 然后 RAM (to_integer (Counter) ) '0') ;否则计数器
    • 我添加了实体声明并修复了一个小错误。它按原样编译。
    【解决方案2】:

    我相信你在一个进程中只能有一个通用的数组约束。否则编译器无法详细说明。

    在函数或过程中,您可以拥有真正可变的数组边界。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-24
      • 1970-01-01
      • 1970-01-01
      • 2014-07-21
      • 2011-05-03
      • 1970-01-01
      相关资源
      最近更新 更多