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

Subversion Repositories fir_wishbone

[/] [fir_wishbone/] [trunk/] [hw/] [quartus-synthesis/] [fir.vhdl] - Blame information for rev 17

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 daniel.kho
/* FIR Filter.
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 9 daniel.kho
                Daniel C.K. Kho [daniel.kho@gmail.com] | [daniel.kho@tauhop.com];
24 3 daniel.kho
                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
library ieee;
31
use ieee.std_logic_1164.all;
32
use ieee.numeric_std.all;
33
 
34
/* Filter order = number of unit delays. */
35
entity fir is generic(order:positive:=30; width:positive:=16);
36
        port(
37
                reset:in std_ulogic;                    -- asserting reset will start protocol sequence transmission. To restart the re-transmission of the sequence, re-assert this reset signal, and the whole SPI sequence will be re-transmitted again.
38
                clk:in std_ulogic:='0';
39
 
40
                /* Filter ports. */
41
                u:in signed(width-1 downto 0):=(others=>'0');
42
                y:buffer signed(width-1 downto 0)
43
        );
44
end entity fir;
45
 
46
architecture rtl of fir is
47
        /* Memory I/Os: */
48
        signal q:signed(width-1 downto 0):=(others=>'0');
49
        --signal rst: std_ulogic;
50
        --signal pwrUpCnt: unsigned(8 downto 0):=(others=>'0');
51
        --signal trig:std_logic;
52
 
53
        --signal c:unsigned(positive(ceil(log2(real(order))))-1 downto 0);      --counter:5bits
54
 
55
 
56
        -- debugger
57
        --signal dbgSignals:std_ulogic_vector(127 downto 0);
58
 
59
 
60
        /* Memories: */
61
        /* TODO: Change these arrays to internal process variables instead. */
62
        /* Read-only Memory (ROM). */
63
        type signed_vector is array(natural range <>) of signed(width-1 downto 0);               -- 32-by-N matrix array structure (as in RAM). Similar to integer_vector, difference being base vector is 32-bit unsigned.
64
        type signedx2_vector is array(natural range<>) of signed(width*2-1 downto 0);
65
 
66
        /* Filter length = number of taps = number of coefficients = order + 1 */
67
        constant b:signed_vector(0 to order):=(
68
                x"FFEF",
69
                x"FFED",
70
                x"FFE8",
71
                x"FFE6",
72
                x"FFEB",
73
                x"0000",
74
                x"002C",
75
                x"0075",
76
                x"00DC",
77
                x"015F",
78
                x"01F4",
79
                x"028E",
80
                x"031F",
81
                x"0394",
82
                x"03E1",
83
                x"03FC",
84
                x"03E1",
85
                x"0394",
86
                x"031F",
87
                x"028E",
88
                x"01F4",
89
                x"015F",
90
                x"00DC",
91
                x"0075",
92
                x"002C",
93
                x"0000",
94
                x"FFEB",
95
                x"FFE6",
96
                x"FFE8",
97
                x"FFED",
98
                x"FFEF"
99
        );
100
 
101
        /*Memory Addressing*/
102
--      signal c:natural range b'range;
103
 
104
        /* Pipes and delay chains. */
105
        signal y0:signed(width*2-1 downto 0);
106
        signal u_pipe:signed_vector(b'range):=(others=>(others=>'0'));
107
        signal y_pipe:signedx2_vector(b'range):=(others=>(others=>'0'));
108
 
109
 
110
        /* Counters. */
111
--      signal cnt:integer range 31 downto -1;                  -- symbol / bit counter. Counts the bits transmitted on the serial line.
112
 
113
--      /* memory pointers (acts as the read/write address for the synchronous RAM). */
114
--      signal instrPtr:natural range rfbSequencesCache'range;          --RFB sequence memory addressing. Acts as instruction pointer. Points to the current SPI instruction to be transmitted on MOSI. Size is one more than the instruction cache size, so it points past the last valid address (used for counting).
115
        /* [end]: Memories. */
116
 
117
        /* Signal preservations. */
118
--      attribute keep:boolean;
119
 
120
        /* Explicitly define all multiplications with the "*" operator to use dedicated DSP hardware multipliers. */
121
        attribute multstyle:string; attribute multstyle of rtl:architecture is "dsp";   --altera
122
--      attribute mult_style:string; attribute mult_style of fir:entity is "block";             --xilinx
123
 
124
begin
125
--      /* 1-Dimensional Synchronous ROM. */
126
--      readCoeffs: process(clk) is begin
127
--              if rising_edge(clk) then
128
--                      if reset='1' then q<=(others=>'0');
129
--                      else q<=b(c);
130
--                      end if;
131
--              end if;
132
--      end process readCoeffs;
133
 
134
        u_pipe(0)<=u;
135
        u_dlyChain: for i in 1 to u_pipe'high generate
136
                delayChain: process(clk) is begin
137
                        if rising_edge(clk) then u_pipe(i)<=u_pipe(i-1); end if;
138
                end process delayChain;
139
        end generate u_dlyChain;
140
 
141
        y_pipe(0)<=b(0)*u;
142
        y_dlyChain: for i in 1 to y_pipe'high generate
143
                y_pipe(i)<=b(i)*u_pipe(i) + y_pipe(i-1);
144
        end generate y_dlyChain;
145
 
146
        y0<=y_pipe(y_pipe'high) when reset='0' else (others=>'0');
147
        y<=y0(width-1 downto 0);
148
end architecture rtl;

powered by: WebSVN 2.1.0

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