Sunteți pe pagina 1din 4

--------------------------------------------------------------------------------

--
-- Company:
-- Engineer:
--
-- Create Date: 11:49:11 05/14/2014
-- Design Name:
-- Module Name: Control_tenis - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
--------------------------------------------------------------------------------
--
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity Control_tenis is
Port ( Clk : in STD_LOGIC;
Reset : in STD_LOGIC;
Inicio : in STD_LOGIC;
Pulsa_der : in STD_LOGIC;
Pulsa_izq : in STD_LOGIC;
Sel_jugador : in STD_LOGIC;
Led : out STD_LOGIC_VECTOR (7 downto 0));
end Control_tenis;
architecture Behavioral of Control_tenis is
Constant Inicial:std_logic_vector(8 downto 0) :="000000000";
Constant Saca_der:std_logic_vector(8 downto 0) :="000000001";
Constant Led1_i:std_logic_vector(8 downto 0) :="000000010";
Constant Led2_i:std_logic_vector(8 downto 0) :="000000100";
Constant Led3_i:std_logic_vector(8 downto 0) :="000001000";
Constant Led4_i:std_logic_vector(8 downto 0) :="000010000";
Constant Led5_i:std_logic_vector(8 downto 0) :="000100000";
Constant Led6_i:std_logic_vector(8 downto 0) :="001000000";
Constant Rec_izq:std_logic_vector(8 downto 0) :="010000000";
Constant Led6_D:std_logic_vector(8 downto 0) :="101000000";
Constant Led5_D:std_logic_vector(8 downto 0) :="100100000";
Constant Led4_D:std_logic_vector(8 downto 0) :="100010000";
Constant Led3_D:std_logic_vector(8 downto 0) :="100001000";
Constant Led2_D:std_logic_vector(8 downto 0) :="100000100";
Constant Led1_D:std_logic_vector(8 downto 0) :="100000010";
Constant Rec_der:std_logic_vector(8 downto 0) :="100000001";
Constant Saca_izq:std_logic_vector(8 downto 0) :="110000000";
signal Estado_actual,Estado_siguiente : std_logic_vector(8 downto 0);
attribute FSM_ENCODING: string;
attribute FSM_ENCODING of Estado_actual : Signal is "USER";
Signal Pulsa_latch_der,Pulsa_latch_izq:std_logic;
Signal Clear_latch_der,Clear_latch_izq:std_logic;
Constant Num_bits:natural :=23; --Simul 3 funcionamiento 24
Signal Cuenta_tic : std_logic_vector(Num_bits-1 downto 0);
signal tic:std_logic;
Constant Cuenta_final : std_logic_vector(Num_bits-1 downto 0) :=(others
=>'1');
begin
--process que describe el flip-flop para pulsador derecha
process(Clk)
begin
if Clk'event and Clk='1' then
if Clear_latch_der='1' then
pulsa_latch_der<='0';
elsif Pulsa_der='1' then
pulsa_latch_der<='1';
end if;
end if;
end process;
--process que describe el flip-flop para pulsador izquierda
process(Clk)
begin
if Clk'event and Clk='1' then
if Clear_latch_izq='1' then
pulsa_latch_izq<='0';
elsif Pulsa_izq='1' then
pulsa_latch_izq<='1';
end if;
end if;
end process;
--process que describe el registro de estado de la FSM y el contador
process(Clk,Reset)
begin
if Reset='1'then
Estado_actual<=Inicial;
Cuenta_tic<=(others =>'0');
elsif Clk'event and Clk='1' then
if Tic='1' then
Estado_actual <=Estado_siguiente;
end if;
Cuenta_tic <= cuenta_tic +1;
end if;
end process;
tic<='1' when Cuenta_tic=Cuenta_final
else '0';
-- Process qe describe el estado siguiente y las salidas de la FSM
Process(Estado_actual,Inicio,Pulsa_latch_der,Pulsa_latch_izq,Sel_jugador
)
begin
Clear_latch_der <='0';
Clear_latch_izq <='0';
Case Estado_actual is
when Inicial =>
Clear_latch_der <='1';
Clear_latch_izq <='1';
if Inicio ='0' then
Estado_siguiente<=Inicial;
elsif Sel_jugador='0' then
Estado_siguiente <=Saca_der;
else
Estado_siguiente<=saca_izq;
end if;
when Saca_der=>
If Pulsa_latch_der='1' then
Estado_siguiente<=led1_I;
else
Estado_siguiente<=saca_der;
end if;
when led1_I=>
Estado_siguiente<=led2_I;
when led2_I=>
Estado_siguiente<=led3_I;
when led3_I=>
Estado_siguiente<=led4_I;
when led4_I=>
Estado_siguiente<=led5_I;
when led5_I=>
Clear_latch_izq<='1';
Estado_siguiente<=led6_I;
when led6_I=>
if Pulsa_latch_izq='1' then
Estado_siguiente<=Inicial;
else
Estado_siguiente<=Rec_izq;
end if;
when Rec_izq=>
if Pulsa_latch_izq='0' then
Estado_siguiente<=Inicial;
else
Estado_siguiente<=led6_D;
end if;
when led6_D=>
Estado_siguiente<=led5_D;
when led5_D=>
Estado_siguiente<=led4_D;
when led4_D=>
Estado_siguiente<=led3_D;
when led3_D=>
Estado_siguiente<=led2_D;
when led2_D=>
Clear_latch_der<='1';
Estado_siguiente<=led1_D;
when Led1_D=>
if Pulsa_latch_der='1' then
Estado_siguiente<=Inicial;
else
Estado_siguiente<=Rec_der;
end if;
when Rec_der=>
if Pulsa_latch_der='0' then
Estado_siguiente<=Inicial;
else
Estado_siguiente<=Led1_I;
end if;
when Saca_izq=>
If Pulsa_latch_izq='1' then
Estado_siguiente<=led6_D;
else
Estado_siguiente<=saca_izq;
end if;
when others =>
Estado_siguiente<=Inicial;
end case;
end process;
led<=Estado_actual(7 downto 0);
end Behavioral;

S-ar putea să vă placă și