2016-11-27 11 views
0

Ich arbeite an einem Projekt mit vhdl, um ein FPGA-Board Spartan 3E zu konfigurieren. was ich tun muss, ist ein geniales Puzzle, in meinem Hauptcode gibt es eine Zustandsmaschine, um die Logik zu steuern.VHDL-Code funktioniert nicht an Bord, aber arbeitet an Simulation

alles funktioniert gut, wenn ich den Code mit Xilinx-Simulator simulieren, aber wenn ich die .bit-Datei auf das FPGA-Board ausführen, was passiert ist, dass die erste LED der Sequenz anschaltet und dann ausschaltet, sollte dies aber dann passieren Ich klicke auf den rechten Knopf, es hört einfach auf zu arbeiten und die nächste Sequenz wird nie gezeigt. natürlich gibt es ein Problem, die Schaltflächen zu debuggen, und das ist der Grund, warum ich einen Zähler verwende, um die Repic zu verhindern, das System zu beschädigen.

Ich arbeite hart an diesem Code zu funktionieren, aber dieses Problem geht nicht weg, vielleicht mache ich etwas falsch, ich weiß es nicht oder ich mache nicht etwas, was ich sollte.

Hier ist mein Hauptcode, der die Zustandsmaschine und eine Uhr mit dem Zähler verarbeitet.

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: integer: = 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. 

Antwort

Verwandte Themen