0
votes

I have an FPGA trying to read/write values to SDRAM on the same chip. What the sdram sees as IN, the top level sees as OUT and otherwise. SDRAM "paths" are instantiated and are brought to the top level. These paths have no direction. However, I know that the top level reads and writes to the sdram. I tried a variation of the code shown and it compiled. The code below is an example to pass two values to the SDRAM and read a third value. I have assigned a direction to paths. Is my logic correct in that it sends two values and received a third?

use IEEE.STD_LOGIC_UNSIGNED.ALL; -- see page 36 of Circuit Design with VHDL

port(
    -- ---------------------------------------------------------------------
    -- Global signals ------------------------------------------------------

    CLK   : in std_logic;
    RESET : in std_logic;

      A       : out std_logic_vector(15 downto 0);
      B       : out std_logic_vector(15 downto 0);
      C       : in  std_logic_vector(15 downto 0);

end entity sigma_k_top;

architecture rtl of function_top is

signal cntr     : std_logic_vector(31 downto 0);
signal sig_A    : std_logic_vector(15 downto 0);
signal sig_B        : std_logic_vector(15 downto 0);
signal sig_C        : std_logic_vector(15 downto 0);

begin

sdram_inst : entity work.sdram

port map (
    CLK               => sdram_CLK_in, --CLK shared by all
    A                 => sdram_A_in, -- Write to sdram
    B                 => sdram_B_in,--  Write to sdram
    C                 => sdram_C_out, --Read from sdram
);

 transfer: process(CLK)
 begin
    IF rising_edge(CLK) then
        cntr <= cntr + 1;
        if cntr = 1000 then -- 
            sig_A  <= "1000000000000000";
            sig_B  <= "1000000000000000";
        end if;             

        if cntr = 1001 then
            if  C(0) = '1' then
                sig_A  <= sig_A - 1; -- Writing 
                sig_B  <= sig_B + 1; -- Writing
                xfer   <= C ;        -- Reading 
            end if;
        end if;
        if cntr > 2000 then
            cntr <= (others => '0');
        end if;

    END IF;

 end process;

-- -------------------------------------------------------------------------
-- Top-level ports ---------------------------------------------------------


 TEST_LED(7 downto 0)   <= xfer(7 downto 0); -- Making some sdram output visible
 A <= sig_A; -- Sending value to sdram
 B <= sig_B; -- Sending value to sdram

end architecture rtl;

1

1 Answers

0
votes

What inputs and outputs exist to/from the RAM could vary based on how you intend to use it. If the RAM really exists on the FPGA chip itself, an example might be that you want to use a simple single port RAM on say a Xilinx Block RAM library component.

As it appears from the code that the sdram is instanced under the FPGA's top level (the RAM is contained within the fpga chip), it seems that the what are the RAM's inputs/outputs should also be the top level's inputs/outputs. It would be reversed if the sdram were outside the FPGA (and thus outside the FPGA's top level)

In general, RAMs tend to be sequential elements that require at the least:

-A clock (typically a 1-bit wide signal)

-An address (tends to be log2(n) bits wide, where n is the size of the RAM array. So if the array has 64 elements, you'd need at least 6 bits to address everything. The same address signal could be used for both reads and writes, or maybe you would have 2 separate address signals.)

-A write enable (in the simplest from could be a 1-bit signal. The most typical use would be to assert this signal for 1 clock cycle to update data at the current address of the address signal)

-data (width would vary and tends to be flexible/configurable on an FPGA. If you want to store 16-bits of data in each RAM entry that should be perfectly valid. This could be a single signal or 2 separate ones for read and write data).

As long as the signal vectors going to/from the RAM have at least these basic functions, it seems like you should be able to use it at least as a simple RAM. Note by the way that in your code the sdram_* signals are neither declared nor connected to anything other than the sdram instance itself.