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

Subversion Repositories psg16

[/] [psg16/] [trunk/] [rtl/] [verilog/] [PSGFilter2.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 robfinch
`timescale 1ns / 1ps
2
`timescale 1ns / 1ps
3
// ============================================================================
4
//        __
5
//   \\__/ o\    (C) 2007-2017  Robert Finch, Waterloo
6
//    \  __ /    All rights reserved.
7
//     \/_//     robfinch<remove>@finitron.ca
8
//       ||
9
//
10
// PSGFilter2.v
11
//
12
// This source file is free software: you can redistribute it and/or modify 
13
// it under the terms of the GNU Lesser General Public License as published 
14
// by the Free Software Foundation, either version 3 of the License, or     
15
// (at your option) any later version.                                      
16
//                                                                          
17
// This source file is distributed in the hope that it will be useful,      
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
20
// GNU General Public License for more details.                             
21
//                                                                          
22
// You should have received a copy of the GNU General Public License        
23
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
24
//                                                                          
25
//        16-tap digital filter
26
//
27
//    Currently this filter is only partially tested. The author believes that
28
//    the approach used is valid however.
29
//      The author opted to include the filter because it is part of the design,
30
//      and even this untested component can provide an idea of the resource
31
//      requirements, and device capabilities.
32
//              This is a "how one might approach the problem" example, at least
33
//      until the author is sure the filter is working correctly.
34
//        
35
//      Time division multiplexing is used to implement this filter in order to
36
//      reduce the resource requirement. This should be okay because it is being
37
//      used to filter audio signals. The effective operating frequency of the
38
//      filter depends on the 'cnt' supplied (eg 1MHz)
39
//
40
//============================================================================
41
//
42
module PSGFilter2(rst, clk, cnt, wr, adr, din, i, o);
43
parameter pTaps = 16;
44
input rst;
45
input clk;
46
input [3:0] cnt;
47
input wr;
48
input [3:0] adr;
49
input [12:0] din;
50
input [21:0] i;
51
output [21:0] o;
52
reg [37:0] o;
53
 
54
reg [37:0] acc;                 // accumulator
55
reg [21:0] tap [0:pTaps-1];     // tap registers
56
integer n;
57
 
58
// coefficient memory
59
reg [11:0] coeff [0:pTaps-1];   // magnitude of coefficient
60
reg [pTaps-1:0] sgn;            // sign of coefficient
61
 
62
initial begin
63
        for (n = 0; n < pTaps; n = n + 1)
64
        begin
65
                coeff[n] <= 0;
66
                sgn[n] <= 0;
67
        end
68
end
69
 
70
// update coefficient memory
71
always @(posedge clk)
72
    if (wr) begin
73
        coeff[adr] <= din[11:0];
74
        sgn[adr] <= din[12];
75
    end
76
 
77
// shift taps
78
// Note: infer a dsr by NOT resetting the registers
79
always @(posedge clk)
80
    if (cnt==4'd0) begin
81
        tap[0] <= i;
82
        for (n = 1; n < pTaps; n = n + 1)
83
                tap[n] <= tap[n-1];
84
    end
85
 
86
wire [33:0] mult = coeff[cnt[3:0]] * tap[cnt[3:0]];
87
 
88
always @(posedge clk)
89
    if (rst)
90
        acc <= 0;
91
    else if (cnt==4'd0)
92
        acc <= sgn[cnt[3:0]] ? 0 - mult : 0 + mult;
93
    else
94
        acc <= sgn[cnt[3:0]] ? acc - mult : acc + mult;
95
 
96
always @(posedge clk)
97
    if (rst)
98
        o <= 0;
99
    else if (cnt==4'd0)
100
        o <= acc;
101
 
102
endmodule

powered by: WebSVN 2.1.0

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