无法从 RAM 内存地址输出数据
我正在尝试在 vhdl 中构建一个 ram,在下面的代码中,我成功地将数据存储在 ram 位置 0000 和 0001 中。我没有成功地从内存位置 0000 和 0001 输出数据。
以下代码适用于 ram vhdl。
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.Numeric_Std.all;
entity ram is
port (
clock : in std_logic;
we : in std_logic;
address : in std_logic_vector(3 downto 0);
datain : in std_logic_vector(7 downto 0);
dataout : out std_logic_vector(7 downto 0)
);
end entity ram;
architecture RTL of ram is
type ram_type is array (0 to 15) of std_logic_vector(datain'range);
signal ram_comp : ram_type;
signal read_address : std_logic_vector(address'range);
begin
RamProc: process(clock) is
begin
if rising_edge(clock) then
if we = '1' then
ram_comp(to_integer(unsigned(address))) <= datain;
end if;
read_address <= address;
end if;
end process RamProc;
dataout <= ram_comp(to_integer(unsigned(read_address)));
end architecture RTL;
以下代码是 ram vhdl 代码的测试平台。
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.Numeric_Std.all;
entity ram_tb is
end entity;
architecture behave of ram_tb is
component ram
port(
clock : in std_logic;
we : in std_logic;
address : in std_logic_vector(3 downto 0);
datain : in std_logic_vector(7 downto 0);
dataout : out std_logic_vector(7 downto 0)
);
end component;
signal clock, we : std_logic;
signal datain, dataout : std_logic_vector(7 downto 0);
signal address : std_logic_vector(3 downto 0);
constant T : time := 20 ns;
begin
clock_process : process
begin
clock <= '0';
wait for T/2;
clock <= '1';
wait for T/2;
end process;
stim_process : process
begin
address <= "0000";
datain <= "00001111";
we <= '1';
wait for 20 ns;
address <= "0001";
datain <= "00001100";
wait for 20 ns;
we <= '0';
wait for 20 ns;
address <= "0000";
wait for 20 ns;
address <= "0001";
wait for 20 ns;
assert false report "Reached end of test";
wait;
end process;
end behave;
ram_tb 截图的模拟
如何在 dataout 信号上输出地址 0000 和 0001 的数据?
我在ModelSim上尝试了模拟,下面是模拟的结果
输出工作正常。这怎么可能?
I am trying to build a ram in vhdl and in the below code I am successful in storing data in the ram locations 0000 and 0001. I am not successful in outputting the data from memory locations 0000 and 0001.
The following code is for the ram vhdl.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.Numeric_Std.all;
entity ram is
port (
clock : in std_logic;
we : in std_logic;
address : in std_logic_vector(3 downto 0);
datain : in std_logic_vector(7 downto 0);
dataout : out std_logic_vector(7 downto 0)
);
end entity ram;
architecture RTL of ram is
type ram_type is array (0 to 15) of std_logic_vector(datain'range);
signal ram_comp : ram_type;
signal read_address : std_logic_vector(address'range);
begin
RamProc: process(clock) is
begin
if rising_edge(clock) then
if we = '1' then
ram_comp(to_integer(unsigned(address))) <= datain;
end if;
read_address <= address;
end if;
end process RamProc;
dataout <= ram_comp(to_integer(unsigned(read_address)));
end architecture RTL;
The following code is a testbench for the ram vhdl code.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.Numeric_Std.all;
entity ram_tb is
end entity;
architecture behave of ram_tb is
component ram
port(
clock : in std_logic;
we : in std_logic;
address : in std_logic_vector(3 downto 0);
datain : in std_logic_vector(7 downto 0);
dataout : out std_logic_vector(7 downto 0)
);
end component;
signal clock, we : std_logic;
signal datain, dataout : std_logic_vector(7 downto 0);
signal address : std_logic_vector(3 downto 0);
constant T : time := 20 ns;
begin
clock_process : process
begin
clock <= '0';
wait for T/2;
clock <= '1';
wait for T/2;
end process;
stim_process : process
begin
address <= "0000";
datain <= "00001111";
we <= '1';
wait for 20 ns;
address <= "0001";
datain <= "00001100";
wait for 20 ns;
we <= '0';
wait for 20 ns;
address <= "0000";
wait for 20 ns;
address <= "0001";
wait for 20 ns;
assert false report "Reached end of test";
wait;
end process;
end behave;
Simulation of the ram_tb screenshot
How can I output the data from address 0000 and 0001 on the dataout signal?
I tried the simulation on ModelSim below is the result of the simulation
the output is working fine. How is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在测试台代码中必须添加端口映射。
In the testbench code the port map must be added.