Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
sim_on_percent.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 measure on-percentage of signal
16 ENTITY sim_on_percent 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  percent_out : OUT integer --! On percentage output
22  );
23 END ENTITY sim_on_percent;
24 
25 --! Architecture sim of entity sim_on_percent
26 ARCHITECTURE sim OF sim_on_percent IS
27 
28  SIGNAL count : integer; --! Clock count
29  SIGNAL count_on : integer; --! On count
30 
31 BEGIN
32 
33  --! @brief Counting process
34  --!
35  --! This process counts the clocks and signal on-time to get the percentage
36  pr_count : PROCESS (clk_in, rst_in) IS
37  BEGIN
38 
39  IF (rst_in = '1') THEN
40  -- Reset counts
41  count <= 0;
42  count_on <= 0;
43  percent_out <= 0;
44  ELSIF (rising_edge(clk_in)) THEN
45  -- Update counts
46  count <= count + 1;
47  IF (signal_in = '1') THEN
48  count_on <= count_on + 1;
49  END IF;
50 
51  -- Calculate percentage
52  IF (count > 0) THEN
53  percent_out <= (count_on * 100) / count;
54  END IF;
55  END IF;
56 
57  END PROCESS pr_count;
58 
59 END ARCHITECTURE sim;
in signal_instd_logic
Signal input.
Entity to measure on-percentage of signal.
in clk_instd_logic
Clock.
integer count
Clock count.
integer count_on
On count.
_library_ ieeeieee
Using IEEE library.
in rst_instd_logic
Asynchronous reset.
out percent_outinteger
On percentage output.