马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY ram4 IS
PORT (
aset : IN STD_LOGIC := '0'; -- aset='1'时才启动
address_a : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
address_b : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
address_c : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
address_d : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
clock : IN STD_LOGIC ;
data_a : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
data_b : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
data_c : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
data_d : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
wren : IN STD_LOGIC := '1';
q_a : OUT STD_LOGIC_VECTOR (31 DOWNTO 0);
q_b : OUT STD_LOGIC_VECTOR (31 DOWNTO 0);
q_c : OUT STD_LOGIC_VECTOR (31 DOWNTO 0);
q_d : OUT STD_LOGIC_VECTOR (31 DOWNTO 0)
);
END ram4;
ARCHITECTURE SYN OF ram4 IS
component ram2
PORT (
address_a : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
address_b : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
clock : IN STD_LOGIC ;
data_a : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
data_b : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
wren_a : IN STD_LOGIC := '1';
wren_b : IN STD_LOGIC := '1';
q_a : OUT STD_LOGIC_VECTOR (31 DOWNTO 0);
q_b : OUT STD_LOGIC_VECTOR (31 DOWNTO 0)
);
end component;
signal address_a_sig : STD_LOGIC_VECTOR (7 DOWNTO 0);
signal address_b_sig : STD_LOGIC_VECTOR (7 DOWNTO 0);
signal data_a_sig : STD_LOGIC_VECTOR (31 DOWNTO 0);
signal data_b_sig : STD_LOGIC_VECTOR (31 DOWNTO 0);
signal q_a_sig : STD_LOGIC_VECTOR (31 DOWNTO 0);
signal q_b_sig : STD_LOGIC_VECTOR (31 DOWNTO 0);
type state_type is (s0,s1,s2,s3) ; -- 状态机描述
signal present_state:state_type := S0; -- 初始设置很重要
begin
ram2_inst : ram2 -- 需要两个时钟周期
PORT MAP (
address_a => address_a_sig,
address_b => address_b_sig,
clock => clock,
data_a => data_a_sig,
data_b => data_b_sig,
wren_a => wren, -- 共用一个wren信号
wren_b => wren,
q_a => q_a_sig,
q_b => q_b_sig
);
state_fb :process(clock)
--signal present_state:state_type := s0;
begin
if(clock'event and clock = '1') then
case present_state is
when s0 =>
if aset = '1' then -- 前两个周期送地址值
address_a_sig <= address_a;
address_b_sig <= address_b;
data_a_sig <= data_a;
data_b_sig <= data_b;
present_state <= s1;
else
address_a_sig <= (others=>'Z');
address_b_sig <= (others=>'Z');
data_a_sig <= (others=>'Z');
data_b_sig <= (others=>'Z');
present_state <= s0;
end if;
when s1 =>
if aset = '1' then --
address_a_sig <= address_c;
address_b_sig <= address_d;
data_a_sig <= data_c;
data_b_sig <= data_d;
present_state <= s2;
else
address_a_sig <= (others=>'Z');
address_b_sig <= (others=>'Z');
data_a_sig <= (others=>'Z');
data_b_sig <= (others=>'Z');
present_state <= s0;
end if;
when s2 =>
if aset = '1' then -- 后两个周期取数据
address_a_sig <= address_a;
address_b_sig <= address_b;
q_a <= q_a_sig;
q_b <= q_b_sig;
present_state <= s0; -- ???这里赋s0时,仿真能看到前三个状态s0,s1,s2正常,当然这时进如不了S3,所以S3一直低电平,也可以说正常,也就是此时程序和波形一致,但是不符合设计要求而已;而这里赋s3时,s0,s1,s2,S3却全都一直低电平,就是此时程序和波形波不一致,
else
address_a_sig <= (others=>'Z');
address_b_sig <= (others=>'Z');
q_a <= (others=>'Z');
q_b <= (others=>'Z');
present_state <= s3;
end if;
when s3 =>
if aset = '1' then -- 后两个周期取数据
address_a_sig <= address_c;
address_b_sig <= address_d;
q_c <= q_a_sig;--(others=>'Z');--
q_d <= q_b_sig;
else
address_a_sig <= (others=>'Z');
address_b_sig <= (others=>'Z');
q_c <= (others=>'Z');
q_d <= (others=>'Z');
end if;
present_state <= s0;
end case;
end if;
end process state_fb;
END SYN;
Warning: Converted TRI buffer or tri-state bus to logic, or removed OPNDRN
Warning: Converting TRI node "data_b_sig[0]~1" that feeds logic to a wire
Warning: Converting TRI node "data_b_sig[1]~2" that feeds logic to a wire
Warning: Converting TRI node "data_b_sig[2]~3" that feeds logic to a wire
Warning: Converting TRI node "data_b_sig[3]~4" that feeds ..............
......................................................................................这个是编译的警告
希望高手排惑!!!! |