Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
sim_edge_count.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief On percentage simulation 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 Entity to count edges
16 ENTITY sim_edge_count IS
17  PORT (
18  clk_in : IN std_logic; --! Clock
19  rst_in : IN std_logic; --! Asynchronous reset
20  signal_in : IN std_logic; --! Signal input
21  rise_out : OUT integer; --! Count of rising edges
22  fall_out : OUT integer --! Count of falling edges
23  );
24 END ENTITY sim_edge_count;
25 
26 --! Architecture sim of entity sim_edge_count
27 ARCHITECTURE sim OF sim_edge_count IS
28 
29  SIGNAL prev_signal : std_logic; --! Previous signal
30  SIGNAL prev_ok : std_logic; --! Previous signal ok flag
31  SIGNAL rise : integer; --! Count of rising edges
32  SIGNAL fall : integer; --! Count of falling edges
33 
34 BEGIN
35 
36  --! @brief Counting process
37  --!
38  --! This process counts the rising and falling edges
39  pr_count : PROCESS (clk_in, rst_in) IS
40  BEGIN
41 
42  IF (rst_in = '1') THEN
43  -- Reset counts
44  prev_signal <= '0';
45  prev_ok <= '0';
46  rise <= 0;
47  fall <= 0;
48  ELSIF (rising_edge(clk_in)) THEN
49  -- Detect edges
50  IF (prev_ok = '1') THEN
51  -- Count rising edges
52  IF (prev_signal = '0' AND signal_in = '1') THEN
53  rise <= rise + 1;
54  END IF;
55 
56  -- Count falling edges
57  IF (prev_signal = '1' AND signal_in = '0') THEN
58  fall <= fall + 1;
59  END IF;
60  END IF;
61 
62  -- Update previous signal
64  prev_ok <= '1';
65  END IF;
66 
67  END PROCESS pr_count;
68 
69  -- Output counts
70  rise_out <= rise;
71  fall_out <= fall;
72 
73 END ARCHITECTURE sim;
Entity to count edges.
in clk_instd_logic
Clock.
in rst_instd_logic
Asynchronous reset.
out rise_outinteger
Count of rising edges.
integer fall
Count of falling edges.
std_logic prev_signal
Previous signal.
in signal_instd_logic
Signal input.
out fall_outinteger
Count of falling edges.
std_logic prev_ok
Previous signal ok flag.
_library_ ieeeieee
Using IEEE library.
Definition: sdm_tb.vhd:7
integer rise
Count of rising edges.