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

Subversion Repositories uart_block

[/] [uart_block/] [trunk/] [hdl/] [iseProject/] [baud_generator.vhd] - Blame information for rev 14

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

Line No. Rev Author Line
1 6 leonardoar
--! Baud generator
2
--! http://www.fpga4fun.com/SerialInterface.html
3
library ieee;
4
use ieee.std_logic_1164.all;
5
use ieee.std_logic_unsigned.all;
6
use ieee.std_logic_arith.all;
7
 
8
--! Use CPU Definitions package
9
use work.pkgDefinitions.all;
10
 
11
entity baud_generator is
12
    Port ( rst : in STD_LOGIC;
13
                          clk : in  STD_LOGIC;
14
           cycle_wait : in  STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
15 11 leonardoar
                          baud_oversample : out std_logic;
16 6 leonardoar
           baud : out  STD_LOGIC);
17
end baud_generator;
18
 
19
architecture Behavioral of baud_generator is
20
signal genTick : std_logic;
21 11 leonardoar
signal genTickOverSample : std_logic;
22 6 leonardoar
begin
23 14 leonardoar
        process (rst, clk, cycle_wait)
24 6 leonardoar
        variable wait_clk_cycles : STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
25
        variable half_cycle : STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
26
        begin
27
                if rst = '1' then
28
                        wait_clk_cycles := (others => '0');
29
                        half_cycle := '0' & cycle_wait(cycle_wait'high downto 1);
30
                        genTick <= '0';
31
                elsif rising_edge(clk) then
32 8 leonardoar
                        -- Just decremented the cycle_wait by one because genTick would be updated on the next cycle
33
                        -- and we really want to bring genTick <= '1' when (wait_clk_cycles = cycle_wait)
34
                        if wait_clk_cycles = (cycle_wait - conv_std_logic_vector(1, (nBitsLarge-1))) then
35 6 leonardoar
                                genTick <= '1';
36
                                wait_clk_cycles := (others => '0');
37
                        else
38
                                wait_clk_cycles := wait_clk_cycles + conv_std_logic_vector(1, (nBitsLarge-1));
39
                                -- If we're at half of the cycle
40
                                if wait_clk_cycles = half_cycle then
41
                                        genTick <= '0';
42
                                end if;
43
                        end if;
44
                end if;
45
        end process;
46
 
47
        baud <= genTick;
48 11 leonardoar
        baud_oversample <= genTickOverSample;
49
 
50
        -- Process to generate the overclocked (8x) sample
51 14 leonardoar
        process (rst, clk, cycle_wait)
52 11 leonardoar
        variable wait_clk_cycles : STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
53
        variable half_cycle : STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
54
        variable cycle_wait_oversample : STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
55
        begin
56
                if rst = '1' then
57
                        wait_clk_cycles := (others => '0');
58
 
59 12 leonardoar
                        -- Divide cycle_wait by 4
60
                        cycle_wait_oversample := '0' & cycle_wait(cycle_wait'high downto 1);
61 11 leonardoar
                        cycle_wait_oversample := '0' & cycle_wait_oversample(cycle_wait_oversample'high downto 1);
62
 
63
                        -- Half of cycle_wait_oversample
64
                        half_cycle := '0' & cycle_wait_oversample(cycle_wait_oversample'high downto 1);
65
                        genTickOverSample <= '0';
66
                elsif rising_edge(clk) then
67
                        -- Just decremented the cycle_wait by one because genTick would be updated on the next cycle
68
                        -- and we really want to bring genTick <= '1' when (wait_clk_cycles = cycle_wait)
69
                        if wait_clk_cycles = (cycle_wait_oversample - conv_std_logic_vector(1, (nBitsLarge-1))) then
70
                                genTickOverSample <= '1';
71
                                wait_clk_cycles := (others => '0');
72
                        else
73
                                wait_clk_cycles := wait_clk_cycles + conv_std_logic_vector(1, (nBitsLarge-1));
74
                                -- If we're at half of the cycle
75
                                if wait_clk_cycles = half_cycle then
76
                                        genTickOverSample <= '0';
77
                                end if;
78
                        end if;
79
                end if;
80
        end process;
81 6 leonardoar
 
82
end Behavioral;
83
 

powered by: WebSVN 2.1.0

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