1 |
2 |
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 System68
|
9 |
|
|
--
|
10 |
|
|
-- File name : clkunit2.vhd
|
11 |
|
|
--
|
12 |
|
|
-- Purpose : Implements an miniUART device for communication purposes
|
13 |
|
|
-- between the CPU68 processor and the Host computer through
|
14 |
|
|
-- an RS-232 communication protocol.
|
15 |
|
|
--
|
16 |
|
|
-- Dependencies : ieee.std_logic_1164
|
17 |
|
|
-- ieee.numeric_std
|
18 |
|
|
--
|
19 |
|
|
--===========================================================================--
|
20 |
|
|
-------------------------------------------------------------------------------
|
21 |
|
|
-- Revision list
|
22 |
|
|
-- Version Author Date Changes
|
23 |
|
|
--
|
24 |
|
|
-- 0.1 Ovidiu Lupas 15 January 2000 New model
|
25 |
|
|
-- olupas@opencores.org
|
26 |
|
|
--
|
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 |
|
|
-- 3.1 John kent 12 January 2003 Changed divide by 1 for 38.4Kbps
|
30 |
|
|
-- 3.3 John Kent 6 September 2003 Changed Clock Edge.
|
31 |
|
|
-- dilbert57@opencores.org
|
32 |
|
|
-------------------------------------------------------------------------------
|
33 |
|
|
-- Description : Generates the Baud clock and enable signals for RX & TX
|
34 |
|
|
-- units.
|
35 |
|
|
-------------------------------------------------------------------------------
|
36 |
|
|
-- Entity for Baud rate generator Unit - 9600 baudrate --
|
37 |
|
|
-------------------------------------------------------------------------------
|
38 |
|
|
library ieee;
|
39 |
|
|
use ieee.std_logic_1164.all;
|
40 |
|
|
use ieee.numeric_std.all;
|
41 |
|
|
-------------------------------------------------------------------------------
|
42 |
|
|
-- Baud rate generator
|
43 |
|
|
-------------------------------------------------------------------------------
|
44 |
|
|
entity ClkUnit is
|
45 |
|
|
port (
|
46 |
|
|
Clk : in Std_Logic; -- System Clock
|
47 |
|
|
Reset : in Std_Logic; -- Reset input
|
48 |
|
|
EnableRx : out Std_Logic; -- Control signal
|
49 |
|
|
EnableTx : out Std_Logic; -- Control signal
|
50 |
|
|
BaudRate : in Std_Logic_Vector(1 downto 0));
|
51 |
|
|
end; --================== End of entity ==============================--
|
52 |
|
|
-------------------------------------------------------------------------------
|
53 |
|
|
-- Architecture for Baud rate generator Unit
|
54 |
|
|
-------------------------------------------------------------------------------
|
55 |
|
|
architecture Behaviour of ClkUnit is
|
56 |
|
|
signal tmpEnRx : std_logic;
|
57 |
|
|
|
58 |
|
|
begin
|
59 |
|
|
-----------------------------------------------------------------------------
|
60 |
|
|
-- Divides the system clock of 40 MHz div 260 gives 153KHz for 9600bps
|
61 |
|
|
-- 48 MHz div 156 gives 306KHz for 19.2Kbps
|
62 |
|
|
-- 24 MHz div 156 gives 153KHz for 9600bps
|
63 |
|
|
-- 9.8304MHz div 32 gives 306KHz for 19.2Kbps
|
64 |
|
|
-- 4.9152MHz div 32 gives 153KHz for 9600bps
|
65 |
|
|
-----------------------------------------------------------------------------
|
66 |
|
|
DivClk : process(Clk,Reset,tmpEnRx, BaudRate)
|
67 |
|
|
variable Count : unsigned(7 downto 0);
|
68 |
|
|
constant CntOne : Unsigned(7 downto 0):="00000001";
|
69 |
|
|
begin
|
70 |
|
|
if Clk'event and Clk = '0' then
|
71 |
|
|
if Reset = '1' then
|
72 |
|
|
Count := "00000000";
|
73 |
|
|
tmpEnRx <= '0';
|
74 |
|
|
else
|
75 |
|
|
if Count = "00000000" then
|
76 |
|
|
tmpEnRx <= '1';
|
77 |
|
|
case BaudRate is
|
78 |
|
|
when "00" =>
|
79 |
|
|
-- 6850 divide by 1 ((1*2)-1) (synchronous)
|
80 |
|
|
-- miniUart 9.83MHz div 16 = 38.4Kbps
|
81 |
|
|
Count := "00001111";
|
82 |
|
|
when "01" =>
|
83 |
|
|
-- 6850 divide by 16 ((16*2)-1) (9600 Baud)
|
84 |
|
|
-- miniUart 9.83MHz div 32 = 19.2Kbps
|
85 |
|
|
Count := "00011111";
|
86 |
|
|
when "10" =>
|
87 |
|
|
-- 6850 divide by 64 ((64*2)-1) (2400 Baud)
|
88 |
|
|
-- miniUart 9.83MHz div 128 = 4800bps
|
89 |
|
|
Count := "01111111";
|
90 |
|
|
when others =>
|
91 |
|
|
-- when "11" => -- reset
|
92 |
|
|
Count := "00000000";
|
93 |
|
|
null;
|
94 |
|
|
end case;
|
95 |
|
|
else
|
96 |
|
|
tmpEnRx <= '0';
|
97 |
|
|
Count := Count - CntOne;
|
98 |
|
|
end if;
|
99 |
|
|
end if;
|
100 |
|
|
end if;
|
101 |
|
|
EnableRx <= tmpEnRx;
|
102 |
|
|
end process;
|
103 |
|
|
|
104 |
|
|
-----------------------------------------------------------------------------
|
105 |
|
|
-- Provides the EnableTX signal, at 9.6 KHz
|
106 |
|
|
-- Divide by 16
|
107 |
|
|
-- Except it wasn't ... it counted up to "10010" (18)
|
108 |
|
|
-----------------------------------------------------------------------------
|
109 |
|
|
DivClk16 : process(Clk,Reset,tmpEnRX)
|
110 |
|
|
variable Cnt16 : unsigned(4 downto 0);
|
111 |
|
|
constant CntOne : Unsigned(4 downto 0):="00001";
|
112 |
|
|
begin
|
113 |
|
|
if Clk'event and Clk = '0' then
|
114 |
|
|
if Reset = '1' then
|
115 |
|
|
Cnt16 := "00000";
|
116 |
|
|
EnableTX <= '0';
|
117 |
|
|
else
|
118 |
|
|
case Cnt16 is
|
119 |
|
|
when "00000" =>
|
120 |
|
|
if tmpEnRx = '1' then
|
121 |
|
|
Cnt16 := "01111";
|
122 |
|
|
EnableTx <='1';
|
123 |
|
|
else
|
124 |
|
|
Cnt16 := Cnt16;
|
125 |
|
|
EnableTx <= '0';
|
126 |
|
|
end if;
|
127 |
|
|
when others =>
|
128 |
|
|
if tmpEnRx = '1' then
|
129 |
|
|
Cnt16 := Cnt16 - CntOne;
|
130 |
|
|
else
|
131 |
|
|
Cnt16 := Cnt16;
|
132 |
|
|
end if;
|
133 |
|
|
EnableTX <= '0';
|
134 |
|
|
end case;
|
135 |
|
|
end if;
|
136 |
|
|
end if;
|
137 |
|
|
end process;
|
138 |
|
|
end Behaviour; --==================== End of architecture ===================--
|