无法从 RAM 内存地址输出数据

发布于 2025-01-11 17:50:13 字数 2801 浏览 1 评论 0原文

我正在尝试在 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

enter image description here

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

enter image description here

the output is working fine. How is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀里藏娇 2025-01-18 17:50:13

在测试台代码中必须添加端口映射。

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
    uut: ram port map(clock, we, address, datain, dataout);

    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;

In the testbench code the port map must be added.

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
    uut: ram port map(clock, we, address, datain, dataout);

    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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文