1 -------------------------------------------------------------------------------
2 --! @file motor_control_unit_tb.vhd
3 --! @author Marc Kossmann
4 --! @author Michael Riedel
8 --! @brief Testbench for Motor-Control-Unit Component
9 --! @details Tests full functionality of component
12 --! @details v0.1.0 26.11.2014 Riedel
14 --! @details v0.1.1 27.11.2014 Riedel
15 --! - implemented first test-procedures
16 --! @details v0.1.2 28.11.2014 Riedel
17 --! - added documentation for GENERIC divider
18 --! - moved test-procedure-documentation to doxygen-heade
19 --! @details v0.1.3 30.11.2014 Kossmann
20 --! - changed divider to 250 to get 1 ms in simulation for 1 s
21 --! in real. Simulation takes longer but easier to measure
22 --! - Test-procedure must no commented in or out for easier readability
23 --! - initialized every signal
24 --! @details v0.1.4 30.11.2014 Riedel & Kossmann
25 --! - wiring new run signal for signal_generator
27 --! @details v0.1.5 03.12.2014 Kossmann
28 --! - implemented more testcases
29 --! @details v1.0.0 05.12.2014 Riedel & Kossmann
30 --! - release milestone 3b
31 -------------------------------------------------------------------------------
33 --! Use Standard Library
35 --! Use Logic Elements
36 USE ieee.STD_LOGIC_1164.
all;
37 --! Use Arithmetic Functions
38 USE ieee.STD_LOGIC_arith.
all;
39 --! Use Conversion Functions
40 USE ieee.STD_LOGIC_SIGNED.
all;
42 --! @brief Entity of testbench for motor_control_unit
46 --! @brief Prescaler for PWM-signal.
47 --! @details For this purpose 2,5 ms are used as minimal pulse-width.
48 --! @details The prescaler is calculated with the given and desired frequency
49 --! via the following formula:
51 --! \text{prescaler} = \frac{f_{\text{clock}} \text{Hz}}{f_{\text{prescaler}} \text{Hz}}
55 --! \left.\begin{aligned}
56 --! f_{\text{prescaler}} &= \frac{5}{2}\,\text{ms} \newline
57 --! &= 400\,\text{Hz} \newline\newline
58 --! \text{prescaler} &= \frac{50\,\text{Mhz}}{400\,\text{Hz}} \newline
59 --! &= 125000 \newline
62 --! \qquad \text{pulse-width: 2.5 ms}
64 --! @details For simulation-purpose the divider was set to 125 for faster wave generation.
69 --! @brief Architecture of testbench for motor_control_unit
72 SIGNAL motor_pwm : (3 DOWNTO 0) := "0000";
73 SIGNAL reset_n : := '1';
74 SIGNAL clock : := '0';
75 SIGNAL speed : (2 DOWNTO 0) := "000";
76 SIGNAL mode : (3 DOWNTO 0) := "0000";
77 SIGNAL direction : := '0';
80 SIGNAL steps : (31 DOWNTO 0) := (others => '0');
81 SIGNAL motor_en : (1 DOWNTO 0) := "00";
82 CONSTANT left : := '0';
83 CONSTANT right : := NOT left;
95 speed :
IN (
2 DOWNTO 0);
96 mode :
IN (
3 DOWNTO 0);
100 steps :
OUT (
31 DOWNTO 0);
125 clock <= not clock after 10 ns;
127 -- Test-procedure (1), reset_n
131 -- Test-procedure (2), Continuous Run with speed = 0, direction = left
132 -- 5 ms sim time for two pulses
133 -- run <= '1' after 20 ns;
134 -- mode <= "0001" after 20 ns;
135 -- direction <= left;
138 -- Test-procedure (3), Continuous Run with speed = 1, direction = left, R/S toggle
139 -- 3 ms sim time for two pulses
140 -- run <= '1' after 20 ns,
141 -- '0' after 3000 us,
142 -- '1' after 3100 us;
143 -- mode <= "0001" after 20 ns;
144 -- direction <= left;
147 -- Test-procedure (4), Continuous Run with speed = 7, direction = left
148 -- 15 us sim time for two pulses
149 -- run <= '1' after 20 ns;
150 -- mode <= "0001" after 20 ns;
151 -- direction <= left;
154 -- Test-procedure (5), Continuous Run with speed = 7, direction = right
155 -- 15 us sim time for two pulses
156 -- run <= '1' after 20 ns;
157 -- mode <= "0001" after 20 ns;
158 -- direction <= right;
161 -- Test-procedure (6), Chain of Steps - 1/4 rotation with speed = 7, direction = left
162 -- 750 us sim time for 1/4 rotation
163 -- register_interface_sim : process(clock)
165 -- if (reset_n = '0') then
168 -- elsif(rising_edge(clock)) then
177 -- mode <= "0010" after 20 ns;
178 -- direction <= right;
179 -- speed <= "111" after 20 ns;
181 -- Test-procedure (7), Chain of Steps - 1/4 rotation with speed = 7, direction = left/right switch
182 -- 750 us sim time for 1/4 rotation
183 -- register_interface_sim : process(clock)
185 -- if (reset_n = '0') then
187 -- elsif(rising_edge(clock)) then
196 -- mode <= "0010" after 20 ns;
197 -- direction <= right,
198 -- left after 300 us;
199 -- speed <= "111" after 20 ns;
201 -- Test-procedure (8), Chain of Steps - 1/4 rotation with speed = 7, direction = left with R/S restart
202 -- 750 us sim time for 1/4 rotation
203 -- register_interface_sim : process(clock)
205 -- if (reset_n = '0') then
207 -- elsif(rising_edge(clock)) then
216 -- mode <= "0010" after 20 ns;
217 -- direction <= right,
218 -- left after 300 us;
219 -- speed <= "111" after 20 ns;
221 -- Test-procedure (9): Chain of Steps - 1/2 rotation with speed = 7, direction = left
222 -- 1100 us sim time for 1/2 rotation
223 -- register_interface_sim : process(clock)
225 -- if (reset_n = '0') then
227 -- elsif(rising_edge(clock)) then
236 -- mode <= "0110" after 20 ns;
237 -- direction <= right,
238 -- left after 300 us;
239 -- speed <= "111" after 20 ns;
241 -- Test-procedure (10): Chain of Steps - 1 rotation with speed = 7, direction = left
242 -- 2100 us sim time for 1 rotation
243 -- register_interface_sim : process(clock)
245 -- if (reset_n = '0') then
247 -- elsif(rising_edge(clock)) then
256 -- mode <= "1010" after 20 ns;
257 -- direction <= right,
258 -- left after 300 us;
259 -- speed <= "111" after 20 ns;
261 -- Test-procedure (11): Chain of Steps - 2 rotation with speed = 7, direction = left
262 -- 4200 us sim time for 2 rotation
263 -- register_interface_sim : process(clock)
265 -- if (reset_n = '0') then
267 -- elsif(rising_edge(clock)) then
276 -- mode <= "1110" after 20 ns;
277 -- direction <= right,
278 -- left after 300 us;
279 -- speed <= "111" after 20 ns;
281 -- Test-procedure (12): Reserved mode with speed = 7, direction = left
282 -- 200 us sim time for 2 rotation
283 -- register_interface_sim : process(clock)
285 -- if (reset_n = '0') then
287 -- elsif(rising_edge(clock)) then
296 -- mode <= "1111" after 20 ns;
297 -- direction <= right,
298 -- left after 300 us;
299 -- speed <= "111" after 20 ns;
301 finish_sim_time :
PROCESS
305 REPORT "simulation finished"
307 END PROCESS finish_sim_time;
in modeSTD_LOGIC_VECTOR(3 DOWNTO0)
mode to run motor with
in clockSTD_LOGIC
component clock
out motor_enSTD_LOGIC_VECTOR(1 DOWNTO0)
both enable signals for the motor
dividerinteger:=125000
Prescaler for PWM-signal.
in directionSTD_LOGIC
motor direction ('0' is left)
dividerinteger:=125
Prescaler for PWM-signal.
in reset_nSTD_LOGIC
resets the component
_library_ ieeeieee
Use Standard Library.
in runSTD_LOGIC
chip enable
out irSTD_LOGIC
IR signal set when motor stopped.
out motor_pwmSTD_LOGIC_VECTOR(3 DOWNTO0)
signal-bus for the motor pulse-width-modulation
Entity of testbench for motor_control_unit.
in speedSTD_LOGIC_VECTOR(2 DOWNTO0)
speed to run moter with
out stepsSTD_LOGIC_VECTOR(31 DOWNTO0)
number of steps motor did