Code Dram
Code Dram
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity dram_controller is
port(clk:in std_logic;
addr:in std_logic_vector(31 downto 0);
ads:in std_logic;
read_write:in std_logic;
reset:in std_logic;
ack:out std_logic;
we:out std_logic;
ready:out std_logic;
dram:out std_logic_vector(9 downto 0);
ras:out std_logic_vector(1 downto 0);
cas:out std_logic_vector(3 downto 0));
end;
process(reset,clk)
begin
if reset='1' then
stroed<=(others=>'0'); readr<='0';
elsif clk'event and clk='1' then
if ads='0' then
stroed<=addr; readr<=read_write;
end if;
end if;
end process;
process(row_addr,col_addr,present_state)
begin
if (present_state=row_address or present_state=ras_assert) then
dram<=row_addr;
else dram<=col_addr;
end if;
end process;
process(reset,clk)
begin
if reset='1' then
ref_timer<=(others=>'0');
elsif clk'event and clk='1' then
if ref_timer="100111000" then
ref_timer<=(others=>'0');
else ref_timer<=ref_timer+1;
end if;
end if;
end process;
process(present_state,ref_request,ads,match)
begin
case present_state is
when idle=>
if ref_request='1' then
next_state<=refresh0;
elsif ads='0' then
next_state<=address_detect;
else next_state<=idle;
end if;
when address_detect=>
if match='1' then
next_state<=row_address;
else next_state<=idle;
end if;
when row_address=>next_state<=ras_assert;
when ras_assert=>next_state<=col_address;
when col_address=>next_state<=cas_assert;
when cas_assert=>next_state<=data_ready;
when data_ready=>next_state<=wait_state;
when wait_state=>next_state<=idle;
when refresh0=>next_state<=refresh1;
when refresh1=>next_state<=idle;
end case;
end process;
process(reset,clk)
begin
if reset='1' then
present_state<=idle;
elsif clk'event and clk='1' then
present_state<=next_state;
end if;
end process;
end;