
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
Verilog只能实现双口RAM的仿真模型,真的双口RAM是hard macro.不能用verilog实现的下面是一个例子,a口写,b口读。记住这只是仿真模型。真正实现是要调用hard macro的
xx是地址位宽
yy是数据位宽
module dual_port_ram(clka, clkb, addra, wr_data, wr_en, addrb, rd_data)
input clka, clkb
input [(xx-1):0] addra,addrb
input [(yy-1):0] wr_data
input wr_en
output [yy:0] rd_data;
reg [yy:0] ram_data[(xx^2)]
always @ (posedge clka)
if(wr_en)
ram_data[addra] <=wr_data
always @ (posedge clkb)
rd_data <= ram_data[addrb]
endmodule
inout [7:0] din这儿是一个小问题,改成input。
但是我不确定这个问题会不会造成你所说的仿真问题。
初看起来这个程序应该没有错,仿真出的是00000000而不是xxxxxxxx说明这个地址是写了东西进去的。自己找找看测试向量的问题,比如clk 比如 wr rd ain aout
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)