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 32

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 15 leonardoar
use ieee.std_logic_arith.all;
7
use ieee.numeric_std.all;
8 6 leonardoar
 
9
--! Use CPU Definitions package
10
use work.pkgDefinitions.all;
11
 
12
entity baud_generator is
13
    Port ( rst : in STD_LOGIC;
14
                          clk : in  STD_LOGIC;
15
           cycle_wait : in  STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
16 11 leonardoar
                          baud_oversample : out std_logic;
17 6 leonardoar
           baud : out  STD_LOGIC);
18
end baud_generator;
19
 
20
architecture Behavioral of baud_generator is
21
signal genTick : std_logic;
22 11 leonardoar
signal genTickOverSample : std_logic;
23 6 leonardoar
begin
24 14 leonardoar
        process (rst, clk, cycle_wait)
25 6 leonardoar
        variable wait_clk_cycles : STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
26
        variable half_cycle : STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
27
        begin
28
                if rst = '1' then
29
                        wait_clk_cycles := (others => '0');
30
                        half_cycle := '0' & cycle_wait(cycle_wait'high downto 1);
31
                        genTick <= '0';
32
                elsif rising_edge(clk) then
33 8 leonardoar
                        -- Just decremented the cycle_wait by one because genTick would be updated on the next cycle
34
                        -- and we really want to bring genTick <= '1' when (wait_clk_cycles = cycle_wait)
35 15 leonardoar
                        if wait_clk_cycles = (cycle_wait - conv_std_logic_vector(1, nBitsLarge)) then
36 6 leonardoar
                                genTick <= '1';
37
                                wait_clk_cycles := (others => '0');
38
                        else
39 15 leonardoar
                                wait_clk_cycles := wait_clk_cycles + conv_std_logic_vector(1, nBitsLarge);
40 6 leonardoar
                                -- If we're at half of the cycle
41
                                if wait_clk_cycles = half_cycle then
42 16 leonardoar
                                        genTick <= '0';
43 6 leonardoar
                                end if;
44 15 leonardoar
                        end if;
45
 
46
                        -- Avoid creation of transparent latch (By default the VHDL will create an register for vectors that are assigned only in one
47
                        -- ocasion of a (if, case) instruction
48
                        half_cycle := '0' & cycle_wait(cycle_wait'high downto 1);
49 6 leonardoar
                end if;
50
        end process;
51
 
52
        baud <= genTick;
53 11 leonardoar
        baud_oversample <= genTickOverSample;
54
 
55
        -- Process to generate the overclocked (8x) sample
56 14 leonardoar
        process (rst, clk, cycle_wait)
57 11 leonardoar
        variable wait_clk_cycles : STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
58
        variable half_cycle : STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
59 15 leonardoar
        variable cycle_wait_oversample : STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
60 11 leonardoar
        begin
61
                if rst = '1' then
62
                        wait_clk_cycles := (others => '0');
63
 
64 32 leonardoar
                        -- Divide cycle_wait by 8
65 15 leonardoar
                        --cycle_wait_oversample := '0' & cycle_wait(cycle_wait'high downto 1);                  
66
                        --cycle_wait_oversample := '0' & cycle_wait_oversample(cycle_wait_oversample'high downto 1);
67 32 leonardoar
                        --cycle_wait_oversample := '0' & cycle_wait_oversample(cycle_wait_oversample'high downto 1);
68
                        cycle_wait_oversample := "000" & cycle_wait(cycle_wait'high downto 3);  -- Shift right by 3                     
69 11 leonardoar
 
70 15 leonardoar
 
71 11 leonardoar
                        -- Half of cycle_wait_oversample
72 15 leonardoar
                        half_cycle := '0' & cycle_wait_oversample(cycle_wait_oversample'high downto 1); -- Shift right by 1
73 11 leonardoar
                        genTickOverSample <= '0';
74
                elsif rising_edge(clk) then
75
                        -- Just decremented the cycle_wait by one because genTick would be updated on the next cycle
76
                        -- and we really want to bring genTick <= '1' when (wait_clk_cycles = cycle_wait)
77 15 leonardoar
                        if wait_clk_cycles = (cycle_wait_oversample - conv_std_logic_vector(1, nBitsLarge)) then
78 11 leonardoar
                                genTickOverSample <= '1';
79
                                wait_clk_cycles := (others => '0');
80
                        else
81 15 leonardoar
                                wait_clk_cycles := wait_clk_cycles + conv_std_logic_vector(1, nBitsLarge);
82 11 leonardoar
                                -- If we're at half of the cycle
83
                                if wait_clk_cycles = half_cycle then
84
                                        genTickOverSample <= '0';
85
                                end if;
86 15 leonardoar
                        end if;
87
 
88
                        -- Avoid creation of transparent latch (By default the VHDL will create an register for vectors that are assigned only in one
89
                        -- ocasion of a (if, case) instruction
90 32 leonardoar
                        cycle_wait_oversample := "000" & cycle_wait(cycle_wait'high downto 3);
91 15 leonardoar
                        half_cycle := '0' & cycle_wait_oversample(cycle_wait_oversample'high downto 1);
92 11 leonardoar
                end if;
93
        end process;
94 6 leonardoar
 
95
end Behavioral;
96
 

powered by: WebSVN 2.1.0

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