He codificado este estado en VHDL, pero tengo problemas para entrar en un estado determinado.
architecture Behavioral of game is
type LIST is ARRAY (11 downto 0) of std_logic_vector(3 downto 0);
Constant LISTEN: LIST := ("0010","0100","1000","0001","0100","0010","0010","0010","1000","0001","0010","0001");
begin
process(CLK)
variable prescaler: integer range 0 to 50000000;
Variable control: std_logic := '0';
variable pointer: integer range 0 to 11:=0;
variable test: std_logic:='0';
variable error: std_logic:='0';
variable top_pointer: integer range 0 to 11 := 0;
variable buttontimer: integer range 0 to 50000000 := 0;
begin
if rising_edge (clk) then
if control = '0' and error = '0' then
winLEd <= "01";
if(prescaler < 49999999/1) then
prescaler := prescaler + 1;
else
prescaler := 0;
top_pointer := top_pointer + 1; -- Top pointer increment
control := '1'; --- trigger event to get to new state
--test := '0';
end if;
end if;
if control = '1' and error = '0' then
winLEd <= "11";
-- test := '0';
if pointer > (top_pointer) then -- If pointer is higher than toppointer, it means the sequence has to be incrementet.
LED <= "0000";
control := '0';
pointer := 0;
test := '0';
error:= '0';
end if;
--if switch = "0000" then
if switch = LISTEN(pointer-1) and pointer<= top_pointer then -- Checks if the switch match the sequence.
test := '1';
buttontimer := buttontimer + 1;
errorLed <= "01";
if switch = "0000" and test = '1' and buttontimer < 49999999/1 then
pointer:= pointer +1;
test := '0';
errorLed <= "10";
buttontimer:= 0;
end if;
end if;
if switch /= LISTEN(pointer-1) and switch /= "0000" then -- if it doesn not match, error will be set high => trigger an new state.
error:= '1';
end if;
if switch = "0000" then
Led <= LISTEN(pointer-1);
errorLed <= "11";
error:= '0';
control := '1';
end if;
--end if;
end if;
if error = '1' then -- stays here infinetly until board is reset.
winLED <= "10";
errorLed <= "00";
Led <= switch;
end if;
end if;
end process;
end Behavioral;
Estoy teniendo problemas para aumentar el puntero aquí. Listen es una matriz, que contiene diferentes patrones de 4 bits. El interruptor es el interruptor en mi FGPA, he usado errorLED para ver dónde estoy en el código, veo que estoy ingresando esta instrucción if, cuando se cambia el patrón de 4 bits.