-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdivisor_freq.vhd
46 lines (38 loc) · 1 KB
/
divisor_freq.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity divisor_freq is
generic (N : natural := 50000000;
BUS_WIDTH : natural := 26);
port (signal reset_n : in std_logic;
signal clk : in std_logic;
signal clk_o : out std_logic);
end divisor_freq;
architecture structural of divisor_freq is
signal clk_o_reg : std_logic;
signal clk_o_next : std_logic;
signal q_reg : unsigned(BUS_WIDTH-1 downto 0);
signal q_next : unsigned(BUS_WIDTH-1 downto 0);
begin
seq: process(reset_n,clk)
begin
if (reset_n = '0') then
clk_o_reg <= '0';
q_reg <= (others => '0');
elsif rising_edge(clk) then
clk_o_reg <= clk_o_next;
q_reg <= q_next;
end if;
end process seq;
comb: process(q_reg)
begin
if (q_reg = (N-1)) then
clk_o_next <= '1';
q_next <= (others => '0');
else
clk_o_next <= '0';
q_next <= q_reg + 1;
end if;
end process comb;
clk_o <= clk_o_reg;
end structural;