1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
entity Compteur is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
load : in STD_LOGIC;
clock : in STD_LOGIC;
reset : in STD_LOGIC;
s : out STD_LOGIC_VECTOR (3 downto 0);
clk : in STD_LOGIC;
div_33554432 : out STD_LOGIC);
end Compteur;
architecture clk_div_262k_arch of clk_div_262k is -- architecture de mon diviseur d'horloge
signal div_32, div_1024, div_32768, div_8388608: std_logic_vector (15 downto 0) := (others => '0');
signal div_262144 : std_logic_vector (3 downto 0) := (others => '0');
signal temp_div_33554432 : std_logic_vector (1 downto 0) := (others => '0');
signal div_32_clk, div_1024_clk, div_32768_clk, div_262144_clk, div_8388608_clk : std_logic := '0';
begin
--compteur de période 16 et division par 32 = 2^5
process (CLK)
begin
if CLK'event and CLK='1' then
div_32 <= div_32(14 downto 0) & not div_32(15);
end if;
end process;
div_32_clk <= div_32(15);
--compteur de période 16 et division par 32 x 32 = 2^10
process (div_32_clk)
begin
if div_32_clk'event and div_32_clk='1' then
div_1024 <= div_1024(14 downto 0) & not div_1024(15);
end if;
end process;
div_1024_clk <= div_1024(15);
process (div_1024_clk)
begin
if div_1024_clk'event and div_1024_clk='1' then
div_32768 <= div_32768(14 downto 0) & not div_32768(15);
end if;
end process;
div_32768_clk <= div_32768(15);
process (div_32768_clk)
begin
if div_32768_clk'event and div_32768_clk='1' then
div_262144 <= div_262144(2 downto 0) & not div_262144(3);
end if;
end process;
div_262144_clk <= div_262144(3);
process (div_262144_clk)
begin
if div_262144_clk'event and div_262144_clk='1' then
div_8388608 <= div_8388608(14 downto 0) & not div_8388608(15);
end if;
end process;
div_8388608_clk <= div_8388608(15);
process (div_8388608_clk)
begin
if div_8388608_clk'event and div_8388608_clk='1' then
temp_div_33554432 <= temp_div_33554432(0) & not temp_div_33554432(1);
end if;
end process;
div_33554432 <= temp_div_33554432(1) ;
end clk_div_262k_arch; -- fin architecture de mon diviseur d'horloge
architecture Compteur_arch of Compteur is -- architecture de mon compteur, que je souhaite synchronisé avec mon horloge divisée (ici, synchronisée avec l'horloge par defaut de la FPGA)
signal scpt : STD_LOGIC_VECTOR (3 downto 0):= (others =>'0');
begin
process (clock,load) begin
if (reset='1')then
scpt <= (others => '0');
elsif (rising_edge(clock)) then
if (load='1') then
scpt <= a;
else
scpt <= scpt +1;
end if;
end if;
end process;
s <= scpt;
end Compteur_arch; |
Partager