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

Subversion Repositories System68

[/] [System68/] [tags/] [arelease/] [vhdl/] [clkunit.vhd] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 dilbert57
--===========================================================================--
2
--
3
--  S Y N T H E Z I A B L E    miniUART   C O R E
4
--
5
--  www.OpenCores.Org - January 2000
6
--  This core adheres to the GNU public license  
7
 
8
-- Design units   : miniUART core for the OCRP-1
9
--
10
-- File name      : clkUnit.vhd
11
--
12
-- Purpose        : Implements an miniUART device for communication purposes 
13
--                  between the OR1K processor and the Host computer through
14
--                  an RS-232 communication protocol.
15
--                  
16
-- Library        : uart_lib.vhd
17
--
18
-- Dependencies   : IEEE.Std_Logic_1164
19
--
20
--===========================================================================--
21
-------------------------------------------------------------------------------
22
-- Revision list
23
-- Version   Author                 Date              Changes
24
--
25
-- 0.1      Ovidiu Lupas       15 January 2000        New model
26
--        olupas@opencores.org
27
-- 2.0      John Kent          10 November 2002       Added programmable baud rate
28
-- 3.0      John Kent          15 December 2002       Fix TX clock divider
29
-------------------------------------------------------------------------------
30
-- Description    : Generates the Baud clock and enable signals for RX & TX
31
--                  units. 
32
-------------------------------------------------------------------------------
33
-- Entity for Baud rate generator Unit - 9600 baudrate                       --
34
-------------------------------------------------------------------------------
35
library ieee;
36
   use ieee.std_logic_1164.all;
37
   use ieee.numeric_std.all;
38
library work;
39
--   use work.UART_Def.all;
40
-------------------------------------------------------------------------------
41
-- Baud rate generator
42
-------------------------------------------------------------------------------
43
entity ClkUnit is
44
  port (
45
     Clk      : in  Std_Logic;  -- System Clock
46
     Reset    : in  Std_Logic; -- Reset input
47
     EnableRx : out Std_Logic;  -- Control signal
48
     EnableTx : out Std_Logic;  -- Control signal
49
          BaudRate : in Std_Logic_Vector(1 downto 0));
50
end entity; --================== End of entity ==============================--
51
-------------------------------------------------------------------------------
52
-- Architecture for Baud rate generator Unit
53
-------------------------------------------------------------------------------
54
architecture Behaviour of ClkUnit is
55
signal tmpEnRx : std_logic;
56
 
57
begin
58
  -----------------------------------------------------------------------------
59
  -- Divides the system clock of 40 MHz div 260 gives 153 KHz for 9600bps
60
  --                             48 MHz div 156 gives 300 KHz for 19.2Kbps
61
  --                             24 MHz div 156 gives 153 KHz for 9600bps
62
  --                             4.9152MHz div 32 gives 153KHz for 9600bps 
63
  -----------------------------------------------------------------------------
64
  DivClk : process(Clk,Reset,tmpEnRx, BaudRate)
65
   variable Count  : unsigned(7 downto 0);
66
   constant CntOne : Unsigned(7 downto 0):="00000001";
67
   begin
68
     if Clk'event and Clk = '1' then
69
        if Reset = '1' then
70
           Count := "00000000";
71
           tmpEnRx <= '0';
72
        else
73
                          if Count = "00000000" then
74
                                 tmpEnRx <= '1';
75
                                 case BaudRate is
76
                                 when "00" => -- divide by 1 ((1*2)-1) (fast)
77
                                   Count := "00000001";
78
                                 when "01" => -- divide by 16 ((16*2)-1) (9600 Baud)
79
                                   Count := "00011111";
80
                                 when "10" => -- divide by 64 ((64*2)-1) (2400 Baud)
81
                                   Count := "01111111";
82
                                 when others =>
83
--                               when "11" => -- reset
84
                                   Count := "00000000";
85
                                   null;
86
                                 end case;
87
                          else
88
             tmpEnRx <= '0';
89
                       Count := Count - CntOne;
90
           end if;
91
        end if;
92
     end if;
93
     EnableRx <= tmpEnRx;
94
  end process;
95
 
96
  -----------------------------------------------------------------------------
97
  -- Provides the EnableTX signal, at 9.6 KHz
98
  -- Divide by 16
99
  -- Except it wasn't ... it counted up to "10010" (18)
100
  -----------------------------------------------------------------------------
101
  DivClk16 : process(Clk,Reset,tmpEnRX)
102
   variable Cnt16  : unsigned(4 downto 0);
103
   constant CntOne : Unsigned(4 downto 0):="00001";
104
   begin
105
    if Clk'event and Clk = '1' then
106
      if Reset = '1' then
107
        Cnt16 := "00000";
108
        EnableTX <= '0';
109
      else
110
        case Cnt16 is
111
          when "00000" =>
112
            if tmpEnRx = '1' then
113
              Cnt16 := "01111";
114
              EnableTx <='1';
115
                                else
116
                                  Cnt16 := Cnt16;
117
                                  EnableTx <= '0';
118
                                end if;
119
               when others =>
120
            if tmpEnRx = '1' then
121
              Cnt16 := Cnt16 - CntOne;
122
                                else
123
                                  Cnt16 := Cnt16;
124
                                end if;
125
            EnableTX <= '0';
126
        end case;
127
                end if;
128
    end if;
129
  end process;
130
end Behaviour; --==================== End of architecture ===================--

powered by: WebSVN 2.1.0

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