OpenCores
URL https://opencores.org/ocsvn/quadratic_func/quadratic_func/trunk

Subversion Repositories quadratic_func

[/] [quadratic_func/] [trunk/] [vhdl/] [quadratic_func_bench.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sdoherty
----------------------------------------------------------------------
2
--                                                                  --
3
--  THIS VHDL SOURCE CODE IS PROVIDED UNDER THE GNU PUBLIC LICENSE  --
4
--                                                                  --
5
----------------------------------------------------------------------
6
--                                                                  --
7
--    Filename            : quadratic_func_bench.vhd                --
8
--                                                                  --
9
--    Author              : Simon Doherty                           --
10
--                          Senior Design Consultant                --
11
--                          www.zipcores.com                        --
12
--                                                                  --
13
--    Date last modified  : 16.02.2009                              --
14
--                                                                  --
15
--    Description         : Quadratic function testbench            --
16
--                                                                  --
17
----------------------------------------------------------------------
18
 
19
 
20
use std.textio.all;
21
 
22
library ieee;
23
use ieee.std_logic_1164.all;
24
use ieee.std_logic_textio.all;
25
use ieee.std_logic_arith.all;
26
 
27
 
28
entity quadratic_func_bench is
29
begin
30
end quadratic_func_bench;
31
 
32
 
33
architecture behav of quadratic_func_bench is
34
 
35
 
36
component quadratic_func
37
 
38
generic ( fw : integer ); -- width of fraction in range 0 to 8
39
 
40
port (
41
 
42
  -- system clock
43
  clk      : in  std_logic;
44
 
45
  -- clock enable
46
  en       : in  std_logic;
47
 
48
  -- Coefficients as 8-bit signed fraction
49
  coeff_a  : in  std_logic_vector(7 downto 0);
50
  coeff_b  : in  std_logic_vector(7 downto 0);
51
  coeff_c  : in  std_logic_vector(7 downto 0);
52
 
53
  -- Input as a 8-bit signed fraction
54
  x_in     : in  std_logic_vector(7 downto 0);
55
 
56
  -- Output as a 24-bit signed fraction
57
  y_out    : out std_logic_vector(23 downto 0));
58
 
59
end component;
60
 
61
 
62
signal  clk            : std_logic := '0';
63
signal  reset          : std_logic := '0';
64
signal  capture        : std_logic := '0';
65
signal  end_of_test    : std_logic := '0';
66
signal  count          : std_logic_vector(7 downto 0);
67
 
68
signal  coeff_a        : std_logic_vector(7 downto 0);
69
signal  coeff_b        : std_logic_vector(7 downto 0);
70
signal  coeff_c        : std_logic_vector(7 downto 0);
71
 
72
signal  x_in           : std_logic_vector(7 downto 0);
73
signal  y_out          : std_logic_vector(23 downto 0);
74
signal  y_int          : integer;
75
 
76
 
77
begin
78
 
79
 
80
-- Generate a 100MHz clk
81
clk <= not clk after 5 ns;
82
 
83
 
84
-- Test bench control
85
test_bench_control: process
86
begin
87
    -- start of test
88
    wait for 1 us;
89
        wait until clk'event and clk = '1';
90
        -- bring out of reset
91
    reset <= '1';
92
    -- module has 3-cycle latency
93
    wait until clk'event and clk = '1';
94
    wait until clk'event and clk = '1';
95
    wait until clk'event and clk = '1';
96
    -- start capturing the output
97
    capture <= '1';
98
    wait until clk'event and clk = '1' and end_of_test = '1';
99
    -- module has 3-cycle latency
100
    wait until clk'event and clk = '1';
101
    wait until clk'event and clk = '1';
102
    wait until clk'event and clk = '1';
103
    -- stop capturing the output
104
    capture <= '0';
105
    wait for 1 us;
106
    wait until clk'event and clk = '1';
107
    assert false report "    SIMULATION FINISHED!" severity failure;
108
end process test_bench_control;
109
 
110
 
111
-- generate input sequence from -128 to 127
112
counter: process(clk, reset)
113
begin
114
  if reset = '0' then
115
    count <= "10000000";
116
  elsif clk'event and clk = '1' then
117
    count <= unsigned(count) + '1';
118
  end if;
119
end process counter;
120
 
121
 
122
-- check for end of test
123
end_of_test <= '1' when (count = "01111111") else '0';
124
 
125
 
126
-- Fixed coefficients
127
coeff_a <= std_logic_vector(conv_signed( 55 ,8));
128
coeff_b <= std_logic_vector(conv_signed(-14, 8));
129
coeff_c <= std_logic_vector(conv_signed( 19 ,8));
130
 
131
 
132
-- Input stimulus
133
x_in <= count;
134
 
135
 
136
-- DUT
137
quad_func: quadratic_func
138
 
139
generic map ( fw => 6 )
140
 
141
port map (
142
 
143
  -- system clock
144
  clk      => clk,
145
 
146
  -- clock enable
147
  en       => '1',
148
 
149
  -- 8-bit signed coefficients
150
  coeff_a  => coeff_a,
151
  coeff_b  => coeff_b,
152
  coeff_c  => coeff_c,
153
 
154
  -- 8-bit signed input
155
  x_in     => x_in,
156
 
157
  -- 24-bit signed output
158
  y_out    => y_out );
159
 
160
 
161
-- Convert 24-bit output to integer
162
y_int <= conv_integer(unsigned(y_out));
163
 
164
 
165
-- Capture output data
166
grab_data: process (clk)
167
 
168
  file     terminal   : text open write_mode is "quadratic_func_out.txt";
169
  variable resoutline : line;
170
 
171
begin
172
 
173
  if clk'event and clk = '1' then
174
    if capture = '1' then
175
       write(resoutline, y_int);
176
       writeline(terminal, resoutline);
177
     end if;
178
   end if;
179
end process grab_data;
180
 
181
 
182
end behav;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.