library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--use IEEE.STD_LOGIC_Arith.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 Pract15 is
Port ( KB : in Unsigned (9 downto 0);
Start : in STD_LOGIC;
motor : out STD_LOGIC;
Stop : in STD_LOGIC;
SEGDP : out Unsigned (6 downto 0);
sensor : in STD_LOGIC;
CLKfast : in STD_LOGIC;
PolDP : out Unsigned (3 downto 0));
end Pract15;
architecture Behavioral of Pract15 is
signal C,RA,RB,CU1,CU2 : Unsigned(3 downto 0);
signal Q : unsigned(6 downto 0);
signal tecla,QCU: unsigned (1 downto 0);
signal SP,CU099 : UNSIGNED(7 downto 0);
signal q1,q2 : unsigned(3 downto 0);
signal MUXDP : unsigned (3 downto 0);
signal reset : std_logic ;
begin
teclado: process(KB, C, tecla) --este proceso es el encargado de registrar la cantidad
variable i: unsigned(1 downto 0) :="00"; --de veces que contará el sensor antes del reset de ciclo
begin
if KB ="0000000001" then
C <="0000"; tecla <= i;
elsif KB ="0000000010" then
C <= "0001"; tecla <= i;
elsif KB ="0000000100" then
C <= "0010"; tecla <= i;
elsif KB ="0000001000" then
C <= "0011"; tecla <= i;
elsif KB ="0000010000" then
C <= "0100"; tecla <= i;
elsif KB ="0000100000" then
C <= "0101"; tecla <= i;
elsif KB ="0001000000" then
C <= "0110"; tecla <= i;
elsif KB ="0010000000" then
C <= "0111"; tecla <= i;
elsif KB ="0100000000" then
C <= "1000"; tecla <= i;
else
C <= "1001"; tecla <= i;
end if;
if tecla ="00" then
RB <= C; -- Unidades
else
RA <= C; -- Decenas
end if;
i:= i+1;
if (i = "10") then
i := "00";
end if;
end process;
Convert: process(RA, RB) -- este proceso convierte los 2 numeros de BCD a entero
--variable X : UNsigned (7 downto 0);
begin
SP <= (RA*10)+(RB);
--SP <= X;
end process;
Memory: process(start, RA, RB) -- Esta memoria registra la cantidad a contar una vez que se
begin -- presiona el botón de iniciar (start)
if (start' event and start ='1') then
q1 <= RB;
q2 <= RA;
end if;
end process;
Contar99 : process(sensor,CU099, reset) -- Es el contador de conteo actual
begin
If reset = '1' or CU099 = "01100011" or stop = '1' then CU099 <= "00000000";
else
If sensor ' event and sensor = '1' then
CU099 <= CU099+1;
end if;
end if;
end process;
QuickCU: process(CLKfast, QCU) --Contador control de multiplexor de display
begin
if CLKfast' event and CLKfast = '1' then
if QCU = "11" then QCU <= "00";
else
QCU <= QCU+1;
end if;
end if;
end process;
CUnit : process ( sensor, CU1, CU2, reset) -- Este marca el conteo actual y lo envia al MUX para
begin -- los displays
IF stop = '1' or CU1 = "1010" or reset = '1' then CU1 <= "0000";
else
if sensor ' event and sensor = '1' then
CU1 <= CU1+1;
end if;
if (stop ='1' or CU2 = "1010") or reset = '1' then CU2 <= "0000";
if sensor' event and sensor ='1' and CU1 = "1010" then
CU2 <= CU2 +1;
end if;
end if;
end if;
end process;
CMP : process (SP, CU099) -- compara el conteo actual con el solicitado
begin
if SP = CU099 then
reset <= '1';
else reset <= '0';
end if;
end process;
Encoder : process(QCU) -- este polariza los displays
begin
case QCU is
when "11" => PolDP <= "1110";
when "10" => PolDP <= "1101";
when "01" => PolDP <= "1011";
when "00" => PolDP <= "0111";
when others => PolDP <= "1111";
end case;
end process;
MUX : process( q1,q2,CU1,CU2,QCU) -- multiplexa el numero que se observará en cada display
begin
case QCU is
when "11" => MUXDP <= q1;
when "10" => MUXDP <= q2;
when "01" => MUXDP <= CU1;
when "00" => MUXDP <= CU2;
when others => MUXDP <= "0000";
end case;
end process;
DISP : Process(MUXDP) --decoder de BCD a display 7 segmentos
begin
case MUXDP is
when "0000" => SEGDP <= "1000000";
when "0001" => SEGDP <= "1111001";
when "0010" => SEGDP <= "0100100";
when "0011" => SEGDP <= "0110000";
when "0100" => SEGDP <= "0011001";
when "0101" => SEGDP <= "0010010";
when "0110" => SEGDP <= "0000010";
when "0111" => SEGDP <= "1111000";
when "1000" => SEGDP <= "0000000";
when "1001" => SEGDP <= "0011000";
when others => SEGDP <= "1111111";
end case;
end process;
end Behavioral;