Arrays 从RAM读取VHDL并存储在阵列延迟中?
我目前正在用VHDL做一个项目,因为我不是专家,所以我遇到了一些问题 我会尽力澄清一切。让我们分成几部分 我试图做的是将某些值写入两个不同的RAM内存中,然后从中读取并将不同的值存储到一个数组中,该数组将由不同的块用于执行MAC过滤 这是我正在使用的RAM代码(是对张伟军提供的代码的修改),我不知道我是否必须在这里发布链接。如果有人需要它,我会把它寄出去Arrays 从RAM读取VHDL并存储在阵列延迟中?,arrays,vhdl,ram,Arrays,Vhdl,Ram,我目前正在用VHDL做一个项目,因为我不是专家,所以我遇到了一些问题 我会尽力澄清一切。让我们分成几部分 我试图做的是将某些值写入两个不同的RAM内存中,然后从中读取并将不同的值存储到一个数组中,该数组将由不同的块用于执行MAC过滤 这是我正在使用的RAM代码(是对张伟军提供的代码的修改),我不知道我是否必须在这里发布链接。如果有人需要它,我会把它寄出去 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
--------------------------------------------------------------
entity SRAM is
generic( width: integer:=32;
depth: integer:=1024;
addr: integer:=10);
port( clk: in std_logic;
enable: in std_logic;
read_en: in std_logic;
write_en: in std_logic;
read_addr: in std_logic_vector(addr-1 downto 0);
write_addr: in std_logic_vector(addr-1 downto 0);
Data_in: in std_logic_vector(width-1 downto 0);
Data_out: out std_logic_vector(width-1 downto 0)
);
end SRAM;
--------------------------------------------------------------
architecture behav of SRAM is
-- use array to define the bunch of internal temporary signals
type ram_type is array (0 to depth-1) of std_logic_vector(width-1 downto 0);
signal tmp_ram: ram_type:= ((others=> (others=>'0')));
begin
-- read_en Functional Section
process(clk, read_en)
begin
if (clk'event and clk='1') then
if enable='1' then
if read_en='1' then
-- buildin function conv_integer change the type
-- from std_logic_vector to integer
Data_out <= tmp_ram(conv_integer(read_addr));
else
Data_out <= (Data_out'range => 'Z');
end if;
end if;
end if;
end process;
-- write_en Functional Section
process(clk, write_en)
begin
if (clk'event and clk='1') then
if enable='1' then
if write_en='1' then
tmp_ram(conv_integer(write_addr)) <= Data_in;
end if;
end if;
end if;
end process;
end behav;
现在宣布两只公羊
input_RAM: SRAM generic map (width=> t_width, depth=> t_depth, addr=> t_addr)
port map (clk, enable, read_input_en, write_input_en,read_input_addr, write_input_addr, X, saved_input);
coeff_RAM: SRAM generic map (width=> t_width, depth=> t_depth, addr=> t_addr)
port map (clk, enable, read_coeff_en, write_coeff_en,read_coeff_addr, write_coeff_addr, W, saved_coeff);
这是一个过程(常量的值为“0000000001”)
过程(时钟、写入输入、写入系数)
开始
如果(clk'事件和clk='1'),则
如果(写下系数),那么
在另外两条if语句中写入您不应该驾驶i
。如果…elseif
,请尝试更改为。也许这不是您的bug的原因,但这是一条基本规则。看起来您没有在系统重置时重置地址计数器。无论数组是从地址0还是1开始,问题描述中也存在矛盾。在这两者之间,它们可能解释了您的问题。我在最后编辑了我的问题,以回答有关地址重置的问题。此外,该数组是一个数组32(从3到0)。我正在尝试从位置0开始填充,然后是位置1、2、3,然后返回到位置0。
input_RAM: SRAM generic map (width=> t_width, depth=> t_depth, addr=> t_addr)
port map (clk, enable, read_input_en, write_input_en,read_input_addr, write_input_addr, X, saved_input);
coeff_RAM: SRAM generic map (width=> t_width, depth=> t_depth, addr=> t_addr)
port map (clk, enable, read_coeff_en, write_coeff_en,read_coeff_addr, write_coeff_addr, W, saved_coeff);
process (clk, write_input_en, write_coeff_en)
begin
if (clk'event and clk='1') then
if (write_coeff_en='1') then
write_coeff_addr <= cont2;
cont2 <= unsigned(cont2) + unsigned(one);
end if;
if (write_input_en='1') then
i:=0;
write_input_addr <= cont1;
cont1 <= unsigned(cont1) + unsigned(one);
end if;
if (read_input_en='1' and read_coeff_en='1') then
read_input_addr <= cont3;
read_coeff_addr <= cont4;
X_in(i) <= saved_input;
W_in(i) <= saved_coeff;
cont3 <= unsigned(cont3) + unsigned(one);
cont4 <= unsigned(cont4) + unsigned(one);
X_in(i) <= saved_input;
W_in(i) <= saved_coeff;
i:=i+1;
if(i=4) then
i:=0;
end if;
end if;
end if;
end process;
Yn <= X_in(0);
Yt <= saved_input;