2016-04-18 8 views
0

Ich schreibe VHDL-Code von Tic-Tac-Toe-Spiel. In meinem Code verzögert sich der Gewinnstatus um eine Runde.Tic-Tac-Toe in VHDL

(P.S. Ich bin nicht sehr vertraut mit Uhr so, ich muss und p2_play Wert, d. H. 1 oder 0 mit Kraft in der Wellenform). Kann mir bitte jemand vorschlagen, was mein Programm um 1 Umdrehung verzögert.

Vielen Dank.

Winning State (anklickbar)

 library IEEE; 
    use IEEE.STD_LOGIC_1164.ALL; 
    entity tttt1 is  
    Port (
     in1 : in STD_LOGIC; 
     in2 : in STD_LOGIC; 
     in3 : in STD_LOGIC; 
     in4 : in STD_LOGIC; 
     in5 : in STD_LOGIC; 
     in6 : in STD_LOGIC; 
     in7 : in STD_LOGIC; 
     in8 : in STD_LOGIC; 
     in9 : in STD_LOGIC; 
     p1_play : in STD_LOGIC; 
     p2_play : in STD_LOGIC; 
    p1_win : out STD_LOGIC; 
     p2_win : out STD_LOGIC; 
    out_11 : out STD_LOGIC; 
     out_12 : out STD_LOGIC; 
     out_13 : out STD_LOGIC; 
     out_21 : out STD_LOGIC; 
     out_22 : out STD_LOGIC; 
     out_23 : out STD_LOGIC; 
     out_31 : out STD_LOGIC; 
     out_32 : out STD_LOGIC; 
     out_33 : out STD_LOGIC); 

    end entity tttt1; 
    architecture Behavioral of tttt1 is 
    signal temp11, temp12, temp13, temp14, temp15, temp16, temp17, temp18, temp19, temp21, temp22, temp23, temp24, temp25, temp26, temp27, temp28, temp29 :std_logic :='0'; 
    signal p1win,p2win :std_logic :='0'; 
    signal o11,o12,o13,o21,o22,o23,o31,o32,o33:std_logic :='0'; 

    begin 
    process(in1,in2,in3,in4,in5,in6,in7,in8,in9) 
    begin 

-----------Start Player 1 Play------------- 

if(p1_play ='1' and p2_play='0') then 
if (in1= '1') then 
temp11 <='1'; 
temp21 <='0'; 
o11<='1'; 

elsif(in2= '1') then 
temp12 <='1'; 
temp22 <='0'; 
o12<='1'; 

elsif(in3= '1') then 
temp13 <='1'; 
temp23 <='0'; 
o13<='1'; 

elsif(in4= '1') then 
temp14 <='1'; 
temp24 <='0'; 
o21<='1'; 

elsif(in5= '1') then 
temp15 <='1'; 
temp25 <='0'; 
o22<='1'; 

elsif(in6= '1') then 
temp16 <='1'; 
temp26 <='0'; 
o23<='1'; 

elsif(in7= '1') then 
temp17 <='1'; 
temp27 <='0'; 
o31<='1'; 

elsif(in8= '1') then 
temp18 <='1'; 
temp28 <='0'; 
o32<='1'; 

elsif(in9= '1') then 
temp19 <='1'; 
temp29 <='0'; 
o33<='1'; 
end if; 
end if; 
if ((temp11='1' and temp12='1' and temp13='1') or (temp14='1' and temp15='1' and temp16='1') or (temp17='1' and temp18='1' and temp19='1') 
or (temp11='1' and temp14='1' and temp17='1') or (temp12='1' and temp15='1' and temp18='1') or (temp13='1' and temp16='1' and temp19='1') 
or (temp11='1' and temp15='1' and temp19='1') or (temp13='1' and temp15='1' and temp17='1')) then 
p1win<='1'; 
end if; 
---------------End Player 1 Play--------------- 
--------------Start Player 2 Play--------------     

if(p2_play ='1' and p1_play='0') then 
if (in1= '1')then 
temp21 <='1'; 
temp11 <='0'; 
o11<='1'; 

elsif(in2= '1') then 
temp22 <='1'; 
temp12 <='0'; 
o12<='1'; 

elsif(in3= '1') then 
temp23 <='1'; 
temp13 <='0'; 
o13<='1'; 

elsif(in4= '1') then 
temp24 <='1'; 
temp14 <='0'; 
o21<='1'; 

elsif(in5= '1') then 
temp25 <='1'; 
temp15 <='0'; 
o22<='1'; 

