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

Subversion Repositories uart16750

[/] [uart16750/] [trunk/] [rtl/] [vhdl/] [slib_clock_div.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 hasw
--
2
-- Clock divider (clock enable generator)
3
--
4
-- Author:   Sebastian Witt
5
-- Date:     27.01.2008
6
-- Version:  1.0
7
--
8
-- This code is free software; you can redistribute it and/or
9
-- modify it under the terms of the GNU Lesser General Public
10
-- License as published by the Free Software Foundation; either
11
-- version 2.1 of the License, or (at your option) any later version.
12
--
13
-- This code is distributed in the hope that it will be useful,
14
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
15
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
-- Lesser General Public License for more details.
17
--
18
-- You should have received a copy of the GNU Lesser General Public
19
-- License along with this library; if not, write to the
20
-- Free Software  Foundation, Inc., 59 Temple Place, Suite 330,
21
-- Boston, MA  02111-1307  USA
22
--
23
 
24
LIBRARY IEEE;
25
USE IEEE.std_logic_1164.all;
26
USE IEEE.std_logic_unsigned.all;
27
USE IEEE.numeric_std.all;
28
 
29
 
30
entity slib_clock_div is
31
    generic (
32
        RATIO       : integer := 4      -- Clock divider ratio
33
    );
34
    port (
35
        CLK         : in std_logic;     -- Clock
36
        RST         : in std_logic;     -- Reset
37
        CE          : in std_logic;     -- Clock enable input
38
        Q           : out std_logic     -- New clock enable output
39
    );
40
end slib_clock_div;
41
 
42
architecture rtl of slib_clock_div is
43
    -- Signals
44
    signal iQ       : std_logic;                  -- Internal Q
45
    signal iCounter : integer range 0 to RATIO-1; -- Counter
46
 
47
begin
48
    -- Main process
49
    CD_PROC: process (RST, CLK)
50
    begin
51
        if (RST = '1') then
52
            iCounter <= 0;
53
            iQ       <= '0';
54
        elsif (CLK'event and CLK='1') then
55
            iQ <= '0';
56
            if (CE = '1') then
57
                if (iCounter = (RATIO-1)) then
58
                    iQ <= '1';
59
                    iCounter <= 0;
60
                else
61
                    iCounter <= iCounter + 1;
62
                end if;
63
            end if;
64
        end if;
65
    end process;
66
 
67
    -- Output signals
68
    Q <= iQ;
69
 
70
end rtl;
71
 

powered by: WebSVN 2.1.0

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