2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 use ieee.std_logic_unsigned.all;
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
10 -- f_OUT = f_IN / (2 * (1 + 'scale'))
12 -- The divided clock signal has a duty cycle of 50%.
14 -- Change of 'scale' doesn't affect current half-period.
16 -- The reset input signal is asynchronous. All others are synchronous to clk
17 -- rising egde. In default state (when stopped), output is low. When CE goes
18 -- high, 'clk_baud' goes high with next clock rising edge. When CE goes low,
19 -- eventual high half-period is finished and then generator stops with low
22 -- _ _ _ _ _ _ _ _ _ _ _ _
23 -- CLK _| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_
25 -- RESET ________________| |__________________________
26 -- _____________________________
27 -- CE ____| |______________
29 -- CLK_BAUD _____| |___| |________| |___| |___________
31 --------------------------------------------------------------------------------
35 SCALE_WIDTH : integer := 16
41 scale : in std_logic_vector (SCALE_WIDTH-1 downto 0);
42 clk_baud : out std_logic
46 --------------------------------------------------------------------------------
48 architecture behavioral of baud_gen is
50 signal counter : std_logic_vector (SCALE_WIDTH-1 downto 0) := (others => '0');
51 signal clk_baud_s : std_logic := '0';
53 --------------------------------------------------------------------------------
59 if (rising_edge(clk)) then
61 counter <= (others => '0');
65 if (clk_baud_s = '0' and ce = '0') then
66 counter <= (others => '0');
71 clk_baud_s <= not clk_baud_s;
74 counter <= counter - 1;
82 --------------------------------------------------------------------------------
84 clk_baud <= clk_baud_s;