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