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

Subversion Repositories fir_wishbone

[/] [fir_wishbone/] [trunk/] [tester/] [tb_fir.vhdl] - Blame information for rev 5

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

Line No. Rev Author Line
1 5 daniel.kho
/* Synthesisable testbench/BiST for FIR Filter design.
2
 
3
        Copyright© 2012 Tauhop Solutions. All rights reserved.
4
        This core is free hardware design; you can redistribute it and/or
5
        modify it under the terms of the GNU Library General Public
6
        License as published by the Free Software Foundation; either
7
        version 2 of the License, or (at your option) any later version.
8
 
9
        This library is distributed in the hope that it will be useful,
10
        but WITHOUT ANY WARRANTY; without even the implied warranty of
11
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
        Library General Public License for more details.
13
 
14
        You should have received a copy of the GNU Library General Public
15
        License along with this library; if not, write to the
16
        Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
        Boston, MA 02111-1307, USA.
18
 
19
        License: LGPL.
20
 
21
        @dependencies:
22
        @designer(s):
23
                Daniel C.K. Kho [daniel.kho@gmail.com] | [daniel.kho@tauhop.com] | [daniel.kho@sophicdesign.com.my];
24
                Tan Hooi Jing [hooijingtan@gmail.com]
25
        @info:
26
        Revision History: @see Mercurial log for full list of changes.
27
 
28
        This notice and disclaimer must be retained as part of this text at all times.
29
*/
30 2 daniel.kho
library ieee;
31
use ieee.std_logic_1164.all;
32
use ieee.numeric_std.all;
33
 
34 5 daniel.kho
entity tb_fir is generic(order:positive:=30; width:positive:=16);
35
        port(
36
--              clk:in std_ulogic:='0';
37
--              nRst:in std_ulogic:='0';
38
                --u:in signed(16-1 downto 0);
39
                y:out signed(16-1 downto 0)
40
        );
41
end entity tb_fir;
42 2 daniel.kho
 
43 5 daniel.kho
architecture rtl of tb_fir is
44
        signal reset:std_ulogic:='0';
45
        signal u:signed(16-1 downto 0);
46
        signal trig:std_logic;
47
 
48
        /* synthesis translate_off */
49
        signal clk:std_ulogic:='0';
50
        signal nRst:std_ulogic:='1';
51
        /* synthesis translate_on */
52
 
53
        signal count:unsigned(8 downto 0);
54
        signal pwrUpCnt:unsigned(3 downto 0):=(others=>'0');
55
 
56
        /* on-chip debugger */
57
        signal dbgSignals:std_ulogic_vector(127 downto 0):=(others=>'0');
58
 
59
 
60
        /* Explicitly define all multiplications with the "*" operator to use dedicated DSP hardware multipliers. */
61
        attribute multstyle:string; attribute multstyle of rtl:architecture is "dsp";   --altera:
62
--      attribute mult_style:string; attribute mult_style of fir:entity is "block";             --xilinx:
63
 
64
begin
65
        /* synthesis translate_off*/
66
        clk<=not clk after 10 ns;
67
        /* synthesis translate_on*/
68
 
69
        process(pwrUpCnt,nRst) is begin
70
                if pwrUpCnt<10 or nRst='0' then reset<='1';
71
                else reset<='0';
72
                end if;
73
        end process;
74
 
75
        process(reset,clk) is begin
76
                if reset='1' then count<=(others =>'0');
77 2 daniel.kho
                elsif rising_edge(clk) then
78 5 daniel.kho
                        if count<300 then count<=count+1; end if;
79 2 daniel.kho
                end if;
80 5 daniel.kho
        end process;
81
 
82
        process(nRst,clk) is begin
83
                if nRst='0' then pwrUpCnt<=(others =>'0');
84
                elsif rising_edge(clk) then
85 2 daniel.kho
                        if pwrUpCnt<10 then pwrUpCnt<=pwrUpCnt+1; end if;
86
                end if;
87 5 daniel.kho
        end process;
88
 
89
        /* Impulse generator for impulse response measurement. */
90
        u <= (0=>'1', others=>'0') when count=1 else (others=>'0');
91
 
92
 
93
        filter: entity work.fir(rtl)
94
                generic map(order=>order, width=>width)
95
                port map(
96
                        reset=>reset,
97
                        clk=>clk,
98
 
99
                        /* Filter ports. */
100
                        u=>u,
101
                        y=>y
102
        );
103
 
104
 
105
        /* Simulation only. */
106
        /* synthesis translate_off */
107
        reporter: process(clk) is begin
108
                if rising_edge(clk) then
109
                        /* (u,y) pairs will be exported to CSV and Matlab for plotting.
110
                                Results are then correlated to digital simulations and Matlab
111
                                simulations of the filter.
112
                        */
113
                        report ";" & integer'image(to_integer(u)) & ";"
114
                                & integer'image(to_integer(y));
115
                end if;
116
        end process reporter;
117
 
118
        process is begin
119
                assert now<5 us report "simulation stopped." severity failure;
120
                wait;
121
        end process;
122
        /* synthesis translate_on */
123
 
124
 
125
        /* Hardware debugger (SignalTap II embedded logic analyser). */
126
 
127
        trig<='1' when count<300 else '0';               -- Stop SignalTap Triggering after 300 counts, Total data=280
128
 
129
        /* SignalTap debugger. */
130
        dbgSignals(width-1 downto 0)<=std_ulogic_vector(u);                                              -- u:16bits
131
        dbgSignals(width*2-1  downto width)<=std_ulogic_vector(y);                              -- y:32bits                                             
132
        dbgSignals(8+width*2 downto width*2)<=std_ulogic_vector(count);         --9bits (300<512)
133
 
134
/*      debugger: entity work.stp(syn) port map(
135
                acq_clk=>clk,
136
                acq_data_in=>std_logic_vector(dbgSignals),              -- Type conversion: std_ulogic_vector --> std_logic_vector
137
                acq_trigger_in=>"1",
138
                trigger_in=>trig
139
        );
140
*/
141
end architecture rtl;

powered by: WebSVN 2.1.0

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