Memory VHDL高效且正确的内存分配
我正试图在FPGA上生成一个内存,但我有一些问题与如何处理存储的数据有关。 当我想更新数据时,是否需要使用新的_q1信号?(就像我试图在我的代码中应用(版本1和版本3))。 有人告诉我,我需要一个新的q1信号(我不知道为什么),我应该总是有一个“else”语句来防止“不在乎” 版本1是具有新的q1信号的版本,但是,新的_q1没有初始值。第2版是我实际开始使用的版本,但我收到一条评论,说这不是正确的方法,因为我不太理解某些原因 版本3是完全工作的版本,就像向我解释的那样,但是,在我看来,它太多了,合成器拒绝了我的新的_q1结构 我应该用什么版本,有人能澄清我所说的是正确的还是错误的,以及为什么 第1版:Memory VHDL高效且正确的内存分配,memory,vhdl,Memory,Vhdl,我正试图在FPGA上生成一个内存,但我有一些问题与如何处理存储的数据有关。 当我想更新数据时,是否需要使用新的_q1信号?(就像我试图在我的代码中应用(版本1和版本3))。 有人告诉我,我需要一个新的q1信号(我不知道为什么),我应该总是有一个“else”语句来防止“不在乎” 版本1是具有新的q1信号的版本,但是,新的_q1没有初始值。第2版是我实际开始使用的版本,但我收到一条评论,说这不是正确的方法,因为我不太理解某些原因 版本3是完全工作的版本,就像向我解释的那样,但是,在我看来,它太多了,
entity memory is
port(
clk : in std_logic;
reset : in std_logic;
selector : in std_logic_vector(5 downto 0);
write : in std_logic;
value : out std_logic
);
end memory;
architecture behaviour of memory is
signal q1, new_q1 : std_logic_vector(63 downto 0);
begin
process(clk, reset) is
begin
if( clk'event AND clk = '1') then
if(reset = '1') then
q1 <= (others => '0');
else
q1 <= new_q1;
end if;
end if;
end process;
process(q1) is
if(write = '1') then
new_q1(to_integer(unsigned(selector)) <= '1';
else
new_q1 <= q1;
end if;
end process;
value <= q1(to_integer(unsigned(selector));
end behaviour;
实体内存不可用
港口(
clk:标准逻辑中;
复位:在标准逻辑中;
选择器:标准逻辑向量(5到0);
写入:在标准逻辑中;
值:输出标准逻辑
);
终端存储器;
内存的体系结构行为是
信号q1,新的_q1:std_逻辑_矢量(63向下至0);
开始
进程(clk、reset)正在运行
开始
如果(clk'事件和clk='1'),则
如果(重置='1'),则
q1‘0’;
其他的
q1根据一些关于操作的假设,如端口列表中所述,设计可能如下所示。由于尺寸和特殊功能,FPGA中的实现可能使用触发器,而不是内部存储器,因此名称memory
可能会引起误解
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity memory is
port(
clk : in std_logic;
reset : in std_logic; -- Synchronous, assumed to be applied initially
selector : in std_logic_vector(5 downto 0);
write : in std_logic; -- Write set bit only, synchronous
value : out std_logic -- Read value, asynchronous
);
end memory;
architecture behaviour of memory is
signal q1 : std_logic_vector(63 downto 0);
begin
-- Reset and write set, synchronous
process (clk) is
begin
if (clk'event and clk = '1') then -- Rising clock
if (reset = '1') then -- Reset, synchronous
q1 <= (others => '0'); -- Clear all bits
elsif (write = '1') then -- Write to set for selector bit
q1(to_integer(unsigned(selector))) <= '1'; -- Set single bit
end if;
end if;
end process;
-- Read, asynchronous
value <= q1(to_integer(unsigned(selector))); -- Read single bit
end behaviour;
ieee库;
使用ieee.std_logic_1164.all;
使用ieee.numeric_std.all;
实体内存是
港口(
clk:标准逻辑中;
复位:在std_逻辑中;--同步,假设最初应用
选择器:标准逻辑向量(5到0);
写入:在std_逻辑中;--仅写入设置位,同步
值:out std_逻辑——读取值,异步
);
终端存储器;
内存的体系结构行为是
信号q1:std_逻辑_向量(63向下至0);
开始
--复位和写入设置,同步
过程(clk)是
开始
如果(时钟事件和时钟='1'),则——上升时钟
如果(重置='1'),则--reset,synchronous
q1'0');--清除所有位
elsif(write='1'),然后——写入选择器位的设置
q1(to_integer(unsigned(selector)))您能描述一下内存所需的功能吗?似乎write
仅用于设置位,而不是赋值,因此位仅在reset
时重置,因此它可能是某种特殊类型的内存。不管怎么说,它看起来太复杂了,可能不需要新的功能,但这取决于所需的功能。@MortenZilmer是的,我可以,它只用于更新和读取这个64位的数据中的一位。最终将有q1、q2、q3和q4,4个选择器将作为输入,因此可以有4个单比特值作为与q1-q4对应的输出。所有FPGA供应商都支持存储器的合成。对于确切的语言结构,您应该从FPGA供应商处找到应用程序说明。它将有VHDL和Verilog示例。注意,标准内存没有重置!内容从一开始就应该是X,就像一个真实的记忆。谢谢,你能详细说明一下你做了什么,特别是为什么要做这些事情吗?我试着去理解,你没有用别的说法。。。(除非另有规定)。我被告知需要一个else语句来防止不关心。我将在代码中添加注释。else
没有什么特别的地方可以防止不在乎,但是在重置之前内部内存将是未定义的,因此假设最初应用了重置。
entity memory is
port(
clk : in std_logic;
reset : in std_logic;
selector : in std_logic_vector(5 downto 0);
write : in std_logic;
value : out std_logic
);
end memory;
architecture behaviour of memory is
signal q1 : std_logic_vector(63 downto 0);
begin
process(clk, reset) is
begin
if( clk'event AND clk = '1') then
if(reset = '1') then
q1 <= (others => '0');
else
q1 <= new_q1;
end if;
end if;
end process;
process(q1, write) is
if(write = '1') then
if(unsigned(selector) < 63) then
new_q1 <= q1(63 downto to_integer(unsigned(selector))) & '1' & q1(to_integer(unsigned(selector)) downto 0);
else
new_q1 <= '1' & q1(to_integer(unsigned(selector)) downto 0);
end if;
else
new_q1 <= q1;
end if;
end process;
value <= q1(to_integer(unsigned(selector));
end behaviour;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity memory is
port(
clk : in std_logic;
reset : in std_logic; -- Synchronous, assumed to be applied initially
selector : in std_logic_vector(5 downto 0);
write : in std_logic; -- Write set bit only, synchronous
value : out std_logic -- Read value, asynchronous
);
end memory;
architecture behaviour of memory is
signal q1 : std_logic_vector(63 downto 0);
begin
-- Reset and write set, synchronous
process (clk) is
begin
if (clk'event and clk = '1') then -- Rising clock
if (reset = '1') then -- Reset, synchronous
q1 <= (others => '0'); -- Clear all bits
elsif (write = '1') then -- Write to set for selector bit
q1(to_integer(unsigned(selector))) <= '1'; -- Set single bit
end if;
end if;
end process;
-- Read, asynchronous
value <= q1(to_integer(unsigned(selector))); -- Read single bit
end behaviour;