1 -------------------------------------------------------------------------------
2 --! @file milestone3_tb.vhd
3 --! @author Marc Kossmann
4 --! @author Michael Riedel
8 --! @brief Testbench for Milestone 3
9 --! @details Tests the bahavior when all components are wired together
11 --! @details v0.1.0 02.12.2014 Kossmann
13 --! @details v0.1.1 04.12.2014 Riedel
14 --! - corrected output-naming for LEDs
15 --! - corrected formatting and indention
16 --! @details v1.0.0 05.12.2014 Riedel & Kossmann
17 --! - release milestone 3b
18 -------------------------------------------------------------------------------
20 --! Use Standard Library
22 --! Use Logic Elements
23 USE ieee.STD_LOGIC_1164.
all;
24 --! Use Arithmetic Functions
25 USE ieee.STD_LOGIC_arith.
all;
26 --! Use Conversion Functions
27 USE ieee.STD_LOGIC_SIGNED.
all;
29 --! @brief Entity of testbench for milestone3
33 --! @brief Prescaler for PWM-signal.
34 --! @details For this purpose 2,5 ms are used as minimal pulse-width.
35 --! @details The prescaler is calculated with the given and desired frequency
36 --! via the following formula:
38 --! \text{prescaler} = \frac{f_{\text{clock}} \text{Hz}}{f_{\text{prescaler}} \text{Hz}}
42 --! \left.\begin{aligned}
43 --! f_{\text{prescaler}} &= \frac{5}{2}\,\text{ms} \newline
44 --! &= 400\,\text{Hz} \newline\newline
45 --! \text{prescaler} &= \frac{50\,\text{Mhz}}{400\,\text{Hz}} \newline
46 --! &= 125000 \newline
49 --! \qquad \text{pulse-width: 2.5 ms}
51 --! @details For simulation-purpose the divider was set to 125 for faster wave generation.
56 --! @brief Architecture of testbench for milestone3
59 SIGNAL LEDG : (7 DOWNTO 0) := (others => '0');
60 SIGNAL CLOCK_50_B5B : := '0';
61 SIGNAL HSMC_TX_P : (16 DOWNTO 0) := (others => '0');
62 SIGNAL HSMC_RX_N : (16 DOWNTO 0) := (others => '0');
63 SIGNAL KEY : (3 DOWNTO 0) := (others => '1');
-- low active
64 SIGNAL SW : (9 DOWNTO 0) := (others => '0');
65 SIGNAL LEDR : (7 DOWNTO 0) := (others => '0');
66 SIGNAL HSMC_TX_N : (16 DOWNTO 0) := (others => '0');
67 SIGNAL HSMC_RX_P : (16 DOWNTO 0) := (others => '0');
68 SIGNAL CPU_RESET_n : := '0';
75 LEDG :
OUT (
7 DOWNTO 0);
79 KEY :
IN (
3 DOWNTO 0);
81 LEDR :
OUT (
7 DOWNTO 0);
107 CLOCK_50_B5B <= not CLOCK_50_B5B AFTER 10 ns;
109 CPU_RESET_n <= '0', '1' AFTER 20 ns;
111 --Basic functionality
112 --Testing continous run with speed 7.
114 -- sw(1) <= '0'; --direction ('0' is left)
115 -- sw(5 DOWNTO 2) <= "0001"; --mode
116 -- sw(6) <= '1'; --interrupt enabled
117 -- sw(9 DOWNTO 7) <= "111"; --speed
119 -- key(0) <= '0' AFTER 100 ns, --on
122 --Testing continous run with speed 7 and 6. Run/stop switched
124 -- sw(1) <= '0'; --direction ('0' is left)
125 -- sw(5 DOWNTO 2) <= "0001"; --mode
126 -- sw(6) <= '1'; --interrupt enabled
127 -- sw(9 DOWNTO 7) <= "111", --speed
128 -- "110" AFTER 200 us;
130 -- key(0) <= '0' AFTER 100 ns, --on
132 -- '0' AFTER 300 us, --off
134 -- '0' AFTER 400 us, --on
137 --Testing Chain of Steps 1/4 with speed 7. Direction switched and restart
139 -- sw(1) <= '0', --direction ('0' is left)
141 -- sw(5 DOWNTO 2) <= "0010"; --mode
142 -- sw(6) <= '1'; --interrupt enabled
143 -- sw(9 DOWNTO 7) <= "111"; --speed
144 -- key(0) <= '0' AFTER 100 ns, -- low active
147 --Testing Chain of Steps 1/2 with speed 7. Direction switched
149 --sw(1) <= '0', --direction ('0' is left)
151 -- sw(5 DOWNTO 2) <= "0110"; --mode
152 -- sw(6) <= '1'; --interrupt enabled
153 -- sw(9 DOWNTO 7) <= "111"; --speed
154 -- key(0) <= '0' AFTER 100 ns, -- low active
156 -- '0' AFTER 550 us, --on
159 -- Testing CoS 1/4 after finish CoS 1/2 with speed = 7, direction = left
160 -- 3000 us sim time for both
161 sw(1) <= '0';
--direction ('0' is left)
162 sw(5 DOWNTO 2) <= "0010", --mode
163 "0110" after 1200 us;
164 sw(6) <= '1';
--interrupt enabled
165 sw(9 DOWNTO 7) <= "111";
--speed
166 key(0) <= '0' AFTER 100 ns, -- on
168 '0' AFTER 1250 us, -- off
170 '0' AFTER 1350 us, -- on
173 -- Testing CoS 1/2 multiple times with speed = 7, direction = left
174 -- 4000 us sim time for both
175 -- sw(1) <= '0'; --direction ('0' is left)
176 -- sw(5 DOWNTO 2) <= "0110"; --mode
177 -- sw(6) <= '1'; --interrupt enabled
178 -- sw(9 DOWNTO 7) <= "111"; --speed
179 -- key(0) <= '0' AFTER 100 ns, -- on
181 -- '0' AFTER 1050 us, -- off
182 -- '1' AFTER 1051 us,
183 -- '0' AFTER 2200 us, -- on
184 -- '1' AFTER 2201 us,
185 -- '0' AFTER 3400 us, -- off
186 -- '1' AFTER 3401 us;
out HSMC_RX_PSTD_LOGIC_VECTOR(16 DOWNTO0)
Motor_pwm1( bit 0 ) and Motor_pwm2( bit 1 )
Entity of testbench for milestone3.
out LEDRSTD_LOGIC_VECTOR(7 DOWNTO0)
red leds
dividerINTEGER:=125
Prescaler for PWM-signal.
dividerinteger:=125000
Prescaler for PWM-signal.
in CPU_RESET_nSTD_LOGIC
resets the component
out LEDGSTD_LOGIC_VECTOR(7 DOWNTO0)
green leds
in SWSTD_LOGIC_VECTOR(9 DOWNTO0)
switch input
out HSMC_TX_PSTD_LOGIC_VECTOR(16 DOWNTO0)
Motor_en_b( bit 3 )
in CLOCK_50_B5BSTD_LOGIC
component clock
out HSMC_TX_NSTD_LOGIC_VECTOR(16 DOWNTO0)
Motor_en_a( bit 2 )
in KEYSTD_LOGIC_VECTOR(3 DOWNTO0)
key input
out HSMC_RX_NSTD_LOGIC_VECTOR(16 DOWNTO0)
Motor_pwm3( bit 0 ) and Motor_pwm4( bit 1 )
_library_ ieeeieee
Use Standard Library.