]> rtime.felk.cvut.cz Git - fpga/uart.git/blob - baud_gen.vhd
First working prototype of HW UART - TX part.
[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 entity baud_gen is
7   port (
8     clk      : in  std_logic;
9     reset    : in  std_logic;
10     scale    : in  std_logic_vector (15 downto 0);
11     clk_baud : out std_logic
12   );
13 end baud_gen;
14
15 --------------------------------------------------------------------------------
16
17 architecture behavioral of baud_gen is
18
19   signal counter    : std_logic_vector (15 downto 0);
20   signal clk_baud_s : std_logic;
21
22 --------------------------------------------------------------------------------
23
24 begin
25
26   process (clk, reset)
27   begin
28     if (reset = '1') then
29       counter <= (others => '0');
30       clk_baud_s <= '0';
31       
32     elsif (rising_edge(clk)) then
33       if (counter = 0) then
34         counter <= scale;
35         clk_baud_s <= not clk_baud_s;
36         
37       else
38         counter <= counter - 1;
39
40       end if;
41     end if;
42   end process;
43
44 --------------------------------------------------------------------------------
45   
46   clk_baud <= clk_baud_s;
47   
48 end behavioral;
49