Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

Blockram: RAM model read/write

Hello,

Can someone point me out how I can read/write to the following blockram RAM model ?

I can read and write to external SRAM, but I am not able to make this work using blockram. Could someone help?


ENTITY vram8k IS
	PORT
	(
		data		: IN STD_LOGIC_VECTOR (7 DOWNTO 0);
		rdaddress		: IN STD_LOGIC_VECTOR (12 DOWNTO 0);
		rdclock		: IN STD_LOGIC ;
		rden		: IN STD_LOGIC  := '1';
		wraddress		: IN STD_LOGIC_VECTOR (12 DOWNTO 0);
		wrclock		: IN STD_LOGIC ;
		wren		: IN STD_LOGIC  := '1';
		q		: OUT STD_LOGIC_VECTOR (7 DOWNTO 0)
	);
END vram8k;

Instantiation:


	vram8k_inst : work.vram8k PORT MAP (
		data	 	=> v_data_sig,
		rdaddress 	=> v_address_r_sig(12 downto 0),
		rdclock	 	=> Clk_Z80,
		wraddress	=> v_address_w_sig(12 downto 0),
		wrclock	 	=> Clk_Z80,
		wren	 	=> vram_we_sig,
		rden	 	=> vram_re_sig,
		q			=> vram_q_sig
	);

I have tried a lot, and at this time, I have the following assertions for read/writing to the memory:


	v_address_w_sig <= A - x"2000" when (A >= x"2000" and MReq_n = '0');
	v_address_r_sig <= A - x"2000" when (A >= x"2000" and MReq_n = '0');
	vram_we_sig <= Wr_n;
	vram_re_sig <= Rd_n;
	v_data_sig <= DO_CPU when (Wr_n = '0' and MReq_n = '0');
        DI_CPU <= vram_q_sig when (Rd_n = '0' and MReq_n = '0' and A >= x"2000");

What must be changed for this to work?

Thanks.

15 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    It would be easier to have a design example, that contains the complete path from generating addresses, write data and control signals up to reading the data. From your post, I also don't see clearly, which step of the RAM access doesn't work as intended. This could easily be seen from a simulation, also a simulation would help us to understand the timing as achieved in the present design.

    I'm pretty sure that the intended operation can be performed with internal RAM if used correct.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    These seems to have worked very well:

    
    	-- Write into RAM
    	vram_wraddress_sig <= A - x"2000";
    	vram_wren_sig <= not Wr_n when (A >= x"2000" and A <= x"4000");
    	vram_data_sig <= DO_CPU;
    	-- Read from RAM
    	vram_rden_sig <= Rd_n;
    	vram_rdaddress_sig <= A - x"2000";
            DI_CPU <= vram_q_sig when (A >= x"2000" and A <= x"4000") else
    		         D_ROM when (Rd_n = '0' and MReq_n = '0' and A < x"2000") else
                             .....
    

    Also, I am now able to write using a 3.58Mhz clock, and read at 25Mhz.

    However, I am very confused. The LPM model for ram have control signals asserted low:

    ENTITY vram8k IS

    PORT

    (

    data : IN STD_LOGIC_VECTOR (7 DOWNTO 0);

    rdaddress : IN STD_LOGIC_VECTOR (12 DOWNTO 0);

    rdclock : IN STD_LOGIC ;

    rden : IN STD_LOGIC := '1';

    wraddress : IN STD_LOGIC_VECTOR (12 DOWNTO 0);

    wrclock : IN STD_LOGIC ;

    wren : IN STD_LOGIC := '1';

    q : OUT STD_LOGIC_VECTOR (7 DOWNTO 0)

    );

    END vram8k;

    In my code, asserting write HIGH will write data. Asserting READ LOW will read data. something is very wrong here.... Is it me?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I can't say anything about lpm_ram Megafunctions, I used altsyncram since Quartus V2, if I remember right. It has active high control signals, I would have thought the same of lpm_ram function, cause it's actually a wrapper of altsyncram, not inverting any signals as far as I see. Thus I guess, there is a misunderstanding of the basic operation of your design.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You might want to change this snipet of code...

    (A >= x"2000" and A <= x"4000")

    to

    (A >= x"2000" and A < x"4000")

    otherwise you will be writing to ram when the address is x"2000" and x"4000".