elsif(in6= '1') then 
temp26 <='1'; 
temp16 <='0'; 
o23<='1'; 

elsif(in7= '1') then 
temp27 <='1'; 
temp17 <='0'; 
o31<='1'; 

elsif(in8= '1') then 
temp28 <='1'; 
temp18 <='0'; 
o32<='1'; 

elsif(in9= '1') then 
temp29 <='1'; 
temp19 <='0'; 
o33<='1'; 
end if; 
end if; 

if( (temp21='1' and temp22='1' and temp23='1') or (temp24='1' and temp25='1' and temp26='1') or (temp27='1' and temp28='1' and temp29='1') 
or (temp21='1' and temp24='1' and temp27='1') or (temp22='1' and temp25='1' and temp28='1') or (temp23='1' and temp26='1' and temp29='1') 
or (temp21='1' and temp25='1' and temp29='1') or (temp23='1' and temp25='1' and temp27='1')) then 
    p2win<='1'; 

end if; 

---------------End Player 2 Play--------------- 
end process; 

p1_win <= p1win; 
p2_win <= p2win; 
out_11 <= o11; 
out_12 <= o12; 
out_13 <= o13; 
out_21 <= o21; 
out_22 <= o22; 
out_23 <= o23; 
out_31 <= o31; 
out_32 <= o32; 
out_33 <= o33; 

end Behavioral; 
+1

Bitte einrücken Sie Ihren Code, so dass wir es lesen können, ohne zu zählen Öffnen und Schließen if/end-if-Anweisungen ... Btw: Sie VHDL hat überhaupt kein Taktsignal. – Paebbels

+0

Beachten Sie, dass die rot gekennzeichneten Legenden in Ihrer Wellenform p2_win fälschlicherweise als p1_win identifizieren. – user1155120

Antwort

1

Die Ursache Ihrer Verzögerung auf p2_win zu sehen ist, dass temp11 durch temp13, temp21 durch Temp 23 und temp31 durch temp33 nicht in der Prozess Empfindlichkeit Liste sind (noch sollten sie sein) . Die Aktualisierung von p1_win oder p2_win findet erst statt, wenn in der Prozessempfindlichkeitsliste ein Signal auftritt, in diesem Fall ein Übergang auf in3 und in9.

machen die Zuweisungen an die beiden win Ausgänge trennen gleichzeitige Signal assigments wird die Verzögerung rechts:

tttt1_tb.png

Der modifizierte Code (mit Formatierung für Lesbarkeit) wie folgt aussieht:

library ieee; 
use ieee.std_logic_1164.all; 

entity tttt1 is 
    port (
     in1:  in std_logic; 
     in2:  in std_logic; 
     in3:  in std_logic; 
     in4:  in std_logic; 
     in5:  in std_logic; 
     in6:  in std_logic; 
     in7:  in std_logic; 
     in8:  in std_logic; 
     in9:  in std_logic; 
     p1_play: in std_logic; 
     p2_play: in std_logic; 
     p1_win:  out std_logic; 
     p2_win:  out std_logic; 
     out_11:  out std_logic; 
     out_12:  out std_logic; 
     out_13:  out std_logic; 
     out_21:  out std_logic; 
     out_22:  out std_logic; 
     out_23:  out std_logic; 
     out_31:  out std_logic; 
     out_32:  out std_logic; 
     out_33:  out std_logic 
    ); 
end entity tttt1; 

architecture behavioral of tttt1 is 
    signal temp11, temp12, 
      temp13, temp14, 
      temp15, temp16, 
      temp17, temp18, 
      temp19, temp21, 
      temp22, temp23, 
      temp24, temp25, 
      temp26, temp27, 
      temp28, temp29:  std_logic := '0'; 
    signal p1win,p2win:  std_logic := '0'; 
    signal o11,o12,o13,o21, 
      o22,o23,o31,o32, 
      o33:    std_logic := '0'; 

begin 

    process (in1,in2,in3,in4,in5,in6,in7,in8,in9) 
    begin 

-----------Start Player 1 Play------------- 

     if p1_play = '1' and p2_play = '0' then 
      if in1 = '1' then 
       temp11 <= '1'; 
       temp21 <= '0'; 
       o11 <= '1'; 

      elsif in2 = '1' then 
       temp12 <= '1'; 
       temp22 <= '0'; 
       o12 <= '1'; 

      elsif in3 = '1' then 
       temp13 <= '1'; 
       temp23 <= '0'; 
       o13 <= '1'; 

      elsif in4 = '1' then 
       temp14 <= '1'; 
       temp24 <= '0'; 
       o21 <= '1'; 

      elsif in5 = '1' then 
       temp15 <= '1'; 
       temp25 <= '0'; 
       o22 <= '1'; 

      elsif in6 = '1' then 
       temp16 <= '1'; 
       temp26 <= '0'; 
       o23<= '1'; 

      elsif in7 = '1' then 
       temp17 <= '1'; 
       temp27 <= '0'; 
       o31<= '1'; 

      elsif in8 = '1' then 
       temp18 <= '1'; 
       temp28 <= '0'; 
       o32 <= '1'; 

      elsif in9 = '1' then 
       temp19 <= '1'; 
       temp29 <= '0'; 
       o33 <= '1'; 
      end if; 
     end if; 

     -- if (temp11 = '1' and temp12 = '1' and temp13 = '1') or 
     --  (temp14 = '1' and temp15 = '1' and temp16 = '1') or 
     --  (temp17 = '1' and temp18 = '1' and temp19 = '1') or 
     --  (temp11 = '1' and temp14 = '1' and temp17 = '1') or 
     --  (temp12 = '1' and temp15 = '1' and temp18 = '1') or 
     --  (temp13 = '1' and temp16 = '1' and temp19 = '1') or 
     --  (temp11 = '1' and temp15 = '1' and temp19 = '1') or 
     --  (temp13 = '1' and temp15 = '1' and temp17 = '1') then 
     -- 
     --  p1win <= '1'; 
     -- 
     -- end if; 

---------------End Player 1 Play--------------- 

--------------Start Player 2 Play-------------- 

     if p2_play = '1' and p1_play = '0' then 
      if in1 = '1' then 
       temp21 <= '1'; 
       temp11 <= '0'; 
       o11 <= '1'; 

      elsif in2 = '1' then 
       temp22 <= '1'; 
       temp12 <= '0'; 
       o12 <= '1'; 

      elsif in3 = '1' then 
       temp23 <= '1'; 
       temp13 <= '0'; 
       o13 <= '1'; 

      elsif in4 = '1' then 
       temp24 <= '1'; 
       temp14 <= '0'; 
       o21 <= '1'; 

      elsif in5 = '1' then 
       temp25 <= '1'; 
       temp15 <= '0'; 
       o22 <= '1'; 

      elsif in6 = '1' then 
       temp26 <= '1'; 
       temp16 <= '0'; 
       o23 <= '1'; 

      elsif in7 = '1' then 
       temp27 <= '1'; 
       temp17 <= '0'; 
       o31 <= '1'; 

      elsif in8 = '1' then 
       temp28 <= '1'; 
       temp18 <= '0'; 
       o32 <= '1'; 

      elsif in9 = '1' then 
       temp29 <= '1'; 
       temp19 <= '0'; 
       o33 <= '1'; 
      end if; 
     end if; 

     -- if (temp21 = '1' and temp22 = '1' and temp23 = '1') or 
     --  (temp24 = '1' and temp25 = '1' and temp26 = '1') or 
     --  (temp27 = '1' and temp28 = '1' and temp29 = '1') or 
     --  (temp21 = '1' and temp24 = '1' and temp27 = '1') or 
     --  (temp22 = '1' and temp25 = '1' and temp28 = '1') or 
     --  (temp23 = '1' and temp26 = '1' and temp29 = '1') or 
     --  (temp21 = '1' and temp25 = '1' and temp29 = '1') or 
     --  (temp23 = '1' and temp25 = '1' and temp27 = '1') then 
     -- 
     --  p2win <= '1'; 
     -- 
     -- end if; 
---------------End Player 2 Play--------------- 
    end process; 

    p1win <= (temp11 and temp12 and temp13) or 
      (temp14 and temp15 and temp16) or 
      (temp17 and temp18 and temp19) or 
      (temp11 and temp14 and temp17) or 
      (temp12 and temp15 and temp18) or 
      (temp13 and temp16 and temp19) or 
      (temp11 and temp15 and temp19) or 
      (temp13 and temp15 and temp17); 

    p2win <= (temp21 and temp22 and temp23) or 
       (temp24 and temp25 and temp26) or 
       (temp27 and temp28 and temp29) or 
       (temp21 and temp24 and temp27) or 
       (temp22 and temp25 and temp28) or 
       (temp23 and temp26 and temp29) or 
       (temp21 and temp25 and temp29) or 
       (temp23 and temp25 and temp27); 

    p1_win <= p1win; 
    p2_win <= p2win; 
    out_11 <= o11; 
    out_12 <= o12; 
    out_13 <= o13; 
    out_21 <= o21; 
    out_22 <= o22; 
    out_23 <= o23; 
    out_31 <= o31; 
    out_32 <= o32; 
    out_33 <= o33; 

end architecture behavioral; 

Die funktionale Änderungen sind darauf beschränkt, den Win-Ausgabezuweisungen gleichzeitige Signalzuweisungsanweisungen zu geben.

wurde ein Prüfstand verwendet, um die Stimuli in verknüpften Wellenform zu reproduzieren:

library ieee; 
use ieee.std_logic_1164.all; 

entity tttt1_tb is 
end entity; 

architecture foo of tttt1_tb is 
    signal in1:  std_logic := '0'; 
    signal in2:  std_logic := '0'; 
    signal in3:  std_logic := '0'; 
    signal in4:  std_logic := '0'; 
    signal in5:  std_logic := '0'; 
    signal in6:  std_logic := '0'; 
    signal in7:  std_logic := '0'; 
    signal in8:  std_logic := '0'; 
    signal in9:  std_logic := '0'; 
    signal p1_play: std_logic := '0'; 
    signal p2_play: std_logic := '0'; 

    signal p1_win:  std_logic; 
    signal p2_win:  std_logic; 
    signal out_11:  std_logic; 
    signal out_12:  std_logic; 
    signal out_13:  std_logic; 
    signal out_21:  std_logic; 
    signal out_22:  std_logic; 
    signal out_23:  std_logic; 
    signal out_31:  std_logic; 
    signal out_32:  std_logic; 
    signal out_33:  std_logic; 

begin 
DUT: 
    entity work.tttt1 
     port map (
      in1 => in1, 
      in2 => in2, 
      in3 => in3, 
      in4 => in4, 
      in5 => in5, 
      in6 => in6, 
      in7 => in7, 
      in8 => in8, 
      in9 => in9, 
      p1_play => p1_play, 
      p2_play => p2_play, 

      p1_win => p1_win, 
      p2_win => p2_win, 
      out_11 => out_11, 
      out_12 => out_12, 
      out_13 => out_13, 
      out_21 => out_21, 
      out_22 => out_22, 
      out_23 => out_23, 
      out_31 => out_31, 
      out_32 => out_32, 
      out_33 => out_33 
     ); 
STIMULI: 
    process 
    begin 
     in1 <= '1'; 
     p1_play <= '1'; 
     wait for 100 ns; 
     in1 <= '0'; 
     in2 <= '1'; 
     p1_play <= '0'; 
     p2_play <= '1'; 
     wait for 100 ns; 
     in2 <= '0'; 
     in9 <= '1'; 
     p1_play <= '1'; 
     p2_play <= '0'; 
     wait for 100 ns; 
     in5 <= '1'; 
     in9 <= '0'; 
     p1_play <= '0'; 
     p2_play <= '1'; 
     wait for 100 ns; 
     in5 <= '0'; 
     in7 <= '1'; 
     p1_play <= '1'; 
     p2_play <= '0'; 
     wait for 100 ns; 
     in7 <= '0'; 
     in8 <= '1'; 
     p1_play <= '0'; 
     p2_play <= '1'; 
     wait for 100 ns; 
     in3 <= '1'; 
     in8 <= '0'; 
     p1_play <= '1'; 
     p2_play <= '0'; 
     wait for 100 ns; 
     wait;   

    end process; 
end architecture; 

Es gibt eine fehlende Regelprüfung auf einem Spieler einen Platz zu erfassen obliviously nicht zulassen. Diese Regel sollte ebenso implementiert werden wie eine Methode zum Löschen eines Spiels. Der Spielzustand wird in geschlussfolgerten Zwischenspeichern gehalten, die für eine breitere Synthese geeignet sind, wenn die Zwischenspeicher in einem separaten Prozess beschrieben wurden, der durch eine einzige Eingabe gesteuert wird. Es würde auch erwartet werden, dass die Eingaben entlarvt werden.

Da es eine Hardwareerwartung gibt, dass eine Eingabe stattfindet, während der Wert von p1_play und p2_play stabil ist, ist es möglich, eine Uhr zu verwenden und Eingabeereignisse (eine Uhr in Dauer) zu übergeben. Es war üblich, dass diese Arten von Spielen asynchron in Hardware-Implementierungen beschrieben wurden (denken Sie an die 70er und 80er Jahre).

+0

Dies ist sehr nützlich. Vielen Dank für die Beantwortung meiner Frage. Ich schätze deine Freundlichkeit sehr. – Sui