Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
sdm_device_tb.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief SDM device 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 SDM device test bench
16 ENTITY sdm_device_tb IS
17 END ENTITY sdm_device_tb;
18 
19 --! Architecture tb of sdm_device_tb entity
20 ARCHITECTURE tb OF sdm_device_tb IS
21 
22  --! Test bench clock period
23  CONSTANT c_clk_period : time := 10 ns;
24 
25  --! Type for percentage array
26  TYPE t_percent_array IS ARRAY(0 TO 3) OF integer;
27 
28  --! Stimulus record type
29  TYPE t_stimulus IS RECORD
30  name : string(1 TO 30); --! Stimulus name
31  rst : std_logic; --! Reset input to sdm_device
32  data_wr : std_logic_vector(31 DOWNTO 0); --! Write data to sdm_device
33  data_rd : std_logic_vector(31 DOWNTO 0); --! Expected read data from sdm_device
34  percent : t_percent_array; --! Expected sdm percents
35  END RECORD t_stimulus;
36 
37  --! Stimulus array type
38  TYPE t_stimulus_array IS ARRAY(natural RANGE <>) OF t_stimulus;
39 
40  --! Test stimulus
42  (
43  (
44  name => "Reset ",
45  rst => '1',
46  data_wr => X"FFFFFFFF",
47  data_rd => X"00000000",
48  percent => (0, 0, 0, 0)
49  ),
50  (
51  name => "Set 0, 0, 0, 0 ",
52  rst => '0',
53  data_wr => X"00000000",
54  data_rd => X"00000000",
55  percent => (0, 0, 0, 0)
56  ),
57  (
58  name => "Set 255, 255, 255, 255 ",
59  rst => '0',
60  data_wr => X"FFFFFFFF",
61  data_rd => X"FFFFFFFF",
62  percent => (100, 100, 100, 100)
63  ),
64  (
65  name => "Set 127, 127, 127, 127 ",
66  rst => '0',
67  data_wr => X"7F7F7F7F",
68  data_rd => X"7F7F7F7F",
69  percent => (50, 50, 50, 50)
70  ),
71  (
72  name => "Set 0, 85, 170, 255 ",
73  rst => '0',
74  data_wr => X"FFAA5500",
75  data_rd => X"FFAA5500",
76  percent => (0, 33, 67, 100)
77  ),
78  (
79  name => "Set 0, 0, 0, 0 ",
80  rst => '0',
81  data_wr => X"00000000",
82  data_rd => X"00000000",
83  percent => (0, 0, 0, 0)
84  )
85  );
86 
87  -- Signals to uut
88  SIGNAL clk : std_logic; --! Clock input to uut
89  SIGNAL rst : std_logic; --! Reset input to uut
90  SIGNAL dat_wr_done : std_logic; --! Data write done input to uut
91  SIGNAL dat_wr_reg : std_logic_vector(31 DOWNTO 0); --! Data write register input to uut
92  SIGNAL dat_rd_reg : std_logic_vector(31 DOWNTO 0); --! Data read register output from uut
93  SIGNAL sdm_out : std_logic_vector(3 DOWNTO 0); --! PWM outputs from uut
94 
95  -- Signals to on_percent
96  SIGNAL on_rst : std_logic; --! Reset input to on_percent
97  SIGNAL on_percent : t_percent_array; --! Percent output from on_percent
98 
99  --! Function to create string from std_logic_vector
100  FUNCTION to_string (
101  vector : std_logic_vector) RETURN string
102  IS
103 
104  VARIABLE v_str : string(1 TO vector'length);
105 
106  BEGIN
107 
108  FOR i IN vector'range LOOP
109  v_str(i + 1) := std_logic'image(vector(i))(2);
110  END LOOP;
111 
112  RETURN v_str;
113 
114  END FUNCTION to_string;
115 
116 BEGIN
117 
118  --! Instantiate SDM device as uut
119  i_uut : ENTITY work.sdm_device(rtl)
120  PORT MAP (
121  clk_in => clk,
122  rst_in => rst,
126  sdm_out => sdm_out
127  );
128 
129  --! Generate on_percent measuring entities
130  g_on_percent : FOR i IN 0 TO 3 GENERATE
131 
132  --! Instantiate on_percent
133  i_on_percent : ENTITY work.sim_on_percent(sim)
134  PORT MAP (
135  clk_in => clk,
136  rst_in => on_rst,
137  signal_in => sdm_out(i),
138  percent_out => on_percent(i)
139  );
140 
141  END GENERATE g_on_percent;
142 
143  --! @brief Clock generator process
144  --!
145  --! This generates the clk signal and the adv signal
146  pr_clock : PROCESS IS
147  BEGIN
148 
149  clk <= '0';
150  WAIT FOR c_clk_period / 2;
151 
152  clk <= '1';
153  WAIT FOR c_clk_period / 2;
154 
155  END PROCESS pr_clock;
156 
157  --! @brief Stimulus process to drive SDM unit under test
158  pr_stimulus : PROCESS IS
159  BEGIN
160 
161  -- Initialize entity inputs
162  rst <= '1';
163  on_rst <= '1';
164  dat_wr_reg <= (OTHERS => '0');
165  dat_wr_done <= '0';
166  WAIT FOR c_clk_period;
167 
168  -- Loop over stimulus
169  FOR s IN c_stimulus'range LOOP
170 
171  -- Log start of stimulus
172  REPORT "Starting: " & c_stimulus(s).name SEVERITY note;
173 
174  -- Perform write to device
175  rst <= c_stimulus(s).rst;
177  dat_wr_done <= '1';
178  WAIT FOR c_clk_period;
179  dat_wr_done <= '0';
180 
181  -- Wait for sdms to stabilize
182  WAIT FOR 256 * c_clk_period;
183 
184  -- Enable sdm counting
185  on_rst <= '0';
186 
187  -- Accumuate 256*10 clocks
188  WAIT FOR 2560 * c_clk_period;
189 
190  -- Assert sdm channels
191  FOR i IN 0 TO 3 LOOP
192 
193  -- Assert sdm channel
194  ASSERT on_percent(i) >= c_stimulus(s).percent(i) - 5 AND
195  on_percent(i) <= c_stimulus(s).percent(i) + 5
196  REPORT "SDM channel " &
197  integer'image(i) &
198  " expected sdm of " &
199  integer'image(c_stimulus(s).percent(i)) &
200  " but got " &
201  integer'image(on_percent(i))
202  SEVERITY error;
203 
204  END LOOP;
205 
206  -- Assert read from device
207  ASSERT dat_rd_reg = c_stimulus(s).data_rd
208  REPORT "Expected read of " &
209  to_string(c_stimulus(s).data_rd) &
210  " but got " &
211  to_string(dat_rd_reg)
212  SEVERITY error;
213 
214  -- Stop pwm counting
215  on_rst <= '1';
216 
217  END LOOP;
218 
219  -- Log end of test
220  REPORT "Finished" SEVERITY note;
221 
222  -- Finish the simulation
223  std.env.finish;
224 
225  END PROCESS pr_stimulus;
226 
227 END ARCHITECTURE tb;
t_stimulus_array :=((name => "Reset ",rst => '1',data_wr => X"FFFFFFFF",data_rd => X"00000000",percent =>( 0, 0, 0, 0)),(name => "Set 0, 0, 0, 0 ",rst => '0',data_wr => X"00000000",data_rd => X"00000000",percent =>( 0, 0, 0, 0)),(name => "Set 255, 255, 255, 255 ",rst => '0',data_wr => X"FFFFFFFF",data_rd => X"FFFFFFFF",percent =>( 100, 100, 100, 100)),(name => "Set 127, 127, 127, 127 ",rst => '0',data_wr => X"7F7F7F7F",data_rd => X"7F7F7F7F",percent =>( 50, 50, 50, 50)),(name => "Set 0, 85, 170, 255 ",rst => '0',data_wr => X"FFAA5500",data_rd => X"FFAA5500",percent =>( 0, 33, 67, 100)),(name => "Set 0, 0, 0, 0 ",rst => '0',data_wr => X"00000000",data_rd => X"00000000",percent =>( 0, 0, 0, 0))) c_stimulus
Test stimulus.
std_logic_vector( 31 DOWNTO 0) dat_wr_reg
Data write register input to uut.
_library_ ieeeieee
Using IEEE library.
t_percent_array on_percent
Percent output from on_percent.
std_logic on_rst
Reset input to on_percent.
std_logic clk
Clock input to uut.
in signal_instd_logic
Signal input.
in clk_instd_logic
Clock.
Definition: sdm_device.vhd:22
Entity to measure on-percentage of signal.
SDM device test bench.
in dat_wr_done_instd_logic
Device Write Done flag.
Definition: sdm_device.vhd:24
out sdm_outstd_logic_vector( 3 DOWNTO 0)
Modulator outputs.
Definition: sdm_device.vhd:28
( 0 TO 3) integer t_percent_array
Type for percentage array.
std_logic_vector( 31 DOWNTO 0) data_wr
Write data to sdm_device.
std_logic_vector( 3 DOWNTO 0) sdm_out
PWM outputs from uut.
in clk_instd_logic
Clock.
std_logic rst
Reset input to sdm_device.
std_logic dat_wr_done
Data write done input to uut.
in rst_instd_logic
Asynchronous reset.
Definition: sdm_device.vhd:23
std_logic_vector( 31 DOWNTO 0) data_rd
Expected read data from sdm_device.
t_percent_array percent
Expected sdm percents.
t_stimulus
Stimulus record type.
Sigma-Delta modulator device entity.
Definition: sdm_device.vhd:20
array(natural range <> ) of t_stimulus t_stimulus_array
Stimulus array type.
std_logic_vector( 31 DOWNTO 0) dat_rd_reg
Data read register output from uut.
in rst_instd_logic
Asynchronous reset.
in dat_wr_reg_instd_logic_vector( 31 DOWNTO 0)
Device Write Register value.
Definition: sdm_device.vhd:25
time := 10 ns c_clk_period
Test bench clock period.
string to_stringvector,
Function to create string from std_logic_vector.
out percent_outinteger
On percentage output.
string( 1 TO 30) name
Stimulus name.
out dat_rd_reg_outstd_logic_vector( 31 DOWNTO 0)
Device Read Register value.
Definition: sdm_device.vhd:26