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

Subversion Repositories System09

[/] [System09/] [trunk/] [rtl/] [VHDL/] [ACIA_Clock.vhd] - Blame information for rev 89

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

Line No. Rev Author Line
1 19 dilbert57
-----------------------------------------------------------------
2
--
3
-- ACIA Clock Divider for System09
4
--
5
-----------------------------------------------------------------
6
--
7
library IEEE;
8
   use IEEE.std_logic_1164.all;
9
   use IEEE.std_logic_arith.all;
10
   use IEEE.std_logic_unsigned.all;
11
 
12
package bit_funcs is
13
   function log2(v: in natural) return natural;
14
end package bit_funcs;
15
 
16
library IEEE;
17
   use IEEE.std_logic_1164.all;
18
   use IEEE.std_logic_arith.all;
19
   use IEEE.std_logic_unsigned.all;
20
 
21
package body bit_funcs is
22
   function log2(v: in natural) return natural is
23
      variable n: natural;
24
      variable logn: natural;
25
   begin
26
      n := 1;
27
      for i in 0 to 128 loop
28
         logn := i;
29
         exit when (n>=v);
30
         n := n * 2;
31
      end loop;
32
      return logn;
33
   end function log2;
34
 
35
end package body bit_funcs;
36
 
37
library ieee;
38
   use ieee.std_logic_1164.all;
39
   use IEEE.STD_LOGIC_ARITH.ALL;
40
   use IEEE.STD_LOGIC_UNSIGNED.ALL;
41
   use ieee.numeric_std.all;
42
library unisim;
43
        use unisim.vcomponents.all;
44
library work;
45
   use work.bit_funcs.all;
46
 
47
entity ACIA_Clock is
48
  generic (
49
     SYS_Clock_Frequency  : integer;
50
          ACIA_Clock_Frequency : integer
51
  );
52
  port(
53
    clk      : in  Std_Logic;  -- System Clock input
54
         ACIA_Clk : out Std_Logic   -- ACIA Clock output
55
  );
56
end ACIA_Clock;
57
 
58
-------------------------------------------------------------------------------
59
-- Architecture for ACIA_Clock
60
-------------------------------------------------------------------------------
61
architecture rtl of ACIA_Clock is
62
 
63
constant FULL_CYCLE : integer :=  (SYS_Clock_Frequency / ACIA_Clock_Frequency);
64
constant HALF_CYCLE : integer :=  (FULL_CYCLE / 2);
65
signal   ACIA_Count  : Std_Logic_Vector(log2(FULL_CYCLE) downto 0) := (Others => '0');
66
 
67
begin
68
--
69
-- Baud Rate Clock Divider
70
--
71
-- 25MHz / 27  = 926,000 KHz = 57,870Bd * 16
72
-- 50MHz / 54  = 926,000 KHz = 57,870Bd * 16
73
--
74
--my_ACIA_clock: process( clk, ACIA_Count  )
75
my_ACIA_clock: process( clk  )
76
begin
77
    if(clk'event and clk = '0') then
78
                if( ACIA_Count = (FULL_CYCLE - 1) )     then
79
                        ACIA_Clk   <= '0';
80
                   ACIA_Count <= (others => '0'); --"000000";
81
                else
82
                   if( ACIA_Count = (HALF_CYCLE - 1) )  then
83
                                ACIA_Clk <='1';
84
                        end if;
85
                   ACIA_Count <= ACIA_Count + 1;
86
                end if;
87
    end if;
88
end process;
89
 
90
end rtl;

powered by: WebSVN 2.1.0

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