Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need help in designing RAM in Spartan 6 (using VHDL)

Status
Not open for further replies.

juansiahaan

Junior Member level 2
Joined
May 14, 2012
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,581
Hello everyone,

I'm trying to implement a simple RAM (for the SP601 evaluation kit) that will store a 12-bit data. I've seen many sample codes from XST user guide such as this one


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
 
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
 
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
 
entity RAM_src is
    PORT (CLK : in std_logic;
            en : in std_logic;
            we : in std_logic;
            addr : in std_logic_vector (5 downto 0);
            d_in : in std_logic_vector (11 downto 0);
            d_out : out std_logic_vector (11 downto 0)
            );
 
end RAM_src;
 
architecture Behavioral of RAM_src is
type ram_type is array (63 downto 0) of std_logic_vector (11 downto 0);
signal RAM : ram_type;
signal read_a : std_logic_vector (5 downto 0);
 
begin
d_out <= RAM(conv_integer(read_a));
 
    memory: process (CLK)
    begin
    if rising_edge (CLK) then
        if en = '1' then -- enable
            if we = '1' then -- write enable
                RAM(conv_integer(addr)) <= d_in;
                read_a <= addr;
            end if;
        end if;
    end if;
    end process memory;
 
end Behavioral;



From that code, is it possible that an input is stored/written in a selected/defined address so that I only have to access that address if I want to read that data?

Also, does anyone know how to test that RAM code (with testbench, maybe)?

Regards,

Juan
 

you probably want to make read_a a port, or remove it and place the d_out line in the enable if-else statement.
 

you probably want to make read_a a port, or remove it and place the d_out line in the enable if-else statement.

Hi Permute,

do you mean like this? I made a few changes though (but not many)


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
 
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
 
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
 
entity RAM_src is
    PORT (CLK : in std_logic;
            en : in std_logic; -- global enable
            we : in std_logic; -- write enable
            addr : in std_logic_vector (8 downto 0); -- adress bit vector
            d_in : in std_logic_vector (11 downto 0);
            d_out : out std_logic_vector (11 downto 0)
            );          
 
end RAM_src;
 
architecture Behavioral of RAM_src is
type ram_type is array (511 downto 0) of std_logic_vector (11 downto 0); --512 locations in RAM
signal RAM : ram_type;
 
begin
 
    memory : process (CLK)
    begin
    if rising_edge (CLK) then
        if en = '1' then
            if we = '1' then
                RAM(conv_integer(addr)) <= d_in; -- read
            end if;
                                d_out <= RAM(conv_integer(addr)); -- write
        end if;
    end if;
    end process memory;
 
end Behavioral;



so is there any way to select the address to store input only to that address?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top