--===========================================================================--
|
--===========================================================================--
|
--
|
--
|
-- S Y N T H E Z I A B L E miniUART C O R E
|
-- S Y N T H E Z I A B L E miniUART C O R E
|
--
|
--
|
-- www.OpenCores.Org - January 2000
|
-- www.OpenCores.Org - January 2000
|
-- This core adheres to the GNU public license
|
-- This core adheres to the GNU public license
|
|
|
-- Design units : miniUART core for the System68
|
-- Design units : miniUART core for the System68
|
--
|
--
|
-- File name : clkunit2.vhd
|
-- File name : clkunit2.vhd
|
--
|
--
|
-- Purpose : Implements an miniUART device for communication purposes
|
-- Purpose : Implements an miniUART device for communication purposes
|
-- between the CPU68 processor and the Host computer through
|
-- between the CPU68 processor and the Host computer through
|
-- an RS-232 communication protocol.
|
-- an RS-232 communication protocol.
|
--
|
--
|
-- Dependencies : ieee.std_logic_1164
|
-- Dependencies : ieee.std_logic_1164
|
-- ieee.numeric_std
|
-- ieee.numeric_std
|
--
|
--
|
--===========================================================================--
|
--===========================================================================--
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- Revision list
|
-- Revision list
|
-- Version Author Date Changes
|
-- Version Author Date Changes
|
--
|
--
|
-- 0.1 Ovidiu Lupas 15 January 2000 New model
|
-- 0.1 Ovidiu Lupas 15 January 2000 New model
|
-- olupas@opencores.org
|
-- olupas@opencores.org
|
--
|
--
|
-- 2.0 John Kent 10 November 2002 Added programmable baud rate
|
-- 2.0 John Kent 10 November 2002 Added programmable baud rate
|
-- 3.0 John Kent 15 December 2002 Fix TX clock divider
|
-- 3.0 John Kent 15 December 2002 Fix TX clock divider
|
-- 3.1 John kent 12 January 2003 Changed divide by 1 for 38.4Kbps
|
-- 3.1 John kent 12 January 2003 Changed divide by 1 for 38.4Kbps
|
-- 3.3 John Kent 6 September 2003 Changed Clock Edge.
|
-- 3.3 John Kent 6 September 2003 Changed Clock Edge.
|
-- dilbert57@opencores.org
|
-- dilbert57@opencores.org
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- Description : Generates the Baud clock and enable signals for RX & TX
|
-- Description : Generates the Baud clock and enable signals for RX & TX
|
-- units.
|
-- units.
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- Entity for Baud rate generator Unit - 9600 baudrate --
|
-- Entity for Baud rate generator Unit - 9600 baudrate --
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.numeric_std.all;
|
use ieee.numeric_std.all;
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- Baud rate generator
|
-- Baud rate generator
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
entity ClkUnit is
|
entity ClkUnit is
|
port (
|
port (
|
Clk : in Std_Logic; -- System Clock
|
Clk : in Std_Logic; -- System Clock
|
Reset : in Std_Logic; -- Reset input
|
Reset : in Std_Logic; -- Reset input
|
EnableRx : out Std_Logic; -- Control signal
|
EnableRx : out Std_Logic; -- Control signal
|
EnableTx : out Std_Logic; -- Control signal
|
EnableTx : out Std_Logic; -- Control signal
|
BaudRate : in Std_Logic_Vector(1 downto 0));
|
BaudRate : in Std_Logic_Vector(1 downto 0));
|
end; --================== End of entity ==============================--
|
end; --================== End of entity ==============================--
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- Architecture for Baud rate generator Unit
|
-- Architecture for Baud rate generator Unit
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
architecture Behaviour of ClkUnit is
|
architecture Behaviour of ClkUnit is
|
signal tmpEnRx : std_logic;
|
signal tmpEnRx : std_logic;
|
|
|
begin
|
begin
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
-- Divides the system clock of 40 MHz div 260 gives 153KHz for 9600bps
|
-- Divides the system clock of 40 MHz div 260 gives 153KHz for 9600bps
|
-- 48 MHz div 156 gives 306KHz for 19.2Kbps
|
-- 48 MHz div 156 gives 306KHz for 19.2Kbps
|
-- 24 MHz div 156 gives 153KHz for 9600bps
|
-- 24 MHz div 156 gives 153KHz for 9600bps
|
-- 9.8304MHz div 32 gives 306KHz for 19.2Kbps
|
-- 9.8304MHz div 32 gives 306KHz for 19.2Kbps
|
-- 4.9152MHz div 32 gives 153KHz for 9600bps
|
-- 4.9152MHz div 32 gives 153KHz for 9600bps
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
DivClk : process(Clk,Reset,tmpEnRx, BaudRate)
|
DivClk : process(Clk,Reset,tmpEnRx, BaudRate)
|
variable Count : unsigned(7 downto 0);
|
variable Count : unsigned(7 downto 0);
|
constant CntOne : Unsigned(7 downto 0):="00000001";
|
constant CntOne : Unsigned(7 downto 0):="00000001";
|
begin
|
begin
|
if Clk'event and Clk = '0' then
|
if Clk'event and Clk = '0' then
|
if Reset = '1' then
|
if Reset = '1' then
|
Count := "00000000";
|
Count := "00000000";
|
tmpEnRx <= '0';
|
tmpEnRx <= '0';
|
else
|
else
|
if Count = "00000000" then
|
if Count = "00000000" then
|
tmpEnRx <= '1';
|
tmpEnRx <= '1';
|
case BaudRate is
|
case BaudRate is
|
when "00" =>
|
when "00" =>
|
-- 6850 divide by 1 ((1*2)-1) (synchronous)
|
-- 6850 divide by 1 ((1*2)-1) (synchronous)
|
-- miniUart 9.83MHz div 16 = 38.4Kbps
|
-- miniUart 9.83MHz div 16 = 38.4Kbps
|
Count := "00001111";
|
Count := "00001111";
|
when "01" =>
|
when "01" =>
|
-- 6850 divide by 16 ((16*2)-1) (9600 Baud)
|
-- 6850 divide by 16 ((16*2)-1) (9600 Baud)
|
-- miniUart 9.83MHz div 32 = 19.2Kbps
|
-- miniUart 9.83MHz div 32 = 19.2Kbps
|
Count := "00011111";
|
Count := "00011111";
|
when "10" =>
|
when "10" =>
|
-- 6850 divide by 64 ((64*2)-1) (2400 Baud)
|
-- 6850 divide by 64 ((64*2)-1) (2400 Baud)
|
-- miniUart 9.83MHz div 128 = 4800bps
|
-- miniUart 9.83MHz div 128 = 4800bps
|
Count := "01111111";
|
Count := "01111111";
|
when others =>
|
when others =>
|
-- when "11" => -- reset
|
-- when "11" => -- reset
|
Count := "00000000";
|
Count := "00000000";
|
null;
|
null;
|
end case;
|
end case;
|
else
|
else
|
tmpEnRx <= '0';
|
tmpEnRx <= '0';
|
Count := Count - CntOne;
|
Count := Count - CntOne;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
EnableRx <= tmpEnRx;
|
EnableRx <= tmpEnRx;
|
end process;
|
end process;
|
|
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
-- Provides the EnableTX signal, at 9.6 KHz
|
-- Provides the EnableTX signal, at 9.6 KHz
|
-- Divide by 16
|
-- Divide by 16
|
-- Except it wasn't ... it counted up to "10010" (18)
|
-- Except it wasn't ... it counted up to "10010" (18)
|
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
DivClk16 : process(Clk,Reset,tmpEnRX)
|
DivClk16 : process(Clk,Reset,tmpEnRX)
|
variable Cnt16 : unsigned(4 downto 0);
|
variable Cnt16 : unsigned(4 downto 0);
|
constant CntOne : Unsigned(4 downto 0):="00001";
|
constant CntOne : Unsigned(4 downto 0):="00001";
|
begin
|
begin
|
if Clk'event and Clk = '0' then
|
if Clk'event and Clk = '0' then
|
if Reset = '1' then
|
if Reset = '1' then
|
Cnt16 := "00000";
|
Cnt16 := "00000";
|
EnableTX <= '0';
|
EnableTX <= '0';
|
else
|
else
|
case Cnt16 is
|
case Cnt16 is
|
when "00000" =>
|
when "00000" =>
|
if tmpEnRx = '1' then
|
if tmpEnRx = '1' then
|
Cnt16 := "01111";
|
Cnt16 := "01111";
|
EnableTx <='1';
|
EnableTx <='1';
|
else
|
else
|
Cnt16 := Cnt16;
|
Cnt16 := Cnt16;
|
EnableTx <= '0';
|
EnableTx <= '0';
|
end if;
|
end if;
|
when others =>
|
when others =>
|
if tmpEnRx = '1' then
|
if tmpEnRx = '1' then
|
Cnt16 := Cnt16 - CntOne;
|
Cnt16 := Cnt16 - CntOne;
|
else
|
else
|
Cnt16 := Cnt16;
|
Cnt16 := Cnt16;
|
end if;
|
end if;
|
EnableTX <= '0';
|
EnableTX <= '0';
|
end case;
|
end case;
|
end if;
|
end if;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|