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

Subversion Repositories signed_unsigned_multiplier_and_divider

[/] [signed_unsigned_multiplier_and_divider/] [trunk/] [clock_divider.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 zpekic
----------------------------------------------------------------------------------
2
-- Company: @Home
3
-- Engineer: Zoltan Pekic (zpekic@hotmail.com)
4
-- 
5
-- Create Date:    16:56:54 02/13/2016 
6
-- Design Name: 
7
-- Module Name:    clock_divider - rtl 
8
-- Project Name:   Alarm Clock
9
-- Target Devices: Mercury FPGA + Baseboard (http://www.micro-nova.com/mercury/)
10
-- Tool versions:  Xilinx ISE 14.7 (nt64)
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22
 
23
-- Uncomment the following library declaration if using
24
-- arithmetic functions with Signed or Unsigned values
25
use IEEE.NUMERIC_STD.ALL;
26
 
27
-- Uncomment the following library declaration if instantiating
28
-- any Xilinx primitives in this code.
29
--library UNISIM;
30
--use UNISIM.VComponents.all;
31
 
32
entity clock_divider is
33
    Port ( reset : in  STD_LOGIC;
34
           clock : in  STD_LOGIC;
35
           slow : out  STD_LOGIC_VECTOR (11 downto 0);
36
                          baud : out STD_LOGIC_VECTOR(7 downto 0);
37
                          fast : out STD_LOGIC_VECTOR(4 downto 0)
38
                         );
39
end clock_divider;
40
 
41
architecture rtl of clock_divider is
42
        constant max_slowcount: integer := (50000000 / 2048); -- prescale to generate "even" frequencies
43
        constant max_baudcount: integer := (50000000 / 38400); -- prescale to generate "baudrate" frequencies
44
        signal scount: integer range 0 to max_slowcount := 0;
45
        signal bcount: integer range 0 to max_baudcount := 0;
46
        signal slow_cnt: unsigned(11 downto 0);
47
        signal fast_cnt: unsigned(4 downto 0);
48
        signal baud_cnt: unsigned(7 downto 0);
49
 
50
begin
51
 
52
        divider: process(clock, reset)
53
                begin
54
                if reset = '1' then
55
                        scount <= 0;
56
                        bcount <= 0;
57
                        slow_cnt <= X"000";
58
                        baud_cnt <= X"00";
59
                        fast_cnt <= "00000";
60
                else
61
                        if rising_edge(clock) then
62
                                fast_cnt <= fast_cnt + 1;
63
                                if scount = max_slowcount then
64
                                        scount <= 0;
65
                                        slow_cnt <= slow_cnt + 1;
66
                                else
67
                                        scount <= scount + 1;
68
                                end if;
69
                                if bcount = max_baudcount then
70
                                        bcount <= 0;
71
                                        baud_cnt <= baud_cnt + 1;
72
                                else
73
                                        bcount <= bcount + 1;
74
                                end if;
75
                        end if;
76
                end if;
77
        end process;
78
 
79
   -- connect divider outputs with internal counters
80
        slow <= std_logic_vector(slow_cnt);
81
        fast <= std_logic_vector(fast_cnt);
82
        baud <= std_logic_vector(baud_cnt);
83
end rtl;
84
 

powered by: WebSVN 2.1.0

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