OpenCores
URL https://opencores.org/ocsvn/tinyvliw8/tinyvliw8/trunk

Subversion Repositories tinyvliw8

[/] [tinyvliw8/] [trunk/] [src/] [vhdl/] [clock_divider.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 steckol
--
2
--      4-bit clock divider module
3
--
4
--    file:   clock_divider.vhd
5
--    author: Oliver Stecklina <stecklina@ihp-microelectronics.com
6
 
7
LIBRARY IEEE;
8
USE IEEE.STD_LOGIC_1164.ALL;
9
use ieee.std_logic_arith.all;
10
 
11
ENTITY clock_divider IS
12
        generic (n: integer := 2);
13
        PORT (
14
                inclk     : in  std_logic;
15
                outclk    : out std_logic;
16
 
17
                div       : in std_logic_vector((n - 1) downto 0);
18
                en        : IN std_logic
19
        );
20
END clock_divider;
21
 
22
ARCHITECTURE behav OF clock_divider IS
23
 
24
        signal clk_reg : std_logic_vector(((2 ** n) - 2) downto 0);
25
        signal clk_s   : std_logic_vector(((2 ** n) - 1) downto 0);
26
 
27
        signal enable_s : std_logic;
28
        signal outclk_s : std_logic_vector(((2 ** n) - 1) downto 0);
29
 
30
begin
31
 
32
        clk_s(0) <= inclk;
33
        enable_s <= en;
34
 
35
        gen_clk : process(enable_s, clk_s(0))
36
                variable cnt: unsigned (((2 ** n) - 2) downto 0);
37
        begin
38
                if (enable_s = '0') then
39
                        cnt := (others => '0');
40
                else
41
                        if (clk_s(0)'event and clk_s(0) = '0') then
42
                                cnt := cnt + 1;
43
                        end if;
44
                end if;
45
 
46
                clk_reg <= std_logic_vector(cnt);
47
        end process;
48
 
49
        clkSync_gen: for i in 1 to ((2 ** n) - 1) generate
50
        begin
51
                clk_sync : process(enable_s, clk_s(0))
52
                begin
53
                        if (enable_s = '0') then
54
                                clk_s(i) <= '0';
55
                        else
56
                                if (clk_s(0)'event and clk_s(0) = '1') then
57
                                        clk_s(i) <= clk_reg(i - 1);
58
                                end if;
59
                        end if;
60
                end process;
61
 
62
                outclk_s(i - 1) <= clk_s(i) when div = conv_std_logic_vector(i, n) else
63
                                   outclk_s(i);
64
        end generate;
65
 
66
        outclk_s((2 ** n) - 1) <= '0';
67
        outclk <= clk_s(0) when div = conv_std_logic_vector(0, n) else
68
                  outclk_s(0);
69
 
70
end behav;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.