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

Subversion Repositories pdp8

[/] [pdp8/] [trunk/] [pdp8/] [uart/] [uart_brg.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 trurl
--------------------------------------------------------------------
2
--!
3
--! PDP-8 Processor
4
--!
5
--! \brief
6
--!      UART Baud Rate Generator
7
--!
8
--! \details
9
--!      This is a programmable frequency divider that generates
10
--!      common baud rates.
11
--!
12
--! \file
13
--!      uart_brg.vhd
14
--!
15
--! \author
16
--!      Rob Doyle - doyle (at) cox (dot) net
17
--!
18
--------------------------------------------------------------------
19
--
20
--  Copyright (C) 2009, 2010, 2011, 2012 Rob Doyle
21
--
22
-- This source file may be used and distributed without
23
-- restriction provided that this copyright statement is not
24
-- removed from the file and that any derivative work contains
25
-- the original copyright notice and the associated disclaimer.
26
--
27
-- This source file is free software; you can redistribute it
28
-- and/or modify it under the terms of the GNU Lesser General
29
-- Public License as published by the Free Software Foundation;
30
-- version 2.1 of the License.
31
--
32
-- This source is distributed in the hope that it will be
33
-- useful, but WITHOUT ANY WARRANTY; without even the implied
34
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
35
-- PURPOSE. See the GNU Lesser General Public License for more
36
-- details.
37
--
38
-- You should have received a copy of the GNU Lesser General
39
-- Public License along with this source; if not, download it
40
-- from http://www.gnu.org/licenses/lgpl.txt
41
--
42
--------------------------------------------------------------------
43
--
44
-- Comments are formatted for doxygen
45
--
46
 
47
library ieee;                                                   --! IEEE Library
48
use ieee.std_logic_1164.all;                                    --! IEEE 1164
49
use work.uart_types.all;                                        --! UART Types
50
use work.cpu_types.all;                                         --! CPU Types
51
 
52
--
53
--! UART Serial Interface Baud Rate Generator Entity
54
--
55
 
56
entity eUART_BRG is port (
57
    sys    : in  sys_t;                                         --! Clock/Reset
58
    uartBR : in  uartBR_t;                                      --! Baud Rate Select
59
    clkBR  : out std_logic                                      --! Baud Rate Clock Enable
60
);
61
end eUART_BRG;
62
 
63
--
64
--! UART Serial Interface Baud Rate Generator RTL
65
--
66
 
67
architecture rtl of eUART_BRG is
68
 
69
    constant clkfreq : integer := 50000000;
70
    constant clkdiv  : integer := 16;
71
 
72
begin
73
 
74
    --
75
    --! Programmable Clock Divider.
76
    --! This process generates a clkBR signal that is suitable for
77
    --! use as a 16x Baud Rate clock.   Both UART Transmitters and
78
    --! UART Receivers require this 16x clock.
79
    --
80
 
81
    UART_CLKDIV : process(sys)
82
       variable count : integer range 0 to 4095;
83
    begin
84
        if sys.rst = '1' then
85
            clkBR <= '0';
86
            count := 0;
87
        elsif rising_edge(sys.clk) then
88
            if count = 0 then
89
                case uartBR is
90
                    when uartBR1200 =>      --  1,200 (-0.016%)
91
                        count := clkfreq/clkdiv/1200;
92
                    when uartBR2400 =>      --  2,400 (-0.032%)
93
                        count := clkfreq/clkdiv/2400;
94
                    when uartBR4800 =>      --  4,800 (-0.032%)
95
                        count := clkfreq/clkdiv/4800;
96
                    when uartBR9600 =>      --  9,600 (+0.16%)
97
                        count := clkfreq/clkdiv/9600;
98
                    when uartBR19200 =>     -- 19,200 (+0.16%)
99
                        count := clkfreq/clkdiv/19200;
100
                    when uartBR38400 =>     -- 38,400 (+0.16%)
101
                        count := clkfreq/clkdiv/38400;
102
                    when uartBR57600 =>     -- 57,600 (+0.94%)
103
                        count := clkfreq/clkdiv/57600;
104
                    when uartBR115200 =>    -- 115,200 (+1.35%)
105
                        count := clkfreq/clkdiv/115200;
106
                    when others =>
107
                        null;
108
                end case;
109
                clkBR <= '1';
110
            else
111
               count := count - 1;
112
               clkBR <= '0';
113
            end if;
114
        end if;
115
    end process UART_CLKDIV;
116
 
117
end rtl;

powered by: WebSVN 2.1.0

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