32x8寄存器文件VHDL的测试平台

时间:2014-03-15 01:44:20

标签: vhdl

我已经在vhdl中编写了这个电路的汇编代码。我想用测试台来模拟它。

enter image description here

  • RegWrite:1位输入(时钟)
  • 写入寄存器编号:3位输入(写入地址)
  • 写入数据:32位输入(数据输入)读取
  • 寄存器编号A:3位输入(读取地址)
  • 读取寄存器编号B:3位输入(读取地址)
  • 端口A:32位输出(数据输出)
  • 端口B:32位输出(数据输出)

我认为我的问题是我不明白这条电路是做什么的。我选择随机值来分配输入,但它没有输出任何东西。有什么好的输入可供选择?

这是我的测试平台文件供参考:

library ieee; 
use ieee.std_logic_1164.all; 

entity Reg_TB is     -- entity declaration 
end Reg_TB; 

architecture TB of Reg_TB is 
component RegisterFile_32x8
port (  RegWrite: in std_logic; 
    WriteRegNum: in std_logic_vector(2 downto 0);
    WriteData: in std_logic_vector(31 downto 0);
    ReadRegNumA: in std_logic_vector(2 downto 0);
    ReadRegNumB: in std_logic_vector(2 downto 0);
    PortA: out std_logic_vector(31 downto 0);
    PortB: out std_logic_vector(31 downto 0)
 ); 
end component; 

signal T_RegWrite : std_logic;
signal T_WriteRegNum: std_logic_vector(2 downto 0);
signal T_WriteData: std_logic_vector(31 downto 0);
signal T_ReadRegNumA: std_logic_vector(2 downto 0);
signal T_ReadRegNumB: std_logic_vector(2 downto 0);
signal T_PortA : std_logic_vector(31 downto 0);
signal T_PortB : std_logic_vector(31 downto 0);

begin 
T_WriteRegNum <= "011";
T_WriteData <= "00000000000000000000000000000001";
T_ReadRegNumA <= "001";
T_ReadRegNumB <= "100";
U_RegFile: RegisterFile_32x8 port map 
(T_RegWrite, T_WriteRegNum,    T_WriteData,T_ReadRegNumA, T_ReadRegNumB, T_PortA, T_PortB); 

-- concurrent process to offer clock signal 
process 
begin 


T_RegWrite <= '0'; 
wait for 5 ns; 
T_RegWrite <= '1'; 
wait for 5 ns; 
end process; 
process 
 begin 
wait for 12 ns; 
-- case 2 
wait for 28 ns; 
-- case 3 
wait for 2 ns; 
-- case 4 
wait for 10 ns; 
-- case 5 
wait for 20 ns; 
wait; 
 end process; 
end TB; 

你可以看到我选择了

  • WriteRegNum =“011”
  • WriteData =“00000000000000000000000000000001”
  • ReadRegNumA =“001”
  • ReadRegNumB =“100”

我认为我选择了糟糕的输入。模拟这样做:

enter image description here

1 个答案:

答案 0 :(得分:3)

一般来说,在写入地址之前阅读地址并不能产生任何有用的结果。

您的程序框图显示了一个32位宽的8字深寄存器文件,其中包含两个读端口和一个写入端口,RegWrite用作写入地址解码的时钟门控。稳定的WriteRegNum值和RegWrite的上升沿会影响对WriteRegNum指定的地址的写入。

两个读端口看起来完全独立。在相应的ReadRegNumA或ReadRegNumB上指定地址应该将该寄存器的内容输出到相应的输出端口。

为了获得有用的东西,你必须首先写入该位置,否则它将是默认值((其他=&gt;&#39; U&#39;),)可疑地像你的波形。

在期望从中获取有效读取数据之前尝试写入位置。使用可通过寄存器位置区分的值。从理论上讲,你应该在RegRerite的上升沿保留WriteRegNum的设置和保持时间。

示例刺激产生输出:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity registerfile_32x8 is
    port (
        RegWrite:       in  std_logic;
        WriteRegNum:    in  std_logic_vector (2 downto 0);
        WriteData:      in  std_logic_vector (31 downto 0);
        ReadRegNumA:    in  std_logic_vector (2 downto 0);
        ReadRegNumB:    in  std_logic_vector (2 downto 0);
        PortA:          out std_logic_vector (31 downto 0);
        PortB:          out std_logic_vector (31 downto 0)
    );
end entity;

architecture fum of registerfile_32x8 is

    type reg_array is array (0 to 7) of std_logic_vector(31 downto 0);
    signal reg_file: reg_array;

    begin 
    process(RegWrite)
    begin 
        if rising_edge(RegWrite) then
            reg_file(to_integer(unsigned(WriteRegNum))) <= WriteData;
        end if;
    end process;

    PortA <= reg_file(to_integer(unsigned(ReadRegNumA)));

    PortB  <= reg_file(to_integer(unsigned(ReadRegNumB)));

end architecture;

library ieee; 
use ieee.std_logic_1164.all; 

entity reg_tb is    
end entity; 

architecture fum of reg_tb is 

component registerfile_32x8
    port (  
        RegWrite:       in  std_logic; 
        WriteRegNum:    in  std_logic_vector (2 downto 0);
        WriteData:      in  std_logic_vector (31 downto 0);
        ReadRegNumA:    in  std_logic_vector (2 downto 0);
        ReadRegNumB:    in  std_logic_vector (2 downto 0);
        PortA:          out std_logic_vector (31 downto 0);
        PortB:          out std_logic_vector (31 downto 0)
        ); 
    end component; 

signal RegWrite:        std_logic := '1';
signal WriteRegNum:     std_logic_vector (2 downto 0) := "000";
signal WriteData:       std_logic_vector (31 downto 0) := (others => '0');
signal ReadRegNumA:     std_logic_vector (2 downto 0) := "000";
signal ReadRegNumB:     std_logic_vector (2 downto 0) := "000";
signal PortA:           std_logic_vector (31 downto 0);
signal PortB:           std_logic_vector (31 downto 0);

begin 

DUT: 
    registerfile_32x8 
        port map (
            RegWrite => RegWrite,
            WriteRegNum => WriteRegNum,
            WriteData  => WriteData,
            ReadRegNumA => ReadRegNumA, 
            ReadRegNumB => ReadRegNumB, 
            PortA => PortA, 
            PortB => PortB
        ); 


STIMULUS:
    process 
    begin 
    wait for 20 ns;
    RegWrite <= '0';
    wait for 20 ns;
    RegWrite <= '1';
    wait for 20 ns;
    WriteData <= x"feedface";
    WriteRegnum <= "001";
    RegWrite <= '0';
    wait for 20 ns;
    RegWrite <= '1';
    ReadRegNumA <= "001";
    wait for 20 ns;
    WriteData <= x"deadbeef";
    WriteRegNum <= "010";
    ReadRegNumB <= "010";
    RegWrite <= '0';
    wait for 20 ns;
    RegWrite <= '1';
    wait for 20 ns;
    wait for 20 ns;
    wait;
 end process; 
end architecture; 
  

david_koontz @ Macbook:ghdl -a regfile_32x8.vhdl
  david_koontz @ Macbook:ghdl -e reg_tb
  david_koontz @ Macbook:ghdl -r reg_tb --wave = reg_tb.ghw
  david_koontz @ Macbook:打开reg_tb.gtkw

reg_tb showing register contents

基本上,重点是让非&#39; U&#39;正在读取的寄存器文件中的值。如果您注意到写入WriteRegNum =&#34; 010&#34;的最后一次写入,则PortB会在写入发生之前显示未定义的输出。