-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdivisor_freq.vhd.bak
62 lines (53 loc) · 1.79 KB
/
divisor_freq.vhd.bak
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
----------------------------------------------------------------------------------------
-- Archivo: divisor_freq.vhd
----------------------------------------------------------------------------------------
-- Autor: Mg. Ing. Mario Raffo
-- Email: [email protected]
-- Entidad: Pontificia Universidad Católica del Perú (PUCP)
-- Facultad: Estudios Generales Ciencias (EE.GG.CC)
-- Curso: 1IEE04 - Diseño Digital
----------------------------------------------------------------------------------------
-- Historia de Versión:
-- Versión 1.0 (01/10/2017) - Mario Raffo
----------------------------------------------------------------------------------------
-- Descripción:
-- Circuito basado en un contador mod N
----------------------------------------------------------------------------------------
Library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity divisor_freq is
generic (n : natural := 10;
width : natural := 4);
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(width-1 downto 0);
signal q_next : unsigned(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;