summaryrefslogtreecommitdiff
path: root/FPGA/vhdl/clock_divider.vhd
diff options
context:
space:
mode:
Diffstat (limited to 'FPGA/vhdl/clock_divider.vhd')
-rw-r--r--FPGA/vhdl/clock_divider.vhd57
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
7library ieee;
8use 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
28entity 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);
36end clock_divider;
37
38architecture RTL of clock_divider is
39 constant max : natural := integer(board_frequency/user_frequency);
40begin
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;
57end RTL;