Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
edge_detect.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief Edge detect 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 Edge detect entity
13 --!
14 --! This edge detect entity takes a signal input and detects rising or falling
15 --! edges.
16 ENTITY edge_detect IS
17  PORT (
18  clk_in : IN std_logic; --! Clock
19  rst_in : IN std_logic; --! Asynchronous reset
20  sig_in : IN std_logic; --! Input signal
21  rise_out : OUT std_logic; --! Rising edge output
22  fall_out : OUT std_logic --! Falling edge output
23  );
24 END ENTITY edge_detect;
25 
26 --! Architecture rtl of edge_detect entity
27 ARCHITECTURE rtl OF edge_detect IS
28 
29  --! Previous input valid signal
30  SIGNAL prev_ok : std_logic;
31 
32  --! Previous input signal
33  SIGNAL prev : std_logic;
34 
35 BEGIN
36 
37  --! @brief Edge detection process
38  pr_detect : PROCESS (clk_in, rst_in) IS
39  BEGIN
40 
41  IF (rst_in = '1') THEN
42  -- Aynchronous reset
43  prev_ok <= '0';
44  prev <= '0';
45  rise_out <= '0';
46  fall_out <= '0';
47  ELSIF (rising_edge(clk_in)) THEN
48  IF (prev_ok = '1') THEN
49  -- Detect rising edge
50  IF (sig_in = '1' AND prev = '0') THEN
51  rise_out <= '1';
52  ELSE
53  rise_out <= '0';
54  END IF;
55 
56  -- Detect falling edge
57  IF (sig_in = '0' AND prev = '1') THEN
58  fall_out <= '1';
59  ELSE
60  fall_out <= '0';
61  END IF;
62  END IF;
63 
64  -- Save previous sig_in
65  prev <= sig_in;
66  prev_ok <= '1';
67  END IF;
68 
69  END PROCESS pr_detect;
70 
71 END ARCHITECTURE rtl;
out rise_outstd_logic
Rising edge output.
Definition: edge_detect.vhd:21
in rst_instd_logic
Asynchronous reset.
Definition: edge_detect.vhd:19
Edge detect entity.
Definition: edge_detect.vhd:16
std_logic prev_ok
Previous input valid signal.
Definition: edge_detect.vhd:30
in sig_instd_logic
Input signal.
Definition: edge_detect.vhd:20
in clk_instd_logic
Clock.
Definition: edge_detect.vhd:18
std_logic prev
Previous input signal.
Definition: edge_detect.vhd:33
_library_ ieeeieee
Using IEEE library.
Definition: delay_line.vhd:7
out fall_outstd_logic
Falling edge output.
Definition: edge_detect.vhd:23