jerryt
Junior Member level 3
I have a counter issue though in my tictactoe project design. I need a counter because the design requirements are to delay 2 seconds after the player makes the first tictactoe move.
My problem is the signal twosecwait gets set to '1' after a key is pressed by the player and then the counter will see a key is pressed by the player (twosecwait = '1') and set the cntr :=0. The next clock cycle however when scanning for a player key press the twosecwait signal will again get set high and in the counter process the twosecwait = '1' will be valid again and the cntr will get set back to 0 again. This puts me into an infinite loop where the counter will continuously be getting set back to 0 over and over again and will never count up to 2000 clock cycles until the twosecwait signal gets set to '0'.
Do you have any ideas on how I can do this? I can't set the twosecwait signal in both processes or I will get an "X" value for the twosecwait signal.
I really appreciate everyone's help...Thanks!!
----------------------------------------
My counter process:
CNTR_PROC : process(clk)
variable cntr : integer;
begin
if rising_edge(clk) then
cntr_done <= '0'; --cntr_done is a signal declared above that tells us whether the counter if finished or not
if reset = '1' or twosecwait = '1' then --twosecwait is a signal that says a player made his move last clock cycle
cntr := 0;
elsif cntr = 2000 then --this design uses a 1KHz clock so it takes ""2000 clk cycles"" to make a 2 sec wait
cntr_done <= '1';
else
cntr := cntr + 1;
end if;
end if;
end process CNTR_PROC;
---------------------------------------------------
My TicTacToe Algorithm Process (small portion of it):
TTT_ALGORITHM : process(clk)
if rising_edge(clk) then
if reset = 1 then
[RESET SIGNALS]
elsif reset = 0 then
if K1 = '1' then --where square = 10 means the player placed an X in that square
square1 <= "10"; --setting square for player move (making the square a X)
sG1 <= '1';
twosecwait <= '1';
elsif K2 = '1' then --where square = 10 means the player placed an X in that square
square2 <= "10"; --setting square for player move (making the square a X)
sG2 <= '1';
twosecwait <= '1';
end if;
--------------------------------------------------------------
My problem is the signal twosecwait gets set to '1' after a key is pressed by the player and then the counter will see a key is pressed by the player (twosecwait = '1') and set the cntr :=0. The next clock cycle however when scanning for a player key press the twosecwait signal will again get set high and in the counter process the twosecwait = '1' will be valid again and the cntr will get set back to 0 again. This puts me into an infinite loop where the counter will continuously be getting set back to 0 over and over again and will never count up to 2000 clock cycles until the twosecwait signal gets set to '0'.
Do you have any ideas on how I can do this? I can't set the twosecwait signal in both processes or I will get an "X" value for the twosecwait signal.
I really appreciate everyone's help...Thanks!!
----------------------------------------
My counter process:
CNTR_PROC : process(clk)
variable cntr : integer;
begin
if rising_edge(clk) then
cntr_done <= '0'; --cntr_done is a signal declared above that tells us whether the counter if finished or not
if reset = '1' or twosecwait = '1' then --twosecwait is a signal that says a player made his move last clock cycle
cntr := 0;
elsif cntr = 2000 then --this design uses a 1KHz clock so it takes ""2000 clk cycles"" to make a 2 sec wait
cntr_done <= '1';
else
cntr := cntr + 1;
end if;
end if;
end process CNTR_PROC;
---------------------------------------------------
My TicTacToe Algorithm Process (small portion of it):
TTT_ALGORITHM : process(clk)
if rising_edge(clk) then
if reset = 1 then
[RESET SIGNALS]
elsif reset = 0 then
if K1 = '1' then --where square = 10 means the player placed an X in that square
square1 <= "10"; --setting square for player move (making the square a X)
sG1 <= '1';
twosecwait <= '1';
elsif K2 = '1' then --where square = 10 means the player placed an X in that square
square2 <= "10"; --setting square for player move (making the square a X)
sG2 <= '1';
twosecwait <= '1';
end if;
--------------------------------------------------------------