2016-11-27 141 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. 

回答

相关问题