-
Notifications
You must be signed in to change notification settings - Fork 9
/
ym3438_pg.v
394 lines (321 loc) · 7.33 KB
/
ym3438_pg.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
module ym3438_pg
(
input MCLK,
input c1,
input c2,
input [11:0] fnum,
input [2:0] block,
input dt_sign_1,
input dt_sign_2,
input [4:0] dt_value,
input [3:0] multi,
input pg_reset,
input [7:0] reg_21,
input fsm_sel2,
output [9:0] pg_out,
output pg_dbg_o
);
wire [2:0] block_sr_o;
ym_sr_bit_array #(.DATA_WIDTH(3)) block_sr
(
.MCLK(MCLK),
.c1(c1),
.c2(c2),
.data_in(block),
.data_out(block_sr_o)
);
wire [2:0] block_l_o;
ym_dlatch_1 #(.DATA_WIDTH(3)) block_l
(
.MCLK(MCLK),
.c1(c1),
.inp(block_sr_o),
.val(block_l_o),
.nval()
);
wire block_sh0 = block_l_o[1:0] == 2'h0;
wire block_sh1 = block_l_o[1:0] == 2'h1;
wire block_sh2 = block_l_o[1:0] == 2'h2;
wire block_sh3 = block_l_o[1:0] == 2'h3;
wire [12:0] freq1 = { fnum, 1'h0 };
wire [15:0] freq2 = ({16{block_sh0}} & { 3'h0, freq1 })
| ({16{block_sh1}} & { 2'h0, freq1, 1'h0 })
| ({16{block_sh2}} & { 1'h0, freq1, 2'h0 })
| ({16{block_sh3}} & { freq1, 3'h0 });
wire [16:0] freq3 = ~(
({17{~block_l_o[2]}} & { 4'h0, freq2[15:3] })
| ({17{block_l_o[2]}} & { freq2, 1'h0 })
);
wire [16:0] freq_l_o;
ym_dlatch_2 #(.DATA_WIDTH(17)) freq_l
(
.MCLK(MCLK),
.c2(c2),
.inp(freq3),
.val(),
.nval(freq_l_o)
);
wire [4:0] dt_value_sr_o;
ym_sr_bit_array #(.DATA_WIDTH(5)) dt_value_sr
(
.MCLK(MCLK),
.c1(c1),
.c2(c2),
.data_in(dt_value ^ {5{dt_sign_1}}),
.data_out(dt_value_sr_o)
);
wire [16:0] dt_add = { {12{dt_sign_2}}, dt_value_sr_o };
wire [16:0] freq_dt = freq_l_o + dt_add + dt_sign_2;
wire [16:0] freq_l2_o;
ym_dlatch_1 #(.DATA_WIDTH(17)) freq_l2
(
.MCLK(MCLK),
.c1(c1),
.inp(freq_dt),
.val(freq_l2_o),
.nval()
);
wire [15:0] multi_sel;
genvar i;
generate
for (i = 0; i < 16; i = i + 1)
begin : l1
assign multi_sel[i] = multi == i;
end
endgenerate
wire multi_sel_1_l_o;
ym_dlatch_1 multi_sel_1_l
(
.MCLK(MCLK),
.c1(c1),
.inp(multi_sel[14] | multi_sel[15]),
.val(multi_sel_1_l_o),
.nval()
);
wire multi_sel_2_l_o;
ym_dlatch_1 multi_sel_2_l
(
.MCLK(MCLK),
.c1(c1),
.inp(multi_sel[8] | multi_sel[9] | multi_sel[10] | multi_sel[11] | multi_sel[12] | multi_sel[13]),
.val(multi_sel_2_l_o),
.nval()
);
wire multi_sel_3_l_o;
ym_dlatch_1 multi_sel_3_l
(
.MCLK(MCLK),
.c1(c1),
.inp(multi_sel[4] | multi_sel[5] | multi_sel[6] | multi_sel[7]),
.val(multi_sel_3_l_o),
.nval()
);
wire multi_sel_4_l_o;
ym_dlatch_1 multi_sel_4_l
(
.MCLK(MCLK),
.c1(c1),
.inp(multi_sel[1] | multi_sel[3] | multi_sel[5] | multi_sel[7] | multi_sel[9] | multi_sel[11] | multi_sel[13]),
.val(multi_sel_4_l_o),
.nval()
);
wire multi_sel_5_l_o;
ym_dlatch_1 multi_sel_5_l
(
.MCLK(MCLK),
.c1(c1),
.inp(multi_sel[12] | multi_sel[13]),
.val(multi_sel_5_l_o),
.nval()
);
wire multi_sel_6_l_o;
ym_dlatch_1 multi_sel_6_l
(
.MCLK(MCLK),
.c1(c1),
.inp(multi_sel[14]),
.val(multi_sel_6_l_o),
.nval()
);
wire multi_sel_7_l_o;
ym_dlatch_1 multi_sel_7_l
(
.MCLK(MCLK),
.c1(c1),
.inp(multi_sel[2] | multi_sel[3] | multi_sel[6] | multi_sel[7] | multi_sel[10] | multi_sel[11]),
.val(multi_sel_7_l_o),
.nval()
);
wire multi_sel_8_l_o;
ym_dlatch_1 multi_sel_8_l
(
.MCLK(MCLK),
.c1(c1),
.inp(multi_sel[15]),
.val(multi_sel_8_l_o),
.nval()
);
wire multi_sel_9_l_o;
ym_dlatch_1 multi_sel_9_l
(
.MCLK(MCLK),
.c1(c1),
.inp(multi_sel[0]),
.val(multi_sel_9_l_o),
.nval()
);
wire [19:0] freq_multi_add1 = ~(
({20{multi_sel_5_l_o}} & { 1'h0, freq_l2_o, 2'h0 })
| ({20{multi_sel_6_l_o}} & { 2'h3, ~freq_l2_o, 1'h1 })
| ({20{multi_sel_7_l_o}} & { 2'h0, freq_l2_o, 1'h0 })
| ({20{multi_sel_8_l_o}} & { 3'h7, ~freq_l2_o })
| ({20{multi_sel_9_l_o}} & { 4'h0, freq_l2_o[16:1] })
);
wire [17:0] freq_multi_add2 = ~(
({18{multi_sel_3_l_o}} & { 1'h0, freq_l2_o })
| ({18{multi_sel_2_l_o}} & { freq_l2_o, 1'h0 })
| ({18{multi_sel_1_l_o}} & { freq_l2_o[15:0], 2'h0 })
);
wire [19:0] freq_multi_add1_l_o;
ym_dlatch_2 #(.DATA_WIDTH(20)) freq_multi_add1_l
(
.MCLK(MCLK),
.c2(c2),
.inp(freq_multi_add1),
.val(),
.nval(freq_multi_add1_l_o)
);
wire [17:0] freq_multi_add2_l_o;
ym_dlatch_2 #(.DATA_WIDTH(18)) freq_multi_add2_l
(
.MCLK(MCLK),
.c2(c2),
.inp(freq_multi_add2),
.val(),
.nval(freq_multi_add2_l_o)
);
wire multi_c_in;
ym_dlatch_2 multi_c_in_l
(
.MCLK(MCLK),
.c2(c2),
.inp(~(multi_sel_6_l_o | multi_sel_8_l_o)),
.val(),
.nval(multi_c_in)
);
wire [19:0] freq_multi_sum = freq_multi_add1_l_o + { freq_multi_add2_l_o, 2'h0 } + multi_c_in;
wire [19:0] freq_multi_sum_sr_o;
ym_sr_bit_array #(.DATA_WIDTH(20)) freq_multi_sum_sr
(
.MCLK(MCLK),
.c1(c1),
.c2(c2),
.data_in(freq_multi_sum),
.data_out(freq_multi_sum_sr_o)
);
wire [16:0] freq_multi_add3_l_o;
ym_dlatch_2 #(.DATA_WIDTH(17)) freq_multi_add3_l
(
.MCLK(MCLK),
.c2(c2),
.inp(freq_l2_o),
.val(freq_multi_add3_l_o),
.nval()
);
wire [19:0] freq_multi_add3_sr_o;
ym_sr_bit_array #(.DATA_WIDTH(20)) freq_multi_add3_sr
(
.MCLK(MCLK),
.c1(c1),
.c2(c2),
.data_in({3'h0, freq_multi_add3_l_o}),
.data_out(freq_multi_add3_sr_o)
);
wire multi_sel_4_l2_o;
ym_dlatch_2 multi_sel_4_l2
(
.MCLK(MCLK),
.c2(c2),
.inp(multi_sel_4_l_o),
.val(multi_sel_4_l2_o),
.nval()
);
wire multi_sel_4_sr_o;
ym_sr_bit multi_sel_4_sr
(
.MCLK(MCLK),
.c1(c1),
.c2(c2),
.bit_in(multi_sel_4_l2_o),
.sr_out(multi_sel_4_sr_o)
);
wire multi_sel_4_sr_o_r = multi_sel_4_sr_o & pg_reset;
wire [19:0] freq_multi_add3_l2_o;
ym_dlatch_1 #(.DATA_WIDTH(20)) freq_multi_add3_l2
(
.MCLK(MCLK),
.c1(c1),
.inp(~(multi_sel_4_sr_o_r ? freq_multi_add3_sr_o : 20'h00000)),
.val(),
.nval(freq_multi_add3_l2_o)
);
wire [19:0] freq_multi_sum_l_o;
ym_dlatch_1 #(.DATA_WIDTH(20)) freq_multi_sum_l
(
.MCLK(MCLK),
.c1(c1),
.inp(~(pg_reset ? freq_multi_sum_sr_o : 20'h00000)),
.val(),
.nval(freq_multi_sum_l_o)
);
wire [19:0] freq_inc = freq_multi_sum_l_o + freq_multi_add3_l2_o;
wire [19:0] freq_inc_l_o;
ym_dlatch_2 #(.DATA_WIDTH(20)) freq_inc_l
(
.MCLK(MCLK),
.c2(c2),
.inp(freq_inc),
.val(freq_inc_l_o),
.nval()
);
wire pg_reset_sr_o;
ym_sr_bit pg_reset_sr
(
.MCLK(MCLK),
.c1(c1),
.c2(c2),
.bit_in(pg_reset),
.sr_out(pg_reset_sr_o)
);
wire pg_reset2 = pg_reset_sr_o & ~reg_21[3];
wire [19:0] o_phase;
wire [19:0] phase = (pg_reset2 ? o_phase : 20'h00000) + freq_inc_l_o;
wire [19:0] pg_values_o;
ym_sr_bit_array #(.DATA_WIDTH(20), .SR_LENGTH(20)) pg_values
(
.MCLK(MCLK),
.c1(c1),
.c2(c2),
.data_in(phase),
.data_out(pg_values_o)
);
ym_sr_bit_array #(.DATA_WIDTH(20), .SR_LENGTH(4)) pg_values2
(
.MCLK(MCLK),
.c1(c1),
.c2(c2),
.data_in(pg_values_o),
.data_out(o_phase)
);
assign pg_out = pg_values_o[19:10];
ym_dbg_read #(.DATA_WIDTH(10)) dbg_read
(
.MCLK(MCLK),
.c1(c1),
.c2(c2),
.prev(0),
.load(fsm_sel2),
.load_val(o_phase[9:0]),
.next(pg_dbg_o)
);
endmodule