Electrical – FPGA Simple RAM Model – Why is the address delayed

fpgaverilogvhdl

In the sample code below from Doulos that models RAM using an array, why is the address delayed?

Specifically, why did they bother to create a second signal read_address instead of using the input address throughout to access the array?

I suspect it has something to do with concurrent versus sequential, but I can't figure it out…


-- Simple generic RAM Model
--
-- +-----------------------------+
-- |    Copyright 2008 DOULOS    |
-- |   designer :  JK            |
-- +-----------------------------+

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.Numeric_Std.all;

entity sync_ram is
  port (
    clock   : in  std_logic;
    we      : in  std_logic;
    address : in  std_logic_vector;
    datain  : in  std_logic_vector;
    dataout : out std_logic_vector
  );
end entity sync_ram;

architecture RTL of sync_ram is

   type ram_type is array (0 to (2**address'length)-1) of std_logic_vector(datain'range);
   signal ram : 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(to_integer(unsigned(address))) <= datain;
      end if;
      read_address <= address;
    end if;
  end process RamProc;

  dataout <= ram(to_integer(unsigned(read_address)));

end architecture RTL;

Best Answer

It is a write-first (write-before-read) RAM, so the address is delayed to see the new value at dataout port. If dataout was delayed, we would see the old value at dataout port and it would become a read-first RAM.

Related Topic