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

Subversion Repositories rtf68ksys

[/] [rtf68ksys/] [trunk/] [rtl/] [verilog/] [PSGNoteGen.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 robfinch
/* ============================================================================
2
        (C) 2007  Robert Finch
3
        All rights reserved.
4
 
5
        PSGNoteGen.v
6
        Version 1.1
7
 
8
    This source code is available for evaluation and validation purposes
9
    only. This copyright statement and disclaimer must remain present in
10
    the file.
11
 
12
 
13
        NO WARRANTY.
14
    THIS Work, IS PROVIDEDED "AS IS" WITH NO WARRANTIES OF ANY KIND, WHETHER
15
    EXPRESS OR IMPLIED. The user must assume the entire risk of using the
16
    Work.
17
 
18
    IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
19
    INCIDENTAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES WHATSOEVER RELATING TO
20
    THE USE OF THIS WORK, OR YOUR RELATIONSHIP WITH THE AUTHOR.
21
 
22
    IN ADDITION, IN NO EVENT DOES THE AUTHOR AUTHORIZE YOU TO USE THE WORK
23
    IN APPLICATIONS OR SYSTEMS WHERE THE WORK'S FAILURE TO PERFORM CAN
24
    REASONABLY BE EXPECTED TO RESULT IN A SIGNIFICANT PHYSICAL INJURY, OR IN
25
    LOSS OF LIFE. ANY SUCH USE BY YOU IS ENTIRELY AT YOUR OWN RISK, AND YOU
26
    AGREE TO HOLD THE AUTHOR AND CONTRIBUTORS HARMLESS FROM ANY CLAIMS OR
27
    LOSSES RELATING TO SUCH UNAUTHORIZED USE.
28
 
29
 
30
        Note generator. 4/8 channels
31
 
32
        Spartan3
33
        Webpack 9.1i xc3s1000-4ft256
34
        337 LUTs / 224 slices / 98.445 MHz
35
============================================================================ */
36
 
37
module PSGNoteGen(rst, clk, cnt, br, bg, bgn, ack, test,
38
        vt0, vt1, vt2, vt3,
39
        freq0, freq1, freq2, freq3,
40
        pw0, pw1, pw2, pw3,
41
        acc0, acc1, acc2, acc3,
42
        wave, sync, ringmod, o
43
);
44
input rst;
45
input clk;
46
input [7:0] cnt;
47
input ack;
48
input [11:0] wave;
49
input [2:0] bgn;         // bus grant number
50
output [3:0] br;
51
input [3:0] bg;
52
input [3:0] test;
53
input [4:0] vt0, vt1, vt2, vt3;
54
input [15:0] freq0, freq1, freq2, freq3;
55
input [11:0] pw0, pw1, pw2, pw3;
56
input [3:0] sync;
57
input [3:0] ringmod;
58
//      input pxacc25;
59
output [23:0] acc0, acc1, acc2, acc3;    // 1.023MHz / 2^ 24 = 0.06Hz resolution
60
output [11:0] o;
61
 
62
wire [15:0] freqx;
63
wire [11:0] pwx;
64
reg [23:0] pxacc;
65
reg [23:0] acc;
66
reg [11:0] outputT;
67
reg [7:0] pxacc23x;
68
reg [7:0] ibr;
69
 
70
integer n;
71
 
72
reg [23:0] accx [3:0];
73
reg [11:0] pacc [3:0];
74
wire [1:0] sel = cnt[1:0];
75
reg [11:0] outputW [3:0];
76
reg [22:0] lfsr [3:0];
77
 
78
assign br[0] =   ibr[0] & ~bg[0];
79
assign br[1] =  ibr[1] & ~bg[1];
80
assign br[2] =  ibr[2] & ~bg[2];
81
assign br[3] =  ibr[3] & ~bg[3];
82
 
83
wire [4:0] vtx;
84
 
85
always @(sel)
86
        acc <= accx[sel];
87
 
88
 
89
mux4to1 #(16) u1 (.e(1'b1), .s(sel), .i0(freq0), .i1(freq1), .i2(freq2), .i3(freq3), .z(freqx) );
90
mux4to1 #(12) u2 (.e(1'b1), .s(sel), .i0(pw0), .i1(pw1), .i2(pw2), .i3(pw3), .z(pwx) );
91
mux4to1 #( 5) u3 (.e(1'b1), .s(sel), .i0(vt0), .i1(vt1), .i2(vt2), .i3(vt3), .z(vtx) );
92
 
93
 
94
wire [22:0] lfsrx = lfsr[sel];
95
wire [7:0] paccx = pacc[sel];
96
 
97
always @(sel)
98
        pxacc <= accx[sel-1];
99
wire pxacc23 = pxacc[23];
100
 
101
 
102
// for sync'ing
103
always @(posedge clk)
104
        if (cnt < 8'd4)
105
                pxacc23x[sel] <= pxacc23;
106
 
107
wire synca = ~pxacc23x[sel]&pxacc23&sync[sel];
108
 
109
 
110
// detect a transition on the wavetable address
111
// previous address not equal to current address
112
wire accTran = pacc[sel]!=acc[23:12];
113
 
114
// for wave table DMA
115
// capture the previous address
116
always @(posedge clk)
117
        if (rst) begin
118
                for (n = 0; n < 4; n = n + 1)
119
                        pacc[n] <= 0;
120
        end
121
        else if (cnt < 8'd4)
122
                pacc[sel] <= acc[23:12];
123
 
124
 
125
// capture wave input
126
// must be to who was granted the bus
127
always @(posedge clk)
128
        if (rst) begin
129
                for (n = 0; n < 8'd4; n = n + 1)
130
                        outputW[n] <= 0;
131
        end
132
        else if (ack)
133
                outputW[bgn] <= wave;
134
 
135
 
136
// bus request control
137
always @(posedge clk)
138
        if (rst) begin
139
                ibr <= 0;
140
        end
141
        else if (cnt < 8'd4) begin
142
                // check for an address transition and wave enabled
143
                // if so, request bus
144
                if (accTran & vtx[4])
145
                        ibr[sel] <= 1;
146
                // otherwise
147
                // turn off bus request for whoever it was granted
148
                else
149
                        ibr[bgn] <= 0;
150
        end
151
 
152
 
153
// Noise generator
154
always @(posedge clk)
155
        if (cnt < 8'd4 && paccx[2] != acc[18])
156
                lfsr[sel] <= {lfsrx[21:0],~(lfsrx[22]^lfsrx[17])};
157
 
158
 
159
// Harmonic synthesizer
160
always @(posedge clk)
161
        if (rst) begin
162
                for (n = 0; n < 4; n = n + 1)
163
                        accx[n] <= 0;
164
        end
165
        else if (cnt < 8'd4) begin
166
                if (~test[sel]) begin
167
                        if (synca)
168
                                accx[sel] <= 0;
169
                        else
170
                                accx[sel] <= acc + freqx;
171
                end
172
                else
173
                        accx[sel] <= 0;
174
        end
175
 
176
 
177
// Triangle wave, ring modulation
178
wire msb = ringmod[sel] ? acc[23]^pxacc23 : acc[23];
179
always @(acc or msb)
180
        outputT <= msb ? ~acc[22:11] : acc[22:11];
181
 
182
// Other waveforms, ho-hum
183
wire [11:0] outputP = {12{acc[23:12] < pwx}};
184
wire [11:0] outputS = acc[23:12];
185
wire [11:0] outputN = lfsrx[11:0];
186
 
187
wire [11:0] out;
188
PSGNoteOutMux #(12) u4 (.s(vtx), .a(outputT), .b(outputS), .c(outputP), .d(outputN), .e(outputW[sel]), .o(out) );
189
assign o = out;
190
 
191
assign acc0 = accx[0];
192
assign acc1 = accx[1];
193
assign acc2 = accx[2];
194
assign acc3 = accx[3];
195
 
196
endmodule
197
 

powered by: WebSVN 2.1.0

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