2016-11-27 167 views
0

我正在使用vhdl來配置fpga板子的項目斯巴達3E。我必須做的是一個天才謎題,在我的主代碼中有一個狀態機來控制邏輯。VHDL代碼不在板上工作,但在仿真上工作

當我使用xilinx模擬器模擬代碼,但是當我將.bit文件運行到FPGA板時,一切正常,會發生什麼情況是序列的第一個指示燈會亮起然後熄滅,這會發生,我點擊右鍵就停止工作,下一個序列從不顯示。 當然有一個deboucing按鈕的問題,這就是我使用一個計數器來防止repic bug系統的原因。

我正在努力在這個代碼上運行,但是這個問題並沒有消失,也許我做錯了什麼,我不知道或者我沒有做我應該做的事情。

這裏是我的主要代碼,它是狀態機和計數器的時鐘進程。

Flag_conte = starts ou blocks the counter 
Flag_estou_contando = 1=counting, 0= not counting, 3= just finished count. 
BCD = board buttons IN 
LEDs = corresponds to 4 leds that will show the sequence in the game 

entity Algoritmo is 
    port(
     clk: in std_logic; 
     BCD: in std_logic_vector (3 downto 0); 
      botaoStart: in std_logic;  
     botaoReset: in std_logic;   
      seven_seg: out std_logic_vector(6 downto 0); 
      anode: out std_logic_vector(3 downto 0); 
      LEDS: out std_logic_vector(3 downto 0) 
     ); 
END Algoritmo; 

architecture Behavioral of Algoritmo is 

    subtype state_type is integer range 5 downto 0; 
    signal state, nextstate: state_type:=0; 
    signal Inicio, nclk: std_logic:= '0'; 
    --variable posicaoAtual: integer :=0; 
    type mem1 is array (0 to 13) of std_logic_vector (3 downto 0);  
    constant vetorSequencia: mem1 := ("0001", "0010", "0100", "1000", "0001", "0010", "0100", "1000", "0001", "0010", "0100", "1000", "0001", "0010"); 

    constant generic1hz: integer:= 12_500_000; 
    signal t3count:integer:=0; 
    signal posA, posB, signalScore, Flag_conte, 

Flag_estou_contando:整數:= 0;

signal valor: integer :=12_500_000; 
Begin 
------------- 
process (state,BCD,botaoStart,Flag_estou_contando) 
variable Pos: integer :=0; 
variable score: integer:=0; 
variable posicaoAtual: integer:=0; 
variable tentativa: std_logic_vector (3 downto 0); 
begin 
    case state is 
    when 0 => if (botaoStart = '0') 
    then nextstate <= 0;-- estado idle, esperando entrada do tclado,led1=1; 
        else nextstate <= 1; 
        end if; 

     when 1 =>-- if(Flag_estou_contando =0)then 
         if(nextstate=2)then 
          Flag_conte <=0; 
          nextstate <= 2; 
         else if (nextstate/=2)then 
          if (posicaoAtual < score)then 
            if(Flag_estou_contando=0)then 
          LEDS <= vetorSequencia(posicaoAtual); 
             posA <= posicaoAtual; 
             Flag_conte<=1; 
             valor<=10_000_000; 
            else if(Flag_estou_contando=1)then 
             LEDS <=vetorSequencia(posicaoAtual); 
            else if (Flag_estou_contando=3)then 
             --posicaoAtual:=0; 
             posicaoAtual := posicaoAtual + 1; 
             posA <= posicaoAtual; 
             nextstate <=1; 
             Flag_conte<=0; 
            end if;end if;end if; 

          else if(posicaoAtual = score)then 
            if(Flag_estou_contando=0)then 
             Flag_conte<=1; 
             valor<=10_000_000; 
             -- posicaoAtual :=0; 
             posA <= posicaoAtual; 
            else if(Flag_estou_contando=1)then 
             LEDS <=vetorSequencia(posicaoAtual); 
             nextstate<=1; 
            else if(Flag_estou_contando=3)then 
             posicaoAtual:=0; 
             posA <= posicaoAtual; 
             Flag_conte<=0; 
             nextstate <= 2; 
            end if;end if;end if; 
          end if;end if; 
          Flag_conte <=1; 
         end if;end if; 


     when 2 => --if(Flag_estou_contando=0)then 
        if (BCD = "0000")then 
         if(Flag_estou_contando=0)then 
         LEDS <= "0000"; --nextstate <= 2; 
         else if (Flag_estou_contando=1)then 
          nextstate<=2; 
            else if (Flag_estou_contando=3)then 
             Flag_conte <= 0; 
             nextstate<=3; 
            end if;end if;end if; 
          else if(BCD /= "0000")then 
            if(Flag_estou_contando=0)then 
             Flag_conte<=1; 
             valor<=200_000_000; 
             tentativa := BCD; 
             LEDS <= tentativa; 
            else if(Flag_estou_contando=3)then 
             nextstate <= 3; 
            else if(Flag_estou_contando=1)then 
             LEDS <= tentativa; 
             nextstate <=2; 
            end if;end if;end if; 
          end if;end if; 

       when 3 => if (vetorSequencia(Pos) = tentativa)then 
           if (Pos < score)then 
             nextstate <= 2; 
             Pos := Pos + 1; 
             posB <= Pos; 
           else if(Pos = score)then 
             score := score + 1; 
             signalScore <= score; 
             nextstate <= 1; 
             Pos := 0; 
           if (score = 15)-- if score =15 finish game 
              then nextstate <= 5;  
             end if;--end if 
           end if;end if; 
         else -- se estiver errado, perde o jogo 
          nextstate <= 4; -- goes to game over 
        end if;     

     when 4 => if (botaoReset = '1') -- game over 
           then nextstate <= 4;-- "U LOST nOOB" 
       elsif (botaoReset = '0') 
          then nextstate <= 0; -- 
       end if; 
     when 5 => if (botaoReset = '1') -- jogo ganho 
           then nextstate <= 5; -- "GG" 
         elsif (botaoReset = '0') 
           then nextstate <= 0; 
        end if;  
     end case; 


end process; 

    process (clk, Flag_conte) 

    variable sum, count :integer:=0; 
    begin 



if rising_edge(clk) then 
     if(Flag_estou_contando = 0) then 
      if (Flag_conte = 1) then 
       count :=0; 
       Flag_estou_contando <=1; 
      end if; 
     end if; 
    if(Flag_estou_contando=3) then  
     if(Flag_conte =0)then 
      Flag_estou_contando <= 0; 
     else 
      Flag_estou_contando <=3; 
     end if; 
    end if; 

    if (Flag_estou_contando =1)then 
     if(count < valor)then 
      count := count + 1; 
     else 
      count:=0; 
      Flag_estou_contando <=3;   
     end if; 
    end if; 

    sum := sum +1;    
    if(sum = generic1hz)then -- 1hz generate 
     state <= nextstate; 
     nclk <= not nclk; 
     sum := 0;--restart count for 1hz generate 

    end if; 
end if; 

end process; 
end Behavioral; 

if i wasnt clear, please let me know i will try to explain better, if anyone could help i would be very greatful, thank you for your time. 

回答

相關問題