-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_ipod_solution.v.bak
677 lines (547 loc) · 19.5 KB
/
simple_ipod_solution.v.bak
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
`default_nettype none
module simple_ipod_solution(
//////////// CLOCK //////////
CLOCK_50,
//////////// LED //////////
LEDR,
//////////// KEY //////////
KEY,
//////////// SW //////////
SW,
//////////// SEG7 //////////
HEX0,
HEX1,
HEX2,
HEX3,
HEX4,
HEX5,
//////////// Audio //////////
AUD_ADCDAT,
AUD_ADCLRCK,
AUD_BCLK,
AUD_DACDAT,
AUD_DACLRCK,
AUD_XCK,
//////////// I2C for Audio //////////
FPGA_I2C_SCLK,
FPGA_I2C_SDAT,
//////// PS2 //////////
PS2_CLK,
PS2_DAT,
//////// SDRAM //////////
DRAM_ADDR,
DRAM_BA,
DRAM_CAS_N,
DRAM_CKE,
DRAM_CLK,
DRAM_CS_N,
DRAM_DQ,
DRAM_LDQM,
DRAM_UDQM,
DRAM_RAS_N,
DRAM_WE_N,
//////// GPIO //////////
GPIO_0,
GPIO_1
);
`define zero_pad(width,signal) {{((width)-$size(signal)){1'b0}},(signal)}
//=======================================================
// PORT declarations
//=======================================================
//////////// CLOCK //////////
input CLOCK_50;
//////////// LED //////////
output [9:0] LEDR;
//////////// KEY //////////
input [3:0] KEY;
//////////// SW //////////
input [9:0] SW;
//////////// SEG7 //////////
output [6:0] HEX0;
output [6:0] HEX1;
output [6:0] HEX2;
output [6:0] HEX3;
output [6:0] HEX4;
output [6:0] HEX5;
//////////// Audio //////////
input AUD_ADCDAT;
inout AUD_ADCLRCK;
inout AUD_BCLK;
output AUD_DACDAT;
inout AUD_DACLRCK;
output AUD_XCK;
//////////// I2C for Audio //////////
output FPGA_I2C_SCLK;
inout FPGA_I2C_SDAT;
//////////// PS2 //////////
inout PS2_CLK;
inout PS2_DAT;
//////////// GPIO //////////
inout [35:0] GPIO_0;
inout [35:0] GPIO_1;
//////////// SDRAM //////////
output [12:0] DRAM_ADDR;
output [1:0] DRAM_BA;
output DRAM_CAS_N;
output DRAM_CKE;
output DRAM_CLK;
output DRAM_CS_N;
inout [15:0] DRAM_DQ;
output DRAM_LDQM;
output DRAM_UDQM;
output DRAM_RAS_N;
output DRAM_WE_N;
//=======================================================
// REG/WIRE declarations
//=======================================================
// Input and output declarations
logic CLK_50M;
logic [7:0] LED;
assign CLK_50M = CLOCK_50;
assign LEDR[7:0] = LED[7:0];
//Character definitions
//numbers
parameter character_0 =8'h30;
parameter character_1 =8'h31;
parameter character_2 =8'h32;
parameter character_3 =8'h33;
parameter character_4 =8'h34;
parameter character_5 =8'h35;
parameter character_6 =8'h36;
parameter character_7 =8'h37;
parameter character_8 =8'h38;
parameter character_9 =8'h39;
//Uppercase Letters
parameter character_A =8'h41;
parameter character_B =8'h42;
parameter character_C =8'h43;
parameter character_D =8'h44;
parameter character_E =8'h45;
parameter character_F =8'h46;
parameter character_G =8'h47;
parameter character_H =8'h48;
parameter character_I =8'h49;
parameter character_J =8'h4A;
parameter character_K =8'h4B;
parameter character_L =8'h4C;
parameter character_M =8'h4D;
parameter character_N =8'h4E;
parameter character_O =8'h4F;
parameter character_P =8'h50;
parameter character_Q =8'h51;
parameter character_R =8'h52;
parameter character_S =8'h53;
parameter character_T =8'h54;
parameter character_U =8'h55;
parameter character_V =8'h56;
parameter character_W =8'h57;
parameter character_X =8'h58;
parameter character_Y =8'h59;
parameter character_Z =8'h5A;
//Lowercase Letters
parameter character_lowercase_a= 8'h61;
parameter character_lowercase_b= 8'h62;
parameter character_lowercase_c= 8'h63;
parameter character_lowercase_d= 8'h64;
parameter character_lowercase_e= 8'h65;
parameter character_lowercase_f= 8'h66;
parameter character_lowercase_g= 8'h67;
parameter character_lowercase_h= 8'h68;
parameter character_lowercase_i= 8'h69;
parameter character_lowercase_j= 8'h6A;
parameter character_lowercase_k= 8'h6B;
parameter character_lowercase_l= 8'h6C;
parameter character_lowercase_m= 8'h6D;
parameter character_lowercase_n= 8'h6E;
parameter character_lowercase_o= 8'h6F;
parameter character_lowercase_p= 8'h70;
parameter character_lowercase_q= 8'h71;
parameter character_lowercase_r= 8'h72;
parameter character_lowercase_s= 8'h73;
parameter character_lowercase_t= 8'h74;
parameter character_lowercase_u= 8'h75;
parameter character_lowercase_v= 8'h76;
parameter character_lowercase_w= 8'h77;
parameter character_lowercase_x= 8'h78;
parameter character_lowercase_y= 8'h79;
parameter character_lowercase_z= 8'h7A;
//Other Characters
parameter character_colon = 8'h3A; //':'
parameter character_stop = 8'h2E; //'.'
parameter character_semi_colon = 8'h3B; //';'
parameter character_minus = 8'h2D; //'-'
parameter character_divide = 8'h2F; //'/'
parameter character_plus = 8'h2B; //'+'
parameter character_comma = 8'h2C; // ','
parameter character_less_than = 8'h3C; //'<'
parameter character_greater_than = 8'h3E; //'>'
parameter character_equals = 8'h3D; //'='
parameter character_question = 8'h3F; //'?'
parameter character_dollar = 8'h24; //'$'
parameter character_space=8'h20; //' '
parameter character_exclaim=8'h21; //'!'
wire Clock_1KHz, Clock_1Hz;
wire Sample_Clk_Signal;
//=======================================================================================================================
//
// Insert your code for Lab2 here!
//
//
wire flash_mem_read;
wire flash_mem_waitrequest;
wire [22:0] flash_mem_address;
wire [31:0] flash_mem_readdata;
wire flash_mem_readdatavalid;
wire [3:0] flash_mem_byteenable;
wire clock_50, clock_22kHz;
wire [15:0] data_out;
assign flash_mem_write = 1’b0;
assign flash_mem_writedata = 32’b0;
assign flash_mem_burstcount = 6’b000001;
syncronizer sync(1'b0, clock_22kHz, CLK_50M, clock_50);
freq_divider div(CLK_50M, 32'hABE0, clock_22kHz, 1'b0);
fsm_flash fsm1(clock_50, flash_mem_readdata, flash_mem_readdatavalid, flash_mem_address, flash_mem_read, flash_mem_byteenable, rst, data_out);
flash flash_inst (
.clk_clk (clock_50),
.reset_reset_n (1'b1),
.flash_mem_write (1'b0),
.flash_mem_burstcount (1'b1),
.flash_mem_waitrequest (flash_mem_waitrequest),
.flash_mem_read (flash_mem_read),
.flash_mem_address (flash_mem_address),
.flash_mem_writedata (),
.flash_mem_readdata (flash_mem_readdata),
.flash_mem_readdatavalid (flash_mem_readdatavalid),
.flash_mem_byteenable (flash_mem_byteenable)
);
assign Sample_Clk_Signal = Clock_1KHz;
//Audio Generation Signal
//Note that the audio needs signed data - so convert 1 bit to 8 bits signed
wire [15:0] audio_data = data_out;
//======================================================================================
//
// Keyboard Interface
//
//
wire ps2c, ps2d; //filtered kbd wires
wire kbd_data_ready, Kbd_to_LCD_finish;
doublesync ps2c_doublsync
(.indata(PS2_CLK),
.outdata(ps2c),
.clk(CLK_50M),
.reset(1'b1));
doublesync ps2d_doublsync
(.indata(PS2_DAT),
.outdata(ps2d),
.clk(CLK_50M),
.reset(1'b1));
wire reset_kbd_data;
(* KEEP = "TRUE" *) wire conv_now_ignore_timing;
wire [7:0] kbd_received_ascii_code, kbd_scan_code;
Kbd_ctrl Kbd_Controller(
.kbd_clk(ps2c),
.kbd_data(ps2d),
.clk(CLK_50M),
.scan_code(kbd_scan_code),
.reset_kbd_reg(~reset_kbd_data),
.data_ready(kbd_data_ready)
);
key2ascii kbd2ascii(
.key_code(kbd_scan_code),
.ascii_code(kbd_received_ascii_code),
.clk(conv_now_ignore_timing)
);
parameter scope_info_bytes = 16;
parameter scope_info_bits_per_byte = 8;
wire [15:0] write_kbd_debug;
wire [scope_info_bits_per_byte-1:0] scope_info0, scope_info1, scope_info2,
scope_info3, scope_info4, scope_info5, scope_info6, scope_info7, scope_info8,
scope_info9, scope_info10, scope_info11, scope_info12, scope_info13,
scope_info14, scope_info15;
Write_Kbd_To_Scope_LCD Write_Kbd_To_LCD1
(.kbd_ascii_data(kbd_received_ascii_code),
.kbd_ready(kbd_data_ready), .reset_kbd_data(reset_kbd_data),
.sm_clk(CLK_50M), .reset(1'b1),
.finish(Kbd_to_LCD_finish),
.scope_info0(scope_info0),
.scope_info1(scope_info1),
.scope_info2(scope_info2),
.scope_info3(scope_info3),
.scope_info4(scope_info4),
.scope_info5(scope_info5),
.scope_info6(scope_info6),
.scope_info7(scope_info7),
.scope_info8(scope_info8),
.scope_info9(scope_info9),
.scope_info10(scope_info10),
.scope_info11(scope_info11),
.scope_info12(scope_info12),
.scope_info13(scope_info13),
.scope_info14(scope_info14),
.scope_info15(scope_info15),
.debug(write_kbd_debug),
.convert_now(conv_now_ignore_timing)
);
//=====================================================================================
//
// LCD Scope Acquisition Circuitry Wire Definitions
//
//=====================================================================================
wire allow_run_LCD_scope;
wire [15:0] scope_channelA, scope_channelB;
(* keep = 1, preserve = 1 *)wire scope_clk;
reg user_scope_enable_trigger;
wire user_scope_enable;
wire user_scope_enable_trigger_path0, user_scope_enable_trigger_path1;
wire scope_enable_source = SW[8];
wire choose_LCD_or_SCOPE = SW[9];
doublesync user_scope_enable_sync1(.indata(scope_enable_source),
.outdata(user_scope_enable),
.clk(CLK_50M),
.reset(1'b1));
//Generate the oscilloscope clock
Generate_Arbitrary_Divided_Clk32
Generate_LCD_scope_Clk(
.inclk(CLK_50M),
.outclk(scope_clk),
.outclk_Not(),
.div_clk_count(scope_sampling_clock_count),
.Reset(1'h1));
//Scope capture channels
//Scope capture channels
(* keep = 1, preserve = 1 *) logic ScopeChannelASignal;
(* keep = 1, preserve = 1 *) logic ScopeChannelBSignal;
assign ScopeChannelASignal = Sample_Clk_Signal;
assign ScopeChannelBSignal = SW[1];
//Scope capture channels
scope_capture LCD_scope_channelA(
.clk(scope_clk),
.the_signal(ScopeChannelASignal),
.capture_enable(allow_run_LCD_scope & user_scope_enable),
.captured_data(scope_channelA), //Insert your channel B signal here
.reset(1'b1));
scope_capture LCD_scope_channelB
(
.clk(scope_clk),
.the_signal(ScopeChannelBSignal),
.capture_enable(allow_run_LCD_scope & user_scope_enable),
.captured_data(scope_channelB), //Insert your channel A signal here
.reset(1'b1));
//The LCD scope and display
LCD_Scope_Encapsulated_pacoblaze_wrapper LCD_LED_scope(
//LCD control signals
.lcd_d(GPIO_0[7:0]),
.lcd_rs(GPIO_0[8]),
.lcd_rw(GPIO_0[9]),
.lcd_e(GPIO_0[10]),
.clk(CLK_50M),
//LCD Display values
.InH(8'hAA),
.InG(8'hBB),
.InF(8'h01),
.InE(8'h23),
.InD(8'h45),
.InC(8'h67),
.InB(8'h89),
.InA(8'h00),
//LCD display information signals
.InfoH({scope_info15,scope_info14}),
.InfoG({scope_info13,scope_info12}),
.InfoF({scope_info11,scope_info10}),
.InfoE({scope_info9,scope_info8}),
.InfoD({scope_info7,scope_info6}),
.InfoC({scope_info5,scope_info4}),
.InfoB({scope_info3,scope_info2}),
.InfoA({scope_info1,scope_info0}),
//choose to display the values or the oscilloscope
.choose_scope_or_LCD(choose_LCD_or_SCOPE),
//scope channel declarations
.scope_channelA(scope_channelA), //don't touch
.scope_channelB(scope_channelB), //don't touch
//scope information generation
.ScopeInfoA({character_1,character_K,character_H,character_lowercase_z}),
.ScopeInfoB({character_S,character_W,character_1,character_space}),
//enable_scope is used to freeze the scope just before capturing
//the waveform for display (otherwise the sampling would be unreliable)
.enable_scope(allow_run_LCD_scope) //don't touch
);
//=====================================================================================
//
// Seven-Segment and speed control
//
//=====================================================================================
wire speed_up_event, speed_down_event;
//Generate 1 KHz Clock
Generate_Arbitrary_Divided_Clk32
Gen_1KHz_clk
(
.inclk(CLK_50M),
.outclk(Clock_1KHz),
.outclk_Not(),
.div_clk_count(32'h61A6), //change this if necessary to suit your module
.Reset(1'h1));
wire speed_up_raw;
wire speed_down_raw;
doublesync
key0_doublsync
(.indata(!KEY[0]),
.outdata(speed_up_raw),
.clk(Clock_1KHz),
.reset(1'b1));
doublesync
key1_doublsync
(.indata(!KEY[1]),
.outdata(speed_down_raw),
.clk(Clock_1KHz),
.reset(1'b1));
parameter num_updown_events_per_sec = 10;
parameter num_1KHZ_clocks_between_updown_events = 1000/num_updown_events_per_sec;
reg [15:0] updown_counter = 0;
always @(posedge Clock_1KHz)
begin
if (updown_counter >= num_1KHZ_clocks_between_updown_events)
begin
if (speed_up_raw)
begin
speed_up_event_trigger <= 1;
end
if (speed_down_raw)
begin
speed_down_event_trigger <= 1;
end
updown_counter <= 0;
end
else
begin
updown_counter <= updown_counter + 1;
speed_up_event_trigger <=0;
speed_down_event_trigger <= 0;
end
end
wire speed_up_event_trigger;
wire speed_down_event_trigger;
async_trap_and_reset_gen_1_pulse
make_speedup_pulse
(
.async_sig(speed_up_event_trigger),
.outclk(CLK_50M),
.out_sync_sig(speed_up_event),
.auto_reset(1'b1),
.reset(1'b1)
);
async_trap_and_reset_gen_1_pulse
make_speedown_pulse
(
.async_sig(speed_down_event_trigger),
.outclk(CLK_50M),
.out_sync_sig(speed_down_event),
.auto_reset(1'b1),
.reset(1'b1)
);
wire speed_reset_event;
doublesync
key2_doublsync
(.indata(!KEY[2]),
.outdata(speed_reset_event),
.clk(CLK_50M),
.reset(1'b1));
parameter oscilloscope_speed_step = 100;
wire [15:0] speed_control_val;
speed_reg_control
speed_reg_control_inst
(
.clk(CLK_50M),
.up_event(speed_up_event),
.down_event(speed_down_event),
.reset_event(speed_reset_event),
.speed_control_val(speed_control_val)
);
logic [15:0] scope_sampling_clock_count;
parameter [15:0] default_scope_sampling_clock_count = 12499; //2KHz
always @ (posedge CLK_50M)
begin
scope_sampling_clock_count <= default_scope_sampling_clock_count+{{16{speed_control_val[15]}},speed_control_val};
end
logic [7:0] Seven_Seg_Val[5:0];
logic [3:0] Seven_Seg_Data[5:0];
SevenSegmentDisplayDecoder SevenSegmentDisplayDecoder_inst0(.ssOut(Seven_Seg_Val[0]), .nIn(Seven_Seg_Data[0]));
SevenSegmentDisplayDecoder SevenSegmentDisplayDecoder_inst1(.ssOut(Seven_Seg_Val[1]), .nIn(Seven_Seg_Data[1]));
SevenSegmentDisplayDecoder SevenSegmentDisplayDecoder_inst2(.ssOut(Seven_Seg_Val[2]), .nIn(Seven_Seg_Data[2]));
SevenSegmentDisplayDecoder SevenSegmentDisplayDecoder_inst3(.ssOut(Seven_Seg_Val[3]), .nIn(Seven_Seg_Data[3]));
SevenSegmentDisplayDecoder SevenSegmentDisplayDecoder_inst4(.ssOut(Seven_Seg_Val[4]), .nIn(Seven_Seg_Data[4]));
SevenSegmentDisplayDecoder SevenSegmentDisplayDecoder_inst5(.ssOut(Seven_Seg_Val[5]), .nIn(Seven_Seg_Data[5]));
assign HEX0 = Seven_Seg_Val[0];
assign HEX1 = Seven_Seg_Val[1];
assign HEX2 = Seven_Seg_Val[2];
assign HEX3 = Seven_Seg_Val[3];
assign HEX4 = Seven_Seg_Val[4];
assign HEX5 = Seven_Seg_Val[5];
wire Clock_2Hz;
Generate_Arbitrary_Divided_Clk32
Gen_2Hz_clk
(.inclk(CLK_50M),
.outclk(Clock_2Hz),
.outclk_Not(),
.div_clk_count(32'h17D7840 >> 1),
.Reset(1'h1)
);
logic [23:0] actual_7seg_output;
reg [23:0] regd_actual_7seg_output;
always @(posedge Clock_2Hz)
begin
regd_actual_7seg_output <= actual_7seg_output;
Clock_1Hz <= ~Clock_1Hz;
end
assign Seven_Seg_Data[0] = regd_actual_7seg_output[3:0];
assign Seven_Seg_Data[1] = regd_actual_7seg_output[7:4];
assign Seven_Seg_Data[2] = regd_actual_7seg_output[11:8];
assign Seven_Seg_Data[3] = regd_actual_7seg_output[15:12];
assign Seven_Seg_Data[4] = regd_actual_7seg_output[19:16];
assign Seven_Seg_Data[5] = regd_actual_7seg_output[23:20];
assign actual_7seg_output = scope_sampling_clock_count;
//=======================================================================================================================
//
// Audio controller code - do not touch
//
//========================================================================================================================
wire [$size(audio_data)-1:0] actual_audio_data_left, actual_audio_data_right;
wire audio_left_clock, audio_right_clock;
to_slow_clk_interface
interface_actual_audio_data_right
(.indata(audio_data),
.outdata(actual_audio_data_right),
.inclk(CLK_50M),
.outclk(audio_right_clock));
to_slow_clk_interface
interface_actual_audio_data_left
(.indata(audio_data),
.outdata(actual_audio_data_left),
.inclk(CLK_50M),
.outclk(audio_left_clock));
audio_controller
audio_control(
// Clock Input (50 MHz)
.iCLK_50(CLK_50M), // 50 MHz
.iCLK_28(), // 27 MHz
// 7-SEG Displays
// I2C
.I2C_SDAT(FPGA_I2C_SDAT), // I2C Data
.oI2C_SCLK(FPGA_I2C_SCLK), // I2C Clock
// Audio CODEC
.AUD_ADCLRCK(AUD_ADCLRCK), // Audio CODEC ADC LR Clock
.iAUD_ADCDAT(AUD_ADCDAT), // Audio CODEC ADC Data
.AUD_DACLRCK(AUD_DACLRCK), // Audio CODEC DAC LR Clock
.oAUD_DACDAT(AUD_DACDAT), // Audio CODEC DAC Data
.AUD_BCLK(AUD_BCLK), // Audio CODEC Bit-Stream Clock
.oAUD_XCK(AUD_XCK), // Audio CODEC Chip Clock
.audio_outL({actual_audio_data_left,8'b1}),
.audio_outR({actual_audio_data_right,8'b1}),
.audio_right_clock(audio_right_clock),
.audio_left_clock(audio_left_clock)
);
//=======================================================================================================================
//
// End Audio controller code
//
//========================================================================================================================
endmodule