projet-fpga/Compteur_Tempo.vhd

86 lines
2.7 KiB
VHDL
Raw Normal View History

2022-03-21 10:29:51 +01:00
----------------------------------------------------------------------------------
-- Company: SORBONNE UNIVERSITE
-- Designed by: J.DENOULET, Winter 2021
--
-- Module Name: COMPTEUR_TEMPO - Behavioral
-- Project Name: Centrale DCC
-- Target Devices: NEXYS 4 DDR
--
-- Compteur de Temporisation de la Centrale DCC
--
-- Apr<70>s d<>tection du passage <20> 1 de la commande Start_Tempo,
-- le module compte 6 ms et positionne <20> 1 la sortie Fin_Tempo
--
-- Pour <20>tre d<>tect<63>e, la commande Start_Tempo doit <20>tre mise <20> 1
-- pendant au moins 1 p<>riode de l'horloge 100 MHz
--
2022-05-09 08:41:51 +02:00
-- Quand Fin_Tempo passe <20> 1, la sortie reste dans cet <20>tat tant que
2022-03-21 10:29:51 +01:00
-- Start_Tempo est <20> 1.
-- D<>s la d<>tection du retour <20> 0 de Start_Tempo,
-- Fin_Tempo repasse <20> 0.
--
2022-05-09 08:41:51 +02:00
-- De cette mani<6E>re, la dur<75>e minimale de l'impulsion <20> 1 de
2022-03-21 10:29:51 +01:00
-- Fin_Tempo sera d'un cycle de l'horloge 100 MHz.
-- Cela est a priori suffisant pour sa bonne d<>tection
-- par la MAE de la Centrale DCC.
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity COMPTEUR_TEMPO is
Port ( Clk : in STD_LOGIC; -- Horloge 100 MHz
Reset : in STD_LOGIC; -- Reset Asynchrone
Clk1M : in STD_LOGIC; -- Horloge 1 MHz
Start_Tempo : in STD_LOGIC; -- Commande de D<>marrage de la Temporisation
Fin_Tempo : out STD_LOGIC -- Drapeau de Fin de la Temporisation
);
end COMPTEUR_TEMPO;
architecture Behavioral of COMPTEUR_TEMPO is
2022-05-09 08:41:51 +02:00
signal Q : std_logic_vector(1 downto 0); -- Etat S<>quenceur
signal Raz_CPt, Inc_Cpt : std_logic; -- Commandes Compteur
signal Fin_Cpt : std_logic; -- Drapeau de Fin de Comptage
2022-03-21 10:29:51 +01:00
-- Compteur de Temporisation
signal Cpt : INTEGER range 0 to 10000; -- Compteur (6000 = 6 ms)
signal En_Tempo : STD_LOGIC; -- Commande d'Incr<63>mentation
begin
-- S<>quenceur
process(Clk,Reset)
begin
if Reset='1' then Q <= "00";
elsif rising_edge(Clk) then
Q(1) <= ((not Q(1)) and Q(0) and Fin_Cpt) or (Q(1) and Start_Tempo);
Q(0) <= Start_Tempo or ((not Q(1)) and Q(0));
end if;
end process;
-- Sorties S<>quenceur
Raz_Cpt <= Q(1) xnor Q(0);
Inc_Cpt <= (not Q(1)) and Q(0);
2022-05-09 08:41:51 +02:00
Fin_Tempo <= Q(1) and Q(0);
2022-03-21 10:29:51 +01:00
-- Compteur de Temporisation
2022-05-09 08:41:51 +02:00
process (Clk1M, Reset, Raz_Cpt)
2022-03-21 10:29:51 +01:00
begin
-- Reset Asynchrone
if (Reset) = '1' then
Cpt <= 0;
elsif rising_edge (Clk1M) then
if Raz_Cpt = '1' then Cpt <= 0;
elsif Inc_Cpt = '1' then Cpt <= Cpt + 1;
end if;
end if;
end process;
Fin_Cpt <= '1' when (Cpt = 5999) else '0';
end Behavioral;