求助:使用外部SRAM验证跑马灯为什么程序会跑飞
LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
ENTITY ledwater IS
PORT(
osclk : IN STD_LOGIC; --20MHZ
we : OUT STD_LOGIC; --sram write/read,片选CS是一直接地的
oe : OUT STD_LOGIC; --sram output enable
data : INOUT STD_LOGIC_VECTOR(7 DOWNTO 0);
address: OUT integer range 0 to 7;--只用8个地址
datatmp: OUT STD_LOGIC_VECTOR(7 DOWNTO 0)
);
END ledwater;
ARCHITECTURE led OF ledwater IS
type state is(prepare,write_address,write_data,
read_address,read_data,stop);
SIGNAL current_state : state;
SIGNAL sram_clk : STD_LOGIC;
SIGNAL LED_50 :STD_LOGIC;
SIGNAL reg : STD_LOGIC_VECTOR(7 DOWNTO 0) :="00000001";--跑马灯数据
SIGNAL addr: integer range 0 to 8;
BEGIN
PROCESS(osclk)
variable count1 : integer range 0 to 100;
variable t : integer range 0 to 1000000000;
variable n : integer range 0 to 7;
begin
if(osclk'event and osclk='1')then
case current_state is
when prepare => count1:=count1+1; oe<='0';
-- addr <= 0;
-- n := 0;
if(count1=50) then current_state <= write_address;count1:=0;
else current_state <= prepare;
end if ;
when write_address=> count1:=count1+1;--先写地址,再写数据
if addr = 7 then
addr <= 0;
else
if(count1=10) then current_state <= write_data;count1:=0;
addr <= addr + 1 ;
else current_state <= write_address;
end if ;
end if;
when write_data =>
data <= reg;
reg <= reg(6 downto 0)& reg(7); 数据循环
count1:=count1+1;
if(count1<3) then we<='1';
elsif(count1<10) then we<='0';
elsif(count1=11) then we<='1';
if(addr =7 )then current_state<=read_address;count1:=0;
else current_state<=write_address; count1:=0;
end if;
end if ;
when read_address => addr<= n;count1:=count1+1;
if(count1=2)then
current_state<=read_data; count1:=0;data<="ZZZZZZZZ";we<='1';
end if ;
when read_data => count1:=count1+1;
if(count1=2) then datatmp<=data;--读写一个数据,延时2.5S
current_state<=stop;
else current_state<=read_data;
end if;
when stop =>
IF( t =50000000) THEN ----delay 2.5S
t := 0;
if(n =7) then n:=0;
else current_state<=read_address;n:= n +1;
end if;
current_state<=prepare;
else t:=t+1;
end if;
when others => null;
end case;
end if ;
address <= addr;
end process;
END led;
--此程序是用来验证使用外部SRAM,显示由8个LED组成,设计初衷是使LED顺序亮起来(12345678),但是实际运行起来是,亮的顺序是7465128,请高手帮看一下,是哪里出问题了。 回复【楼主位】torchchinaled
-----------------------------------------------------------------------
你试下在data<="ZZZZZZZZ";后面加多一句datatmp<="ZZZZZZZZ"; 试了一下,没有效果,有人做过的,请指点一下,谢谢! 嵌入一个逻辑分析仪,一级一级的找 原因。 楼上能说具体点吗,是在QUARTUSII软件中嵌入吗。
页:
[1]