Hola Lady_Hino y bienvenid@ al foro.
Para hacer un reloj en VHDL, lo primero que debes conocer es la frecuencia de entrada del reloj en tu sistema. Como sabrás, toda GAL o FPGA necesita un reloj para poder realizar las operaciones. Una vez que conozcas la frecuencia, debes hacer un divisor de reloj para obtener una señal de 1Hz. Una vez conseguido esto, nada más que hay que imcrementar los segundos, luegos los minutos, etc..
Aqui te dejo el código de lo que te acabo de contar. He suspuesto que la frecuencia del reloj de entrada es de 50MHz para hacer el divisor. Como verás es muy fácil cambiarla:
Codigo:
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 instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity reloj is
port (
clk : in std_logic;
rst : in std_logic;
segundos_LSB : inout std_logic_vector(3 downto 0);
segundos_MSB : inout std_logic_vector(3 downto 0);
minutos_LSB : inout std_logic_vector(3 downto 0);
minutos_MSB : inout std_logic_vector(3 downto 0);
horas_LSB : inout std_logic_vector(3 downto 0);
horas_MSB : inout std_logic_vector(3 downto 0)
);
end entity reloj;
architecture Behavioral of reloj is
signal contador : integer range 0 to 33554432;-- 25 bits
signal clk_1hz : std_logic;
begin -- architecture behavioral
-- proceso para conseguir una señal de 1HZ a partir de una señal "clk" de 50MHz
CLK_1HZ_PROC : process(clk, rst) is
begin
if (rst="1") then
contador <= 0;
elsif (clk"event and clk="1") then
if (contador = 25000000) then
clk_1hz <= not clk_1hz;
contador <= 0;
else
contador <= contador + 1;
end if;
end if;
end process CLK_1HZ_PROC;
-- proceso que incrementa los contadores a partir de la señal de 1Hz
RTC_PROC : process(clk_1hz, rst) is
begin
if (rst="1") then
segundos_LSB <= (others => "0");
segundos_MSB <= (others => "0");
minutos_LSB <= (others => "0");
minutos_MSB <= (others => "0");
horas_LSB <= (others => "0");
horas_MSB <= (others => "0");
elsif (clk_1hz"event and clk_1hz="1") then
if (segundos_LSB = "1001"
then
segundos_LSB <= (others => "0");
if (segundos_MSB = "0101"
then
segundos_MSB <= (others => "0");
if (minutos_LSB = "1001"
then
minutos_LSB <= (others => "0");
if (minutos_MSB = "0101"
then
minutos_MSB <= (others => "0");
if ((horas_LSB = "0011"
and (horas_MSB = "0010"
) then
horas_MSB <= (others => "0");
horas_LSB <= (others => "0");
elsif (horas_LSB = "1001"
then
horas_LSB <= (others => "0");
horas_MSB <= horas_MSB + "1";
else
horas_LSB <= horas_LSB + "1";
end if;
else
minutos_MSB <= minutos_MSB + "1";
end if;
else
minutos_LSB <= minutos_LSB + "1";
end if;
else
segundos_MSB <= segundos_MSB + "1";
end if;
else
segundos_LSB <= segundos_LSB + "1";
end if;
end if;
end process RTC_PROC;
end Behavioral;
Para hacer la alarma, deberás hacer un comparador con los segundos, minutos y horas a los que se programe la alarma y activar una señal cuando sean iguales.
Si depués vas a mostrar los datos en displays de 7 segmentos, vas a tener que programar un módulo para hacerlo.
Bueno, pues manos a la obra. Si tienes alguna duda ponla aqui.