Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
edge_detect_tb.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief Edge detect test bench
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 Test bench for edge_detect entity
13 ENTITY edge_detect_tb IS
14 END ENTITY edge_detect_tb;
15 
16 --! Architecture tb of edge_detect_tb entity
17 ARCHITECTURE tb OF edge_detect_tb IS
18 
19  --! Stimulus record type
20  TYPE t_stimulus IS RECORD
21  name : string(1 TO 20); --! Stimulus name
22  rst : std_logic_vector(0 TO 7); --! rst input to uut
23  sig : std_logic_vector(0 TO 7); --! sig input to uut
24  rise : std_logic_vector(0 TO 7); --! rise expected from uut
25  fall : std_logic_vector(0 TO 7); --! fall expected from uut
26  END RECORD t_stimulus;
27 
28  --! Stimulus array type
29  TYPE t_stimulus_array IS ARRAY(natural RANGE <>) OF t_stimulus;
30 
31  --! Test bench clock period
32  CONSTANT c_clk_period : time := 10 ns;
33 
34  --! Test stimulus
36  (
37  (
38  name => "Hold in reset ",
39  rst => "11111111",
40  sig => "00000000",
41  rise => "00000000",
42  fall => "00000000"
43  ),
44  (
45  name => "Wake low then edges ",
46  rst => "10000000",
47  sig => "00011100",
48  rise => "00010000",
49  fall => "00000010"
50  ),
51  (
52  name => "Wake high then edges",
53  rst => "10000000",
54  sig => "11100011",
55  rise => "00000010",
56  fall => "00010000"
57  )
58  );
59 
60  -- Signals to unit under test
61  SIGNAL clk : std_logic; --! Signal 'clk' to uut
62  SIGNAL rst : std_logic; --! Signal 'rst' to uut
63  SIGNAL sig : std_logic; --! Signal 'sig' to uut
64  SIGNAL rise : std_logic; --! Signal 'rise' from uut
65  SIGNAL fall : std_logic; --! Signal 'fall' from uut
66 
67 BEGIN
68 
69  --! Instantiate edge_detect as unit under test
70  i_uut : ENTITY work.edge_detect(rtl)
71  PORT MAP (
72  clk_in => clk,
73  rst_in => rst,
74  sig_in => sig,
75  rise_out => rise,
76  fall_out => fall
77  );
78 
79  --! @brief Clock generation process
80  pr_clock : PROCESS IS
81  BEGIN
82 
83  -- Low for 1/2 clock period
84  clk <= '0';
85  WAIT FOR c_clk_period / 2;
86 
87  -- High for 1/2 clock period
88  clk <= '1';
89  WAIT FOR c_clk_period / 2;
90 
91  END PROCESS pr_clock;
92 
93  --! @brief Stimulus process to drive PWM unit under test
94  pr_stimulus : PROCESS IS
95  BEGIN
96 
97  -- Initialize entity inputs
98  rst <= '1';
99  sig <= '0';
100  WAIT FOR c_clk_period;
101 
102  -- Loop over stimulus
103  FOR s IN c_stimulus'range LOOP
104  -- Log start of stimulus
105  REPORT "Starting: " & c_stimulus(s).name SEVERITY note;
106 
107  -- Loop for test stimulus
108  FOR t IN 0 TO 7 LOOP
109  -- Set inputs then wait for clock to rise
110  rst <= c_stimulus(s).rst(t);
111  sig <= c_stimulus(s).sig(t);
112  WAIT UNTIL clk = '1';
113 
114  -- Wait for clk to fall
115  WAIT UNTIL clk = '0';
116 
117  -- Assert rise
118  ASSERT rise = c_stimulus(s).rise(t)
119  REPORT "At time " & integer'image(t)
120  & " expected rise = " & std_logic'image(c_stimulus(s).rise(t))
121  & " but got " & std_logic'image(rise)
122  SEVERITY error;
123 
124  -- Assert fall
125  ASSERT fall = c_stimulus(s).fall(t)
126  REPORT "At time " & integer'image(t)
127  & " expected fall = " & std_logic'image(c_stimulus(s).fall(t))
128  & " but got " & std_logic'image(fall)
129  SEVERITY error;
130  END LOOP;
131  END LOOP;
132 
133  -- Log end of test
134  REPORT "Finished" SEVERITY note;
135 
136  -- Finish the simulation
137  std.env.finish;
138 
139  END PROCESS pr_stimulus;
140 
141 END ARCHITECTURE tb;
out rise_outstd_logic
Rising edge output.
Definition: edge_detect.vhd:21
_library_ ieeeieee
Using IEEE library.
Test bench for edge_detect entity.
in rst_instd_logic
Asynchronous reset.
Definition: edge_detect.vhd:19
Edge detect entity.
Definition: edge_detect.vhd:16
std_logic clk
Signal &#39;clk&#39; to uut.
in sig_instd_logic
Input signal.
Definition: edge_detect.vhd:20
string( 1 TO 20) name
Stimulus name.
array(natural range <> ) of t_stimulus t_stimulus_array
Stimulus array type.
in clk_instd_logic
Clock.
Definition: edge_detect.vhd:18
time := 10 ns c_clk_period
Test bench clock period.
t_stimulus_array :=((name => "Hold in reset ",rst => "11111111",sig => "00000000",rise => "00000000",fall => "00000000"),(name => "Wake low then edges ",rst => "10000000",sig => "00011100",rise => "00010000",fall => "00000010"),(name => "Wake high then edges",rst => "10000000",sig => "11100011",rise => "00000010",fall => "00010000")) c_stimulus
Test stimulus.
t_stimulus
Stimulus record type.
out fall_outstd_logic
Falling edge output.
Definition: edge_detect.vhd:23
std_logic_vector( 0 TO 7) rise
rise expected from uut
std_logic_vector( 0 TO 7) sig
sig input to uut
std_logic_vector( 0 TO 7) rst
rst input to uut
std_logic_vector( 0 TO 7) fall
fall expected from uut