|
用ip核做一个双口ram:
大小为:15k×32bit;
A口配置为只写口(write only),地址线addr A,vs为写使能信号;
B口配置为只读口(read only),地址线addr B,tc为读使能信号;
tc>vs,所以tc由vs分频得到;
地址由计数器产生:对clk_in计数,vs是计数器控制信号,产生14位地址,直接接到A口,B口的地址线上;
A口,B口使用同步时钟clk_in;
源代码:--------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 08:52:10 08/17/07
-- Design Name:
-- Module Name: ram - Behave
-- Project Name:
-- Target Device:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
--------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity ram is
Port ( data_in : in std_logic_vector(31 downto 0);
clk_in : in std_logic;
vs : in std_logic;
reset: in std_logic;
data_out : out std_logic_vector(31 downto 0));
end ram;
architecture Behave of ram is
component dual_portram
port (
addra: IN std_logic_VECTOR(13 downto 0);
addrb: IN std_logic_VECTOR(13 downto 0);
clka: IN std_logic;
clkb: IN std_logic;
dina: IN std_logic_VECTOR(31 downto 0);
doutb: OUT std_logic_VECTOR(31 downto 0);
enb: IN std_logic;
wea: IN std_logic);
end component;
signal cnt: std_logic_vector(3 downto 0);
signal addre :std_logic_vector(13 downto 0);
signal tc: std_logic ;
begin
U1:process(clk_in,cnt)--对vs分频得到tc信号
begin
if (reset = '1') then
cnt<="0000" ;
elsif(vs'event and vs='1')then
cnt<=cnt+1;
end if;
end process;
tc<=cnt(1);
U2:process(clk_in,vs)
begin
if(vs='0') then
addre<="00000000000000";
elsif(clk_in'event and clk_in='1') then
addre<=addre+1;
end if;
end process;
U3:dual_portram
port map (
addra => addre,
addrb => addre,
clka => clk_in,
clkb => clk_in,
dina => data_in,
doutb => data_out,
enb => tc,
wea =>vs);
end Behave;
但功能仿真时,尽管输入不断变化,输出始终为零,不知道是哪出现问题了,敬请赐教,小弟不胜感激~~~! |
|