在网上找了下,发现都只有伪双口ram的vhdl程序,有谁知道真双口ram怎么做吗?求真双口ram的vhdl程序。谢!
答案:1 悬赏:80 手机版
解决时间 2021-03-31 12:41
- 提问者网友:喧嚣尘世
- 2021-03-30 16:40
在网上找了下,发现都只有伪双口ram的vhdl程序,有谁知道真双口ram怎么做吗?求真双口ram的vhdl程序。谢!
最佳答案
- 五星知识达人网友:我住北渡口
- 2021-03-30 17:42
这是我以前写的一个标准双端口ram,可以作为单端口或者双端口用
library ieee;
use ieee.std_logic_1164.all;
use IEEE.STD_LOGIC_ARITH.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
entity blk_mem is
generic(
data_width : integer := 8; -- used to change the memory data's width
addr_width : integer := 11); -- used to change the memery address' width
port (
clka : in std_logic;
dina : in std_logic_vector(data_width - 1 downto 0);
addra : in std_logic_vector(addr_width - 1 downto 0);
ena : in std_logic;
wea : in std_logic;
douta : out std_logic_vector(data_width - 1 downto 0);
clkb : in std_logic;
dinb : in std_logic_vector(data_width - 1 downto 0);
addrb : in std_logic_vector(addr_width - 1 downto 0);
enb : in std_logic;
web : in std_logic;
doutb : out std_logic_vector(data_width - 1 downto 0));
end blk_mem;
architecture blkmem of blk_mem is
type ram_template is array(2 ** addr_width - 1 downto 0) of std_logic_vector(data_width - 1 downto 0);
shared variable ram1 : ram_template;
begin -- blkmem
process (clka)
begin -- process
if clka'event and clka = '1' then -- rising clock edge
if ena = '1' then
douta <= ram1(conv_integer(addra));
if wea = '1' then
ram1(conv_integer(addra)) := dina;
end if;
else
douta <= (others => '0');
end if;
end if;
end process;
process (clkb)
begin -- process
if clkb'event and clkb = '1' then -- rising clock edge
if enb = '1' then
doutb <= ram1(conv_integer(addrb));
if web = '1' then
ram1(conv_integer(addrb)) := dinb;
end if;
else
doutb <= (others => '0');
end if;
end if;
end process;
end blkmem;追问如果A,B同时进行读写的时候,怎么办?不是会有冲突嘛。追答可以同时读写同一个地址,但是有优先的,一般是读优先
对AB的同时读写同一个地址是要你的控制部分避免的,
如果不是同一个地址的话就没问题
library ieee;
use ieee.std_logic_1164.all;
use IEEE.STD_LOGIC_ARITH.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
entity blk_mem is
generic(
data_width : integer := 8; -- used to change the memory data's width
addr_width : integer := 11); -- used to change the memery address' width
port (
clka : in std_logic;
dina : in std_logic_vector(data_width - 1 downto 0);
addra : in std_logic_vector(addr_width - 1 downto 0);
ena : in std_logic;
wea : in std_logic;
douta : out std_logic_vector(data_width - 1 downto 0);
clkb : in std_logic;
dinb : in std_logic_vector(data_width - 1 downto 0);
addrb : in std_logic_vector(addr_width - 1 downto 0);
enb : in std_logic;
web : in std_logic;
doutb : out std_logic_vector(data_width - 1 downto 0));
end blk_mem;
architecture blkmem of blk_mem is
type ram_template is array(2 ** addr_width - 1 downto 0) of std_logic_vector(data_width - 1 downto 0);
shared variable ram1 : ram_template;
begin -- blkmem
process (clka)
begin -- process
if clka'event and clka = '1' then -- rising clock edge
if ena = '1' then
douta <= ram1(conv_integer(addra));
if wea = '1' then
ram1(conv_integer(addra)) := dina;
end if;
else
douta <= (others => '0');
end if;
end if;
end process;
process (clkb)
begin -- process
if clkb'event and clkb = '1' then -- rising clock edge
if enb = '1' then
doutb <= ram1(conv_integer(addrb));
if web = '1' then
ram1(conv_integer(addrb)) := dinb;
end if;
else
doutb <= (others => '0');
end if;
end if;
end process;
end blkmem;追问如果A,B同时进行读写的时候,怎么办?不是会有冲突嘛。追答可以同时读写同一个地址,但是有优先的,一般是读优先
对AB的同时读写同一个地址是要你的控制部分避免的,
如果不是同一个地址的话就没问题
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