]> rtime.felk.cvut.cz Git - fpga/uart.git/blob - baud_gen.vhd
First prototype of receiver shift register.
[fpga/uart.git] / baud_gen.vhd
1 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 --------------------------------------------------------------------------------
7 -- Baud generator is an adjustable clock frequency divider. Division factor
8 -- is determined by the value present on the input vector named 'scale' and is
9 -- equal to:
10 --              f_OUT = f_IN / (2 * (1 + 'scale'))
11 --
12 -- The divided clock signal has a duty cycle of 50%.
13 --
14 -- The reset input signal is asynchronous. When held active, the output is 0.
15 -- When released, the output starts a new period and goes high with the next 
16 -- rising edge of the input clock signal.
17 --
18 --             _   _   _   _   _   _   _   _   _   _   _   _
19 --  CLK      _| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_
20 --                        _________
21 --  RESET    ____________|         |__________________________
22 --             ___     __              ___     ___     ___ 
23 --  CLK_BAUD _|   |___|  |____________|   |___|   |___|   |___
24 --
25 --------------------------------------------------------------------------------
26
27 entity baud_gen is
28   generic (
29     SCALE_WIDTH : integer := 16
30   );
31   port (
32     clk      : in  std_logic;
33     reset    : in  std_logic;
34     scale    : in  std_logic_vector (SCALE_WIDTH-1 downto 0);
35     clk_baud : out std_logic
36   );
37 end baud_gen;
38
39 --------------------------------------------------------------------------------
40
41 architecture behavioral of baud_gen is
42
43   signal counter    : std_logic_vector (SCALE_WIDTH-1 downto 0);
44   signal clk_baud_s : std_logic;
45
46 --------------------------------------------------------------------------------
47
48 begin
49
50   process (clk, reset)
51   begin
52     if (reset = '1') then
53       counter <= (others => '0');
54       clk_baud_s <= '0';
55       
56     elsif (rising_edge(clk)) then
57       if (counter = 0) then
58         counter <= scale;
59         clk_baud_s <= not clk_baud_s;
60         
61       else
62         counter <= counter - 1;
63
64       end if;
65     end if;
66   end process;
67
68 --------------------------------------------------------------------------------
69   
70   clk_baud <= clk_baud_s;
71   
72 end behavioral;
73