Sie sind auf Seite 1von 3

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

-- Company:
-- Engineer:
--
-- Create Date: 15:55:18 05/14/2018
-- Design Name:
-- Module Name: Contador - 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.numeric_std.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 Contador is
Port (
S0 : outSTD_LOGIC;
S1 : outSTD_LOGIC;
M0 : outSTD_LOGIC;
M1 : outSTD_LOGIC;
H0 : outSTD_LOGIC;
H1 : out STD_LOGIC;
clk : in STD_LOGIC;
reset : in STD_LOGIC;
ajusteMM : in STD_LOGIC;
ajusteHH : in STD_LOGIC;
ajuste : in STD_LOGIC);
end Contador;

architecture Behavioral of Contador is


signal ss1: unsigned (2 downto 0) := "000";
signal ss0: UNSIGNED (3 downto 0) := "0000";
signal mm1: UNSIGNED (2 downto 0) := "000";
signal mm0: UNSIGNED (3 downto 0) := "0000";
signal hh1: UNSIGNED (2 downto 0) := "000";
signal hh0: UNSIGNED (3 downto 0) := "0000";
signal clk1, clk2, clk3, clk4, clk5: std_logic:='0';
signal clk_a1, clk_a2: std_logic:='0';
signal ajuste_sync:std_logic;

begin
process (clk, reset, ajuste,ajusteHH,ajusteMM)

begin
--Reseteo
if (reset ='1') then
ss0<="0000";
ss1<="000";
mm0<="0000";
mm1<="000";
hh0<="0000";
hh1<="000";

else

--contador de segundos

if (clk'event and clk='1') then


ss0<= ss0+1;
clk1 <='0';
if (ss0=9) then
ss0<="0000";
clk1 <='1';
end if;
end if;

if (clk'event and clk='1') then


ss1<= ss1+1;
clk2<='0';
if (ss1=5) then
ss1<="000";
clk2<='1';
end if;
end if;

--se�al ajuste de minutis


--sincronizamos a los segundos

if (clk'event and clk='0') then


ajuste_sync<=ajuste;
end if;

clk_a1<=(clk2 and not ajuste_sync) or (ajusteMM and ajuste_sync);

--contador minutos

if (clk_a1'event and clk_a1='1') then


mm0<= mm0+1;
clk1 <='0';
if (mm0=9) then
mm0<="0000";
clk3 <='1';
end if;
end if;

if (clk3'event and clk3='1') then


mm1<= mm1+1;
clk4<='0';
if (mm1=5) then
mm1<="000";
clk4<='1';
end if;
end if;

--se�al ajuste horas


clk_a2<=(clk4 and not ajuste_sync) or (ajusteHH and ajuste_sync);

--contaddor horas
if (clk_a2'event and clk_a2='1') then
hh0<= hh0+1;
clk5 <='0';
if (hh0=9) then
hh0<="0000";
clk5 <='1';
end if;
end if;

if (clk5'event and clk5='1') then


hh1<= hh1+1;
end if;

if (hh1=2 and hh0=4) then


hh1<= "000";
hh0<= "0000";
clk_a1<='0';
clk_a2<='0';
clk1<='0';
clk2<='0';
clk3<='0';
clk4<='0';
clk5<='0';
end if;

end if;

end process;

----Asignaci�n de se�ales
--H1 <= STD_LOGIC_VECTOR(hh1);
--H0 <= STD_LOGIC_VECTOR(hh0);
--M1 <= STD_LOGIC_VECTOR(mm1);
--M0 <= STD_LOGIC_VECTOR(mm0);
--S1 <= STD_LOGIC_VECTOR(ss1);
--S0 <= STD_LOGIC_VECTOR(ss0);

end Behavioral;

Das könnte Ihnen auch gefallen