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 10

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
           baud : out  STD_LOGIC);
16
end baud_generator;
17
 
18
architecture Behavioral of baud_generator is
19
signal genTick : std_logic;
20
begin
21
        process (rst, clk)
22
        variable wait_clk_cycles : STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
23
        variable half_cycle : STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
24
        begin
25
                if rst = '1' then
26
                        wait_clk_cycles := (others => '0');
27
                        half_cycle := '0' & cycle_wait(cycle_wait'high downto 1);
28
                        genTick <= '0';
29
                elsif rising_edge(clk) then
30 8 leonardoar
                        -- Just decremented the cycle_wait by one because genTick would be updated on the next cycle
31
                        -- and we really want to bring genTick <= '1' when (wait_clk_cycles = cycle_wait)
32
                        if wait_clk_cycles = (cycle_wait - conv_std_logic_vector(1, (nBitsLarge-1))) then
33 6 leonardoar
                                genTick <= '1';
34
                                wait_clk_cycles := (others => '0');
35
                        else
36
                                wait_clk_cycles := wait_clk_cycles + conv_std_logic_vector(1, (nBitsLarge-1));
37
                                -- If we're at half of the cycle
38
                                if wait_clk_cycles = half_cycle then
39
                                        genTick <= '0';
40
                                end if;
41
                        end if;
42
                end if;
43
        end process;
44
 
45
        baud <= genTick;
46
 
47
end Behavioral;
48
 

powered by: WebSVN 2.1.0

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