Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
level_filter.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief Level-filter 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 --! @brief Level-filter entity
13 --!
14 --! This entity acts as a level-filter which changes when a signal is
15 --! stable at a level for the specified count.
16 ENTITY level_filter IS
17  GENERIC (
18  count : natural RANGE 1 TO natural'high := 2 --! Filter length
19  );
20  PORT (
21  clk_in : IN std_logic; --! Clock
22  rst_in : IN std_logic; --! Asynchronous reset
23  sig_in : IN std_logic; --! Input signal
24  sig_out : OUT std_logic --! Output signal
25  );
26 END ENTITY level_filter;
27 
28 --! Architecture rtl of level_filter entity
29 ARCHITECTURE rtl OF level_filter IS
30 
31  --! Constant for all-high
32  CONSTANT c_high : std_logic_vector(count - 2 DOWNTO 0) := (OTHERS => '1');
33 
34  --! Constant for all-low
35  CONSTANT c_low : std_logic_vector(count - 2 DOWNTO 0) := (OTHERS => '0');
36 
37  --! Input history shift register
38  SIGNAL history : std_logic_vector(count - 2 DOWNTO 0);
39 
40  --! Current state
41  SIGNAL state : std_logic;
42 
43 BEGIN
44 
45  --! @brief Shift process
46  pr_shift : PROCESS (clk_in, rst_in) IS
47  BEGIN
48 
49  IF (rst_in = '1') THEN
50  -- Reset
51  history <= (OTHERS => '0');
52  state <= '0';
53  ELSIF (rising_edge(clk_in)) THEN
54  -- Detect level
55  IF (sig_in = '1' AND history = c_high) THEN
56  state <= '1';
57  ELSIF (sig_in = '0' AND history = c_low) THEN
58  state <= '0';
59  END IF;
60 
61  -- Update history
62  IF (count = 2) THEN
63  history(0) <= sig_in;
64  ELSE
65  history <= sig_in & history(history'high DOWNTO 1);
66  END IF;
67  END IF;
68 
69  END PROCESS pr_shift;
70 
71  -- Drive sig_out from current state
72  sig_out <= state;
73 
74 END ARCHITECTURE rtl;
std_logic_vector( count- 2 DOWNTO 0) history
Input history shift register.
Level-filter entity.
out sig_outstd_logic
Output signal.
std_logic state
Current state.
in sig_instd_logic
Input signal.
in clk_instd_logic
Clock.
std_logic_vector( count- 2 DOWNTO 0) :=( others => '1') c_high
Constant for all-high.
in rst_instd_logic
Asynchronous reset.
std_logic_vector( count- 2 DOWNTO 0) :=( others => '0') c_low
Constant for all-low.
_library_ ieeeieee
Using IEEE library.
Definition: edge_detect.vhd:7
countnatural range 1 TO natural'high:= 2
Filter length.