Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
sdm_tb.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief Sigma-Delta modulator 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 Sigma-Delta modulator test bench
16 ENTITY sdm_tb IS
17 END ENTITY sdm_tb;
18 
19 --! Architecture tb of sdm_tb entity
20 ARCHITECTURE tb OF sdm_tb IS
21 
22  --! Test bench clock period
23  CONSTANT c_clk_period : time := 10 ns;
24 
25  --! Stimulus record type
26  TYPE t_stimulus IS RECORD
27  name : string(1 TO 20); --! Stimulus name
28  rst : std_logic; --! rst input to uut
29  sdm_level : std_logic_vector(1 DOWNTO 0); --! sdm_level input to uut
30  percent : integer; --! Expected on-percent from uut
31  END RECORD t_stimulus;
32 
33  --! Stimulus array type
34  TYPE t_stimulus_array IS ARRAY(natural RANGE <>) OF t_stimulus;
35 
36  --! Test stimulus
38  (
39  (
40  name => "Hold in reset ",
41  rst => '1',
42  sdm_level => B"11",
43  percent => 0
44  ),
45  (
46  name => "Running value 0 ",
47  rst => '0',
48  sdm_level => B"00",
49  percent => 0
50  ),
51  (
52  name => "Running value 1 ",
53  rst => '0',
54  sdm_level => B"01",
55  percent => 25
56  ),
57  (
58  name => "Running value 2 ",
59  rst => '0',
60  sdm_level => B"10",
61  percent => 50
62  ),
63  (
64  name => "Running value 3 ",
65  rst => '0',
66  sdm_level => B"11",
67  percent => 75
68  )
69  );
70 
71  -- Signals to uut
72  SIGNAL clk : std_logic; --! Clock input to sdm uut
73  SIGNAL rst : std_logic; --! Reset input to sdm uut
74  SIGNAL sdm_level : std_logic_vector(1 DOWNTO 0); --! Level input to sdm uut
75  SIGNAL sdm_out : std_logic; --! Modulator output from sdm uut
76 
77  -- Signals to on_percent
78  SIGNAL on_rst : std_logic; --! Reset input to on_percent
79  SIGNAL on_percent : integer; --! Percent output from on_percent
80 
81 BEGIN
82 
83  --! Instantiate sigma-delta modulator as unit under test
84  i_uut : ENTITY work.sdm(rtl)
85  GENERIC MAP (
86  bit_width => 2
87  )
88  PORT MAP (
89  clk_in => clk,
90  rst_in => rst,
92  sdm_out => sdm_out
93  );
94 
95  --! Instantiate on_percent
96  i_on_percent : ENTITY work.sim_on_percent(sim)
97  PORT MAP (
98  clk_in => clk,
99  rst_in => on_rst,
100  signal_in => sdm_out,
102  );
103 
104  --! @brief Clock generation process
105  pr_clock : PROCESS IS
106  BEGIN
107 
108  -- Low for 1/2 clock period
109  clk <= '0';
110  WAIT FOR c_clk_period / 2;
111 
112  -- High for 1/2 clock period
113  clk <= '1';
114  WAIT FOR c_clk_period / 2;
115 
116  END PROCESS pr_clock;
117 
118  --! @brief Stimulus process to drive PWM unit under test
119  pr_stimulus : PROCESS IS
120  BEGIN
121 
122  -- Initialize entity inputs
123  rst <= '1';
124  sdm_level <= (OTHERS => '0');
125  on_rst <= '1';
126  WAIT FOR c_clk_period;
127 
128  -- Loop over stimulus
129  FOR s IN c_stimulus'range LOOP
130  -- Log start of stimulus
131  REPORT "Starting: " & c_stimulus(s).name SEVERITY note;
132 
133  -- Set stimulus inputs
135  rst <= c_stimulus(s).rst;
136 
137  -- Wait for sdm to stabilize
138  WAIT FOR 10 * c_clk_period;
139 
140  -- Enable sdm counting
141  on_rst <= '0';
142 
143  -- Accumuate 100 clocks
144  WAIT FOR 100 * c_clk_period;
145 
146  -- Assert outputs
147  ASSERT on_percent >= c_stimulus(s).percent - 5 AND
148  on_percent <= c_stimulus(s).percent + 5
149  REPORT "Expected sdm of " & integer'image(c_stimulus(s).percent)
150  & " but got " & integer'image(on_percent)
151  SEVERITY error;
152 
153  -- Stop sdm counting
154  on_rst <= '1';
155  END LOOP;
156 
157  -- Log end of test
158  REPORT "Finished" SEVERITY note;
159 
160  -- Finish the simulation
161  std.env.finish;
162 
163  END PROCESS pr_stimulus;
164 
165 END ARCHITECTURE tb;
166 
integer on_percent
Percent output from on_percent.
Definition: sdm_tb.vhd:79
in rst_instd_logic
Asynchronous reset.
Definition: sdm.vhd:25
string( 1 TO 20) name
Stimulus name.
Definition: sdm_tb.vhd:27
Sigma-Delta modulator test bench.
Definition: sdm_tb.vhd:16
in sdm_level_instd_logic_vector( bit_width- 1 DOWNTO 0)
Modulator level.
Definition: sdm.vhd:26
in signal_instd_logic
Signal input.
t_stimulus_array :=((name => "Hold in reset ",rst => '1',sdm_level => B"11",percent => 0),(name => "Running value 0 ",rst => '0',sdm_level => B"00",percent => 0),(name => "Running value 1 ",rst => '0',sdm_level => B"01",percent => 25),(name => "Running value 2 ",rst => '0',sdm_level => B"10",percent => 50),(name => "Running value 3 ",rst => '0',sdm_level => B"11",percent => 75)) c_stimulus
Test stimulus.
Definition: sdm_tb.vhd:37
Entity to measure on-percentage of signal.
in clk_instd_logic
Clock.
Definition: sdm.vhd:24
array(natural range <> ) of t_stimulus t_stimulus_array
Stimulus array type.
Definition: sdm_tb.vhd:34
out sdm_outstd_logic
Modulator output.
Definition: sdm.vhd:28
std_logic on_rst
Reset input to on_percent.
Definition: sdm_tb.vhd:78
integer percent
Expected on-percent from uut.
Definition: sdm_tb.vhd:30
bit_widthinteger range 1 TO 32:= 8
Bit width.
Definition: sdm.vhd:22
_library_ ieeeieee
Using IEEE library.
in clk_instd_logic
Clock.
std_logic_vector( 1 DOWNTO 0) sdm_level
sdm_level input to uut
Definition: sdm_tb.vhd:29
Using IEE standard numeric components Sigma-Delta modulator entityThis entity is a configurable firs...
Definition: sdm.vhd:19
std_logic sdm_out
Modulator output from sdm uut.
Definition: sdm_tb.vhd:75
t_stimulus
Stimulus record type.
Definition: sdm_tb.vhd:26
std_logic clk
Clock input to sdm uut.
Definition: sdm_tb.vhd:72
std_logic rst
rst input to uut
Definition: sdm_tb.vhd:28
time := 10 ns c_clk_period
Test bench clock period.
Definition: sdm_tb.vhd:23
in rst_instd_logic
Asynchronous reset.
out percent_outinteger
On percentage output.