M
Muhammad Awais
Hi,
I am a little new in the world of vhdl. I am working on a project for
mini-MIPS. I have problem with Register File behavior. When I simulate
Reg file stand alone, it gives me good behavior ie. when writing - it
will write the data on the same clk'edge. But when integrated with
other components. It acts weird i.e. it writes after one cycle.
I am attaching two snapshots of my simulations
<http://users.encs.concordia.ca/~m_humayu/Screenshot-regfile.png>
1st Snap shot is the stand alone only simulation of Reg File, and we
can see As soon as Write Enable (wr_en) is '1' and clk ='1' the write
occur in to the corresponding register(wr_add), without any delay.
<http://users.encs.concordia.ca/~m_humayu/Screenshot-mips-regfile.png>
in the 2nd snapshot same component integrated into mips behave
different. At time = 40 ns (it's the write back stage of the first
instruction). The signals are from the regfiles components. When the
write back data (x08) is ready at the start of clk edge, the write is
enabled, and write back address (01) is held also, the write occurs
into reg(0) on the next clock cycle (time=50) . WHY? and what is the
possible solution.
Following is my Reg file - code, which is 32 x 32bit Register file.
Attached is my code of mini-MIPS - just for reference
<http://users.encs.concordia.ca/~m_humayu/miniMIPS32.zip>
regfile.vhd is used in ID_mips32.vhd (Instruction Decode). Top level
entity is <complete.vhd> and testbench is <tb_complete_mips.vhd>
Thanks
__________________________
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity regfile is
port(
rst : in std_logic;
clk : in std_logic;
rd_1 : in std_logic_vector(4 downto 0);
rd_2 : in std_logic_vector(4 downto 0);
data_in : in std_logic_vector(31 downto 0);
wr_en : in std_logic;
wr_add : in std_logic_vector(4 downto 0);
out_1 : out std_logic_vector(31 downto 0);
out_2 : out std_logic_vector(31 downto 0)
);
end entity regfile ;
architecture rtl of regfile is
type reg_array is array (0 to 31) of std_logic_vector(31 downto 0);
signal reg : reg_array;
signal wr_add_temp : std_logic_vector(4 downto 0);
signal data_in_temp : std_logic_vector(31 downto 0);
signal wr_en_temp : std_logic;
--signal s_out_1, s_out_2 : std_logic_vector(31 downto 0);
begin
readprocess:
out_1 <= reg(conv_integer(rd_1));
out_2 <= reg(conv_integer(rd_2));
wr_add_temp <= wr_add;
data_in_temp <= data_in;
wr_en_temp <= wr_en;
writeprocess:
process(clk,rst,wr_en,wr_add,reg)
begin
if rst = '1' then
for index in 0 to 31 loop
reg(index) <= ( Others => '0' );
end loop;
elsif (RISING_EDGE(clk)) then
if wr_en_temp = '1' then
if wr_add_temp /= "00000" then
reg(conv_integer(wr_add_temp)) <= data_in_temp;
end if;
end if;
end if;
end process;
end architecture rtl;
_____________________________________________________________
I am a little new in the world of vhdl. I am working on a project for
mini-MIPS. I have problem with Register File behavior. When I simulate
Reg file stand alone, it gives me good behavior ie. when writing - it
will write the data on the same clk'edge. But when integrated with
other components. It acts weird i.e. it writes after one cycle.
I am attaching two snapshots of my simulations
<http://users.encs.concordia.ca/~m_humayu/Screenshot-regfile.png>
1st Snap shot is the stand alone only simulation of Reg File, and we
can see As soon as Write Enable (wr_en) is '1' and clk ='1' the write
occur in to the corresponding register(wr_add), without any delay.
<http://users.encs.concordia.ca/~m_humayu/Screenshot-mips-regfile.png>
in the 2nd snapshot same component integrated into mips behave
different. At time = 40 ns (it's the write back stage of the first
instruction). The signals are from the regfiles components. When the
write back data (x08) is ready at the start of clk edge, the write is
enabled, and write back address (01) is held also, the write occurs
into reg(0) on the next clock cycle (time=50) . WHY? and what is the
possible solution.
Following is my Reg file - code, which is 32 x 32bit Register file.
Attached is my code of mini-MIPS - just for reference
<http://users.encs.concordia.ca/~m_humayu/miniMIPS32.zip>
regfile.vhd is used in ID_mips32.vhd (Instruction Decode). Top level
entity is <complete.vhd> and testbench is <tb_complete_mips.vhd>
Thanks
__________________________
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity regfile is
port(
rst : in std_logic;
clk : in std_logic;
rd_1 : in std_logic_vector(4 downto 0);
rd_2 : in std_logic_vector(4 downto 0);
data_in : in std_logic_vector(31 downto 0);
wr_en : in std_logic;
wr_add : in std_logic_vector(4 downto 0);
out_1 : out std_logic_vector(31 downto 0);
out_2 : out std_logic_vector(31 downto 0)
);
end entity regfile ;
architecture rtl of regfile is
type reg_array is array (0 to 31) of std_logic_vector(31 downto 0);
signal reg : reg_array;
signal wr_add_temp : std_logic_vector(4 downto 0);
signal data_in_temp : std_logic_vector(31 downto 0);
signal wr_en_temp : std_logic;
--signal s_out_1, s_out_2 : std_logic_vector(31 downto 0);
begin
readprocess:
out_1 <= reg(conv_integer(rd_1));
out_2 <= reg(conv_integer(rd_2));
wr_add_temp <= wr_add;
data_in_temp <= data_in;
wr_en_temp <= wr_en;
writeprocess:
process(clk,rst,wr_en,wr_add,reg)
begin
if rst = '1' then
for index in 0 to 31 loop
reg(index) <= ( Others => '0' );
end loop;
elsif (RISING_EDGE(clk)) then
if wr_en_temp = '1' then
if wr_add_temp /= "00000" then
reg(conv_integer(wr_add_temp)) <= data_in_temp;
end if;
end if;
end if;
end process;
end architecture rtl;
_____________________________________________________________