Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
step_generator_tb.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief Step Generator 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 --! Using IEE standard numeric components
13 USE ieee.numeric_std.ALL;
14 
15 --! @brief step_generator test bench
17 END ENTITY step_generator_tb;
18 
19 --! Architecture tb of step_generator_tb entity
20 ARCHITECTURE tb OF step_generator_tb IS
21 
22  --! Stimulus record type
23  TYPE t_stimulus IS RECORD
24  name : string(1 TO 20); --! Stimulus name
25  rst : std_logic; --! rst input to uut
26  count : std_logic_vector(2 DOWNTO 0); --! count input to uut
27  delay : std_logic_vector(2 DOWNTO 0); --! delay input to uut
28  rise : integer; --! Expected rise count
29  fall : integer; --! Expected fall count
30  END RECORD t_stimulus;
31 
32  --! Stimulus array type
33  TYPE t_stimulus_array IS ARRAY(natural RANGE <>) OF t_stimulus;
34 
35  --! Test bench clock period
36  CONSTANT c_clk_period : time := 10 ns;
37 
38  --! Test stimulus
40  (
41  (
42  name => "Hold in reset ",
43  rst => '1',
44  count => B"000",
45  delay => B"000",
46  rise => 0,
47  fall => 0
48  ),
49  (
50  name => "No steps ",
51  rst => '0',
52  count => B"000",
53  delay => B"000",
54  rise => 0,
55  fall => 0
56  ),
57  (
58  name => "One step ",
59  rst => '0',
60  count => B"001",
61  delay => B"111",
62  rise => 1,
63  fall => 1
64  ),
65  (
66  name => "Two steps ",
67  rst => '0',
68  count => B"010",
69  delay => B"100",
70  rise => 2,
71  fall => 2
72  ),
73  (
74  name => "Three steps ",
75  rst => '0',
76  count => B"011",
77  delay => B"011",
78  rise => 3,
79  fall => 3
80  ),
81  (
82  name => "Four steps ",
83  rst => '0',
84  count => B"100",
85  delay => B"010",
86  rise => 4,
87  fall => 4
88  ),
89  (
90  name => "Five steps ",
91  rst => '0',
92  count => B"101",
93  delay => B"001",
94  rise => 5,
95  fall => 5
96  ),
97  (
98  name => "Six steps ",
99  rst => '0',
100  count => B"110",
101  delay => B"001",
102  rise => 6,
103  fall => 6
104  ),
105  (
106  name => "Seven steps ",
107  rst => '0',
108  count => B"111",
109  delay => B"000",
110  rise => 7,
111  fall => 7
112  ),
113  (
114  name => "Overrun ",
115  rst => '0',
116  count => B"111",
117  delay => B"111",
118  rise => 3,
119  fall => 2
120  )
121  );
122 
123  -- Signals to step_generator uut
124  SIGNAL clk : std_logic; --! Clock
125  SIGNAL rst : std_logic; --! Reset
126  SIGNAL enable : std_logic; --! Enable input to uut
127  SIGNAL advance : std_logic; --! Advance input to uut
128  SIGNAL count : std_logic_vector(2 DOWNTO 0); --! Count input to uut
129  SIGNAL delay : std_logic_vector(2 DOWNTO 0); --! Delay input to uut
130  SIGNAL step : std_logic; --! Step output from uut
131 
132  -- Signals for edge counter
133  SIGNAL edge_rst : std_logic; --! Reset edge counter
134  SIGNAL edge_rise : integer; --! Count of rising edges
135  SIGNAL edge_fall : integer; --! Count of falling edges
136 
137 BEGIN
138 
139  --! Instantiate step_generator as unit under test
140  i_uut : ENTITY work.step_generator(rtl)
141  GENERIC MAP (
142  count_wid => 3,
143  delay_wid => 3
144  )
145  PORT MAP (
146  clk_in => clk,
147  rst_in => rst,
148  enable_in => enable,
149  advance_in => advance,
150  count_in => count,
151  delay_in => delay,
152  step_out => step
153  );
154 
155  --! Instantiate clk_div_n to generate advance pulses every 4th clock
156  i_adv_divisor : ENTITY work.clk_div_n(rtl)
157  GENERIC MAP (
158  clk_div => 4
159  )
160  PORT MAP (
161  clk_in => clk,
162  rst_in => rst,
163  div_clr_in => '0',
164  div_adv_in => '1',
165  div_end_out => OPEN,
167  );
168 
169  --! Instantiate edge counter to analyze edges
170  i_edge_count : ENTITY work.sim_edge_count(sim)
171  PORT MAP (
172  clk_in => clk,
173  rst_in => edge_rst,
174  signal_in => step,
175  rise_out => edge_rise,
177  );
178 
179  --! @brief Clock generation process
180  pr_clock : PROCESS IS
181  BEGIN
182 
183  -- Low for 1/2 clock period
184  clk <= '0';
185  WAIT FOR c_clk_period / 2;
186 
187  -- High for 1/2 clock period
188  clk <= '1';
189  WAIT FOR c_clk_period / 2;
190 
191  END PROCESS pr_clock;
192 
193  --! @brief Stimulus process to drive PWM unit under test
194  pr_stimulus : PROCESS IS
195  BEGIN
196 
197  -- Initialize entity inputs
198  rst <= '1';
199  edge_rst <= '1';
200  enable <= '0';
201  WAIT FOR c_clk_period;
202 
203  -- Assert step is idle
204  ASSERT step = '0'
205  REPORT "Expected step = 0 but got " & std_logic'image(step)
206  SEVERITY error;
207 
208  -- Loop over stimulus
209  FOR s IN c_stimulus'range LOOP
210  -- Log start of stimulus
211  REPORT "Starting: " & c_stimulus(s).name SEVERITY note;
212 
213  -- Enable edge counter
214  edge_rst <= '0';
215  WAIT UNTIL clk = '1';
216  WAIT UNTIL clk = '0';
217 
218  -- Set inputs then wait for clock to rise
219  rst <= c_stimulus(s).rst;
220  count <= c_stimulus(s).count;
221  delay <= c_stimulus(s).delay;
222  enable <= '1';
223  WAIT UNTIL clk = '1';
224  WAIT UNTIL clk = '0';
225 
226  -- Wait for the clock generation to finish (other than the overrun case)
227  WAIT FOR c_clk_period * 4 * 7 * 5;
228 
229  -- Assert edges
230  ASSERT edge_rise = c_stimulus(s).rise
231  REPORT "Expected " & integer'image(c_stimulus(s).rise)
232  & " rising edges, but got " & integer'image(edge_rise)
233  SEVERITY error;
234  ASSERT edge_fall = c_stimulus(s).fall
235  REPORT "Expected " & integer'image(c_stimulus(s).fall)
236  & " falling edges, but got " & integer'image(edge_fall)
237  SEVERITY error;
238 
239  -- Clear enable
240  edge_rst <= '1';
241  enable <= '0';
242  WAIT FOR c_clk_period;
243 
244  -- Assert step is idle
245  ASSERT step = '0'
246  REPORT "Expected step = 0 but got " & std_logic'image(step)
247  SEVERITY error;
248  END LOOP;
249 
250  -- Log end of test
251  REPORT "Finished" SEVERITY note;
252 
253  -- Finish the simulation
254  std.env.finish;
255 
256  END PROCESS pr_stimulus;
257 
258 END ARCHITECTURE tb;
Entity to count edges.
std_logic rst
rst input to uut
out div_pls_outstd_logic
Divider pulse flag.
Definition: clk_div_n.vhd:30
std_logic step
Step output from uut.
integer edge_fall
Count of falling edges.
out step_outstd_logic
Step output.
out div_end_outstd_logic
Divider end flag.
Definition: clk_div_n.vhd:28
t_stimulus_array :=((name => "Hold in reset ",rst => '1',count => B"000",delay => B"000",rise => 0,fall => 0),(name => "No steps ",rst => '0',count => B"000",delay => B"000",rise => 0,fall => 0),(name => "One step ",rst => '0',count => B"001",delay => B"111",rise => 1,fall => 1),(name => "Two steps ",rst => '0',count => B"010",delay => B"100",rise => 2,fall => 2),(name => "Three steps ",rst => '0',count => B"011",delay => B"011",rise => 3,fall => 3),(name => "Four steps ",rst => '0',count => B"100",delay => B"010",rise => 4,fall => 4),(name => "Five steps ",rst => '0',count => B"101",delay => B"001",rise => 5,fall => 5),(name => "Six steps ",rst => '0',count => B"110",delay => B"001",rise => 6,fall => 6),(name => "Seven steps ",rst => '0',count => B"111",delay => B"000",rise => 7,fall => 7),(name => "Overrun ",rst => '0',count => B"111",delay => B"111",rise => 3,fall => 2)) c_stimulus
Test stimulus.
std_logic enable
Enable input to uut.
in clk_instd_logic
Clock.
Definition: clk_div_n.vhd:24
in clk_instd_logic
Clock.
integer rise
Expected rise count.
count_widinteger range 1 TO integer'high:= 4
Width of count.
integer fall
Expected fall count.
_library_ ieeeieee
Using IEEE library.
in clk_instd_logic
Clock.
in rst_instd_logic
Asynchronous reset.
std_logic_vector( 2 DOWNTO 0) delay
delay input to uut
out rise_outinteger
Count of rising edges.
in rst_instd_logic
Asynchronous reset.
in div_adv_instd_logic
Divider advance flag.
Definition: clk_div_n.vhd:27
clk_divinteger range 2 TO integer'high:= 4
Divider amount.
Definition: clk_div_n.vhd:22
in count_instd_logic_vector( count_wid- 1 DOWNTO 0)
Count of steps.
std_logic edge_rst
Reset edge counter.
in delay_instd_logic_vector( delay_wid- 1 DOWNTO 0)
Delay between steps.
step_generator test bench
in div_clr_instd_logic
Divider clear flag.
Definition: clk_div_n.vhd:26
string( 1 TO 20) name
Stimulus name.
in advance_instd_logic
Advance flag.
in enable_instd_logic
Generator enable flag.
std_logic_vector( 2 DOWNTO 0) count
count input to uut
in signal_instd_logic
Signal input.
t_stimulus
Stimulus record type.
out fall_outinteger
Count of falling edges.
Clock divider entity.
Definition: clk_div_n.vhd:19
time := 10 ns c_clk_period
Test bench clock period.
std_logic advance
Advance input to uut.
integer edge_rise
Count of rising edges.
delay_widinteger range 1 TO integer'high:= 6
Width of delay.
in rst_instd_logic
Asynchronous reset.
Definition: clk_div_n.vhd:25
Step Generator entity.
array(natural range <> ) of t_stimulus t_stimulus_array
Stimulus array type.