1 | -- FMT FAU Erlangen -----------------------------------------------
|
2 | -- moving_average_tb: --
|
3 | -- verify the moving_average module with an sinusodial oscilation--
|
4 | -- The generic parameters can be modified in the constant --
|
5 | -- section. --
|
6 | -- --
|
7 | -------------------------------------------------------------------
|
8 |
|
9 | -- Programming style ----------------------------------------------
|
10 | -- parameter prefix | description --
|
11 | -- g_ | generic, for entity declatation --
|
12 | -- i_ | input, for entity declatation --
|
13 | -- o_ | output, for entity declatation --
|
14 | -- io_ | in-/output, for entity declatation --
|
15 | -- c_ | constant, for architecture declatation --
|
16 | -- t_ | type, for architecture declatation --
|
17 | -- w_ | wire, used for internal signals --
|
18 | -- tb_ | testbench, used for internal signals --
|
19 | -- p_ | process, used for process labels --
|
20 | -- inst_ | instantiate, used fpr component instan- --
|
21 | -- tiation --
|
22 | -- --
|
23 | -- parameter suffix | description --
|
24 | -- _reg | regular signal, for register (synchron) --
|
25 | -- _next | next signal, for register (asynchron) --
|
26 | -- _s | synchronised --
|
27 | -- --
|
28 | -------------------------------------------------------------------
|
29 |
|
30 | -- Revision History -----------------------------------------------
|
31 | -- Version: | Author: | Mod. Date: | Changes Made: --
|
32 | -- 0.1 | Koehnen | 05/09/17: | Module developement --
|
33 | -------------------------------------------------------------------
|
34 |
|
35 | library ieee;
|
36 | use ieee.std_logic_1164.all;
|
37 | use ieee.numeric_std.all;
|
38 |
|
39 |
|
40 | entity moving_average_tb is
|
41 | end entity moving_average_tb;
|
42 |
|
43 |
|
44 | architecture behavioral of moving_average_tb is
|
45 |
|
46 | -- constants
|
47 | constant tb_clk_periode : time := 20 ns; -- 50 MHz
|
48 |
|
49 | constant tb_g_phasewidth : positive := 6; -- recommended maximum: 22
|
50 | constant tb_g_ampliduewidth : positive := 6; -- describes also input data width of moving average module
|
51 | constant tb_g_data_width : positive := 6; -- need to be the same as tb_g_ampliduewidth
|
52 | constant tb_g_shift_width : positive := 8; -- needs at least to be one bit higher then tb_g_phasewidth to observe more then one periode
|
53 |
|
54 | -- signals
|
55 | signal tb_i_clk : std_logic := '0';
|
56 | signal tb_i_reset : std_logic := '0';
|
57 | signal tb_i_step : std_logic_vector(tb_g_phasewidth/2 downto 0) := std_logic_vector(to_unsigned(1,tb_g_phasewidth/2+1));
|
58 | signal tb_i_step_size : std_logic_vector(tb_g_phasewidth/2 downto 0) := (others => '0');
|
59 | signal tb_o_sin_data : std_logic_vector(tb_g_ampliduewidth-1 downto 0);
|
60 | signal tb_o_moving_average : std_logic_vector(tb_g_ampliduewidth-1 downto 0);
|
61 | signal tb_o_trigger : std_logic;
|
62 |
|
63 | -- components
|
64 | component sineLUT is
|
65 | generic(
|
66 | g_phasewidth : positive := 9;
|
67 | g_ampliduewidth : positive := 14
|
68 | );
|
69 | port(
|
70 | i_clk : in std_logic;
|
71 | i_clk_en : in std_logic;
|
72 | i_reset : in std_logic;
|
73 | i_step_size: in std_logic_vector(g_phasewidth/2 downto 0) := (others => '0');
|
74 | i_step : in std_logic_vector(g_phasewidth/2 downto 0) := "01";
|
75 | o_sin_data : out std_logic_vector(g_ampliduewidth-1 downto 0);
|
76 | o_trigger : out std_logic
|
77 | );
|
78 | end component sineLUT;
|
79 |
|
80 | component moving_average is
|
81 | generic(
|
82 | g_data_width : positive := 4;
|
83 | g_shift_width : positive := 2
|
84 | );
|
85 | port(
|
86 | i_clk : in std_logic;
|
87 | i_clear : in std_logic;
|
88 | i_data : in std_logic_vector(g_data_width-1 downto 0);
|
89 | o_data : out std_logic_vector(g_data_width-1 downto 0)
|
90 | );
|
91 | end component moving_average;
|
92 |
|
93 |
|
94 | begin
|
95 |
|
96 | tb_i_reset <= '1', '0' after 10 ns;
|
97 |
|
98 | p_clock : process
|
99 | begin
|
100 | tb_i_clk <= '1';
|
101 | wait for tb_clk_periode/2;
|
102 | tb_i_clk <= '0';
|
103 | wait for tb_clk_periode/2;
|
104 | end process p_clock;
|
105 |
|
106 | inst_NCO : sineLUT
|
107 | generic map(
|
108 | g_phasewidth => tb_g_phasewidth,
|
109 | g_ampliduewidth => tb_g_ampliduewidth
|
110 | )
|
111 | port map(
|
112 | i_clk => tb_i_clk,
|
113 | i_clk_en => '1',
|
114 | i_reset => tb_i_reset,
|
115 | i_step => tb_i_step,
|
116 | i_step_size=> tb_i_step_size,
|
117 | o_sin_data => tb_o_sin_data,
|
118 | o_trigger => tb_o_trigger
|
119 | );
|
120 |
|
121 | inst_DUT : moving_average
|
122 | generic map(
|
123 | g_data_width => tb_g_data_width,
|
124 | g_shift_width => tb_g_shift_width
|
125 | )
|
126 | port map(
|
127 | i_clk => tb_i_clk,
|
128 | i_clear => tb_i_reset,
|
129 | i_data => tb_o_sin_data,
|
130 | o_data => tb_o_moving_average
|
131 | );
|
132 |
|
133 | end architecture behavioral;
|