summaryrefslogtreecommitdiffstats
path: root/divider.vhd
blob: 1a8c2caf8686709aee51c8a4fd15bb66e11970ec (plain)
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
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.numeric_std.all;

entity divider is
    port
        (
            divisor : in  integer;
            clk     : in  std_logic;
            n_reset : in  std_logic;
            clk_out : out std_logic
            );
end divider;


architecture rtl of divider is

    component counter is
        port
            (
                divisor   : in  integer;
                clk       : in  std_logic;
                n_reset   : in  std_logic;
                pulse_out : out std_logic
                );
    end component;


    signal pulse : std_logic;
    signal q :
        std_logic;
begin

    clk_out <= q;

    c1 : counter port map (
        divisor   => divisor,
        clk       => clk,
        n_reset   => n_reset,
        pulse_out => pulse
        );


    process (clk, pulse, n_reset)
    begin
        if n_reset = '0' then
            q <= '0';
        elsif RISING_EDGE(clk) and pulse = '1' then
            q <= not q;
        end if;
    end process;

end rtl;