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

Subversion Repositories c16

[/] [c16/] [trunk/] [vhdl/] [BaudGen.vhd] - Blame information for rev 33

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

Line No. Rev Author Line
1 2 jsauermann
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.STD_LOGIC_ARITH.ALL;
4
use IEEE.STD_LOGIC_UNSIGNED.ALL;
5
 
6
use STD.TEXTIO.ALL;
7
 
8
--  Uncomment the following lines to use the declarations that are
9
--  provided for instantiating Xilinx primitive components.
10
--library UNISIM;
11
--use UNISIM.VComponents.all;
12
 
13
entity BaudGen is
14
        Generic(bg_clock_freq : integer; bg_baud_rate  : integer);
15
    Port( CLK_I  : in  std_logic;
16 9 jsauermann
           RST_I : in  std_logic;
17 2 jsauermann
           CE_16 : out std_logic
18
                );
19
end BaudGen;
20
 
21
architecture Behavioral of BaudGen is
22
 
23
        -- divide bg_clock_freq and bg_baud_rate
24
        -- by their common divisor...
25
        --
26
        function gcd(M, N: integer) return integer is
27
        begin
28
                if ((M mod N) = 0) then          return N;
29
                else                                            return gcd(N, M mod N);
30
                end if;
31
        end;
32
        constant common_div : integer := gcd(bg_clock_freq, 16 * bg_baud_rate);
33
        constant clock_freq : integer := bg_clock_freq     / common_div;
34
        constant baud_freq  : integer := 16 * bg_baud_rate / common_div;
35
        constant limit      : integer := clock_freq - baud_freq;
36
 
37
        signal COUNTER : integer range 0 to clock_freq - 1;
38
 
39
begin
40
 
41
        process(CLK_I)
42
        begin
43
                if (rising_edge(CLK_I)) then
44
                        CE_16 <= '0';            -- make CE_16 stay on for (at most) one cycle
45
 
46 9 jsauermann
                        if (RST_I = '1') then
47 2 jsauermann
                                COUNTER <= 0;
48
                        elsif (COUNTER >= limit) then
49
                                CE_16 <= '1';
50
                                COUNTER <= COUNTER - limit;
51
                        else
52
                                COUNTER <= COUNTER + baud_freq;
53
                        end if;
54
                end if;
55
        end process;
56
 
57
end Behavioral;

powered by: WebSVN 2.1.0

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