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

Subversion Repositories fir_wishbone

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 daniel.kho
/* FIR Filter.
2
 
3 3 daniel.kho
        Copyright© 2012 Tauhop Solutions. All rights reserved.
4 2 daniel.kho
        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 3 daniel.kho
        @designer(s):
23 12 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 2 daniel.kho
        @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 3 daniel.kho
/* Filter order = number of unit delays. */
35 12 daniel.kho
entity fir is generic(order:positive:=30);      --; width:positive:=16);
36 2 daniel.kho
        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 12 daniel.kho
                --u:in signed(width-1 downto 0):=(others=>'0');
42
                --y:buffer signed(width-1 downto 0)
43
                u:in signed;
44
                y:buffer signed
45 2 daniel.kho
        );
46
end entity fir;
47
 
48
architecture rtl of fir is
49
        /* Memory I/Os: */
50 12 daniel.kho
--      signal q:signed(width-1 downto 0):=(others=>'0');
51
        signal q:signed(u'range);
52
 
53 3 daniel.kho
        --signal rst: std_ulogic;
54
        --signal pwrUpCnt: unsigned(8 downto 0):=(others=>'0');
55
        --signal trig:std_logic;
56 2 daniel.kho
 
57 3 daniel.kho
        --signal c:unsigned(positive(ceil(log2(real(order))))-1 downto 0);      --counter:5bits
58 2 daniel.kho
 
59 3 daniel.kho
 
60
        -- debugger
61
        --signal dbgSignals:std_ulogic_vector(127 downto 0);
62
 
63
 
64
        /* Memories: */
65 2 daniel.kho
        /* TODO: Change these arrays to internal process variables instead. */
66
        /* Read-only Memory (ROM). */
67 12 daniel.kho
--      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.
68
--      type signedx2_vector is array(natural range<>) of signed(width*2-1 downto 0);
69 2 daniel.kho
 
70 12 daniel.kho
        /* 32-by-N matrix array structure (as in RAM). Similar to integer_vector, difference being base vector is 32-bit unsigned. */
71
        type signed_vector is array(natural range <>) of signed(u'range);
72
        type signedx2_vector is array(natural range<>) of signed(u'length*2-1 downto 0);
73
 
74 3 daniel.kho
        /* Filter length = number of taps = number of coefficients = order + 1 */
75
        constant b:signed_vector(0 to order):=(
76 2 daniel.kho
                x"FFEF",
77
                x"FFED",
78
                x"FFE8",
79
                x"FFE6",
80
                x"FFEB",
81
                x"0000",
82
                x"002C",
83
                x"0075",
84
                x"00DC",
85
                x"015F",
86
                x"01F4",
87
                x"028E",
88
                x"031F",
89
                x"0394",
90
                x"03E1",
91
                x"03FC",
92
                x"03E1",
93
                x"0394",
94
                x"031F",
95
                x"028E",
96
                x"01F4",
97
                x"015F",
98
                x"00DC",
99
                x"0075",
100
                x"002C",
101
                x"0000",
102
                x"FFEB",
103
                x"FFE6",
104
                x"FFE8",
105
                x"FFED",
106
                x"FFEF"
107
        );
108
 
109 3 daniel.kho
        /*Memory Addressing*/
110
--      signal c:natural range b'range;
111
 
112 2 daniel.kho
        /* Pipes and delay chains. */
113 12 daniel.kho
        signal y0:signed(u'length*2-1 downto 0);
114 3 daniel.kho
        signal u_pipe:signed_vector(b'range):=(others=>(others=>'0'));
115
        signal y_pipe:signedx2_vector(b'range):=(others=>(others=>'0'));
116 2 daniel.kho
 
117
 
118
        /* Counters. */
119
--      signal cnt:integer range 31 downto -1;                  -- symbol / bit counter. Counts the bits transmitted on the serial line.
120
 
121
--      /* memory pointers (acts as the read/write address for the synchronous RAM). */
122
--      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).
123
        /* [end]: Memories. */
124
 
125
        /* Signal preservations. */
126
--      attribute keep:boolean;
127
 
128
        /* Explicitly define all multiplications with the "*" operator to use dedicated DSP hardware multipliers. */
129 3 daniel.kho
        attribute multstyle:string; attribute multstyle of rtl:architecture is "dsp";   --altera
130
--      attribute mult_style:string; attribute mult_style of fir:entity is "block";             --xilinx
131 2 daniel.kho
 
132
begin
133 3 daniel.kho
--      /* 1-Dimensional Synchronous ROM. */
134 2 daniel.kho
--      readCoeffs: process(clk) is begin
135
--              if rising_edge(clk) then
136
--                      if reset='1' then q<=(others=>'0');
137
--                      else q<=b(c);
138
--                      end if;
139
--              end if;
140
--      end process readCoeffs;
141
 
142
        u_pipe(0)<=u;
143
        u_dlyChain: for i in 1 to u_pipe'high generate
144
                delayChain: process(clk) is begin
145
                        if rising_edge(clk) then u_pipe(i)<=u_pipe(i-1); end if;
146
                end process delayChain;
147
        end generate u_dlyChain;
148
 
149
        y_pipe(0)<=b(0)*u;
150
        y_dlyChain: for i in 1 to y_pipe'high generate
151 3 daniel.kho
                y_pipe(i)<=b(i)*u_pipe(i) + y_pipe(i-1);
152 2 daniel.kho
        end generate y_dlyChain;
153
 
154 3 daniel.kho
        y0<=y_pipe(y_pipe'high) when reset='0' else (others=>'0');
155 12 daniel.kho
        y<=y0(y'range);
156 2 daniel.kho
end architecture rtl;

powered by: WebSVN 2.1.0

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