]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - tb/tb_wave_table.vhd
Added vector generator.
[fpga/pwm.git] / tb / tb_wave_table.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 use ieee.std_logic_unsigned.all;
5
6 entity tb_wave_table is
7 end tb_wave_table;
8
9 --------------------------------------------------------------------------------
10
11 architecture testbench of tb_wave_table is
12
13   constant period : time := 37.5 ns;
14   constant offset : time := 0 us;
15
16   constant DAT_W     : integer := 10;
17   constant ADR_W     : integer := 9;
18   constant INIT_FILE : string  := "../sin.lut";
19
20   constant WAVE_SIZE : integer := 2**ADR_W;
21
22
23   signal ACK_O : std_logic;
24   signal ADR_I : std_logic_vector (ADR_W-1 downto 0);
25   signal CLK_I : std_logic;
26   signal DAT_I : std_logic_vector (DAT_W-1 downto 0);
27   signal DAT_O : std_logic_vector (DAT_W-1 downto 0);
28   signal STB_I : std_logic;
29   signal WE_I  : std_logic;
30   signal RST_I : std_logic;
31
32 --------------------------------------------------------------------------------
33
34   component wave_table is
35     generic (
36       DAT_W     : integer;
37       ADR_W     : integer;
38       INIT_FILE : string);
39     port (
40       ACK_O : out std_logic;
41       ADR_I : in  std_logic_vector (ADR_W-1 downto 0);
42       CLK_I : in  std_logic;
43       DAT_I : in  std_logic_vector (DAT_W-1 downto 0);
44       DAT_O : out std_logic_vector (DAT_W-1 downto 0);
45       STB_I : in  std_logic;
46       WE_I  : in  std_logic);
47   end component wave_table;
48   
49 --------------------------------------------------------------------------------
50   
51 begin
52   
53   uut : wave_table
54     generic map (
55       DAT_W     => DAT_W,
56       ADR_W     => ADR_W,
57       INIT_FILE => INIT_FILE)
58     port map (
59       ACK_O => ACK_O,
60       ADR_I => ADR_I,
61       CLK_I => CLK_I,
62       DAT_I => DAT_I,
63       DAT_O => DAT_O,
64       STB_I => STB_I,
65       WE_I  => WE_I);
66   
67   SYSCON_CLK : process
68   begin
69     CLK_I <= '0';
70     wait for offset;
71     loop
72       CLK_I <= '1';
73       wait for period/2;
74       CLK_I <= '0';
75       wait for period/2;
76     end loop;
77   end process;
78
79   SYSCON_RST : process
80   begin
81     RST_I <= '0';
82     wait for offset;
83     wait for 0.75*period;
84     RST_I <= '1';
85     wait for 2*period;
86     RST_I <= '0';
87     wait;
88   end process;
89     
90 --------------------------------------------------------------------------------
91
92   UUT_FEED : process
93   begin
94     DAT_I <= (others => '0');
95     ADR_I <= (others => '0');
96     STB_I <= '0';
97     WE_I  <= '0';
98     
99     wait for offset;
100     wait for 4*period;
101     
102     for i in 0 to 2*(WAVE_SIZE-1) loop
103       ADR_I <= conv_std_logic_vector(i, ADR_W);
104       STB_I <= '1';
105       wait until ACK_O = '1';
106       wait for period;
107       STB_I <= '0';
108       wait for period;
109     end loop;
110     
111     wait;
112   end process;
113   
114 end testbench;
115