Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
clk_div_n.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief Counter module
4 -------------------------------------------------------------------------------
5 
6 --! Using IEEE library
7 LIBRARY ieee;
8 
9 --! Using IEEE standard logic components
10 USE ieee.std_logic_1164.ALL;
11 
12 --! Using IEE standard numeric components
13 USE ieee.numeric_std.ALL;
14 
15 --! @brief Clock divider entity
16 --!
17 --! This clock divider takes an input clock and divides it by an integer
18 --! value.
19 ENTITY clk_div_n IS
20  GENERIC (
21  clk_div : integer RANGE 2 TO integer'high := 4 --! Divider amount
22  );
23  PORT (
24  clk_in : IN std_logic; --! Clock
25  rst_in : IN std_logic; --! Asynchronous reset
26  div_clr_in : IN std_logic; --! Divider clear flag
27  div_adv_in : IN std_logic; --! Divider advance flag
28  div_end_out : OUT std_logic; --! Divider end flag
29  div_pls_out : OUT std_logic --! Divider pulse flag
30  );
31 END ENTITY clk_div_n;
32 
33 --! Architecture rtl of clk_div_n entity
34 ARCHITECTURE rtl OF clk_div_n IS
35 
36  --! Clock counter
37  SIGNAL count : integer RANGE 0 TO clk_div - 1;
38 
39 BEGIN
40 
41  --! @brief Clock divider count process
42  --!
43  --! This process handles counting and reset.
44  pr_count : PROCESS (clk_in, rst_in) IS
45  BEGIN
46 
47  IF (rst_in = '1') THEN
48  -- Asynchronous aeset
49  count <= 0;
50  div_end_out <= '0';
51  div_pls_out <= '0';
52  ELSIF (rising_edge(clk_in)) THEN
53  -- Default pulse to low
54  div_pls_out <= '0';
55 
56  -- Handle conditional advance
57  IF (div_clr_in = '1') THEN
58  -- Synchronous clear
59  count <= 0;
60  div_end_out <= '0';
61  ELSIF (div_adv_in = '1') THEN
62  IF (count = clk_div - 1) THEN
63  -- Handle roll-over
64  count <= 0;
65  div_end_out <= '1';
66  div_pls_out <= '1';
67  ELSE
68  -- Handle normal advance
69  count <= count + 1;
70  div_end_out <= '0';
71  END IF;
72  END IF;
73  END IF;
74 
75  END PROCESS pr_count;
76 
77 END ARCHITECTURE rtl;
78 
out div_pls_outstd_logic
Divider pulse flag.
Definition: clk_div_n.vhd:30
out div_end_outstd_logic
Divider end flag.
Definition: clk_div_n.vhd:28
in clk_instd_logic
Clock.
Definition: clk_div_n.vhd:24
in div_adv_instd_logic
Divider advance flag.
Definition: clk_div_n.vhd:27
integer range 0 TO clk_div- 1 count
Clock counter.
Definition: clk_div_n.vhd:37
clk_divinteger range 2 TO integer'high:= 4
Divider amount.
Definition: clk_div_n.vhd:22
in div_clr_instd_logic
Divider clear flag.
Definition: clk_div_n.vhd:26
Clock divider entity.
Definition: clk_div_n.vhd:19
in rst_instd_logic
Asynchronous reset.
Definition: clk_div_n.vhd:25