diff options
author | Pacien TRAN-GIRARD | 2014-04-11 19:29:53 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-04-11 19:29:53 +0200 |
commit | 12bbdb42cdcf5e6e39832d75fbbd31e3781d550a (patch) | |
tree | 21d9d8fdb7a949c8050de38c237386d0066ca146 /FPGA/vhdl/clock_divider.vhd | |
download | fpga-home-automation-12bbdb42cdcf5e6e39832d75fbbd31e3781d550a.tar.gz |
Import fichiers projet Quartus
Diffstat (limited to 'FPGA/vhdl/clock_divider.vhd')
-rw-r--r-- | FPGA/vhdl/clock_divider.vhd | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/FPGA/vhdl/clock_divider.vhd b/FPGA/vhdl/clock_divider.vhd new file mode 100644 index 0000000..3a061bb --- /dev/null +++ b/FPGA/vhdl/clock_divider.vhd | |||
@@ -0,0 +1,57 @@ | |||
1 | ------------------------------------------------------ | ||
2 | -- Clock Divider | ||
3 | ------------------------------------------------------ | ||
4 | -- Creation : A. Exertier, 2005 | ||
5 | ------------------------------------------------------ | ||
6 | |||
7 | library ieee; | ||
8 | use ieee.std_logic_1164.all; | ||
9 | |||
10 | ------------------------------------------------------ | ||
11 | -- PARAMETRES GENERIQUES | ||
12 | ------------------------------------------------------ | ||
13 | -- board_frequency : frequency of the FPGA | ||
14 | -- user_frequency : desired frequency | ||
15 | ------------------------------------------------------ | ||
16 | -- INPUTS | ||
17 | ------------------------------------------------------ | ||
18 | -- clk : main clock | ||
19 | -- resetn : asynchronous active low reset | ||
20 | ------------------------------------------------------ | ||
21 | -- OUTPUT | ||
22 | ------------------------------------------------------ | ||
23 | -- en_user : signal at user_frequency | ||
24 | -- set to 1 only 1 main clock cycle | ||
25 | ------------------------------------------------------ | ||
26 | |||
27 | |||
28 | entity clock_divider is | ||
29 | generic( | ||
30 | board_frequency : real :=50_000_000.0; -- 50 MHz | ||
31 | user_frequency : real :=4.0); -- 4 Hz | ||
32 | Port ( | ||
33 | clk : in std_logic; | ||
34 | resetn : in std_logic; -- active low | ||
35 | en_user : out std_logic); | ||
36 | end clock_divider; | ||
37 | |||
38 | architecture RTL of clock_divider is | ||
39 | constant max : natural := integer(board_frequency/user_frequency); | ||
40 | begin | ||
41 | process(clk,resetn) | ||
42 | variable counter : natural range 0 to max-1; | ||
43 | begin | ||
44 | if resetn='0' then | ||
45 | counter := 0; | ||
46 | en_user <= '0'; | ||
47 | elsif rising_edge(clk) then | ||
48 | if counter = max-1 then | ||
49 | counter := 0; | ||
50 | en_user <= '1'; | ||
51 | else | ||
52 | counter := counter+1; | ||
53 | en_user <= '0'; | ||
54 | end if; | ||
55 | end if; | ||
56 | end process; | ||
57 | end RTL; | ||