-
Notifications
You must be signed in to change notification settings - Fork 8
/
DE2_115_CAMERA.v
668 lines (588 loc) · 15 KB
/
DE2_115_CAMERA.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
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
// --------------------------------------------------------------------
// Copyright (c) 2010 by Terasic Technologies Inc.
// --------------------------------------------------------------------
//
// Permission:
//
// Terasic grants permission to use and modify this code for use
// in synthesis for all Terasic Development Boards and Altera Development
// Kits made by Terasic. Other use of this code, including the selling
// ,duplication, or modification of any portion is strictly prohibited.
//
// Disclaimer:
//
// This VHDL/Verilog or C/C++ source code is intended as a design reference
// which illustrates how these types of functions can be implemented.
// It is the user's responsibility to verify their design for
// consistency and functionality through the use of formal
// verification methods. Terasic provides no warranty regarding the use
// or functionality of this code.
//
// --------------------------------------------------------------------
//
// Terasic Technologies Inc
// 356 Fu-Shin E. Rd Sec. 1. JhuBei City,
// HsinChu County, Taiwan
// 302
//
// web: http://www.terasic.com/
// email: [email protected]
//
// --------------------------------------------------------------------
//
// Major Functions: DE2_115 D5M+VGA 640*480 800*600 solution
//
// --------------------------------------------------------------------
//
// Revision History :
// --------------------------------------------------------------------
// Ver :| Author :| Mod. Date :| Changes Made:
// V1.0 :| Johnny FAN Peli Li:| 22/07/2010:| Initial Revision
// --------------------------------------------------------------------
//=======================================================
// This code is generated by Terasic System Builder
//=======================================================
//to set the VGA solution
`include "VGA_Param.h"
module DE2_115_CAMERA(
//////////// CLOCK //////////
CLOCK_50,
CLOCK2_50,
CLOCK3_50,
//////////// Sma //////////
SMA_CLKIN,
SMA_CLKOUT,
//////////// LED //////////
LEDG,
LEDR,
//////////// KEY //////////
KEY,
//////////// EJTAG //////////
EX_IO,
//////////// SW //////////
SW,
//////////// SEG7 //////////
HEX0,
HEX1,
HEX2,
HEX3,
HEX4,
HEX5,
HEX6,
HEX7,
//////////// LCD //////////
LCD_BLON,
LCD_DATA,
LCD_EN,
LCD_ON,
LCD_RS,
LCD_RW,
//////////// RS232 //////////
UART_CTS,
UART_RTS,
UART_RXD,
UART_TXD,
//////////// PS2 for Keyboard and Mouse //////////
PS2_CLK,
PS2_CLK2,
PS2_DAT,
PS2_DAT2,
//////////// SDCARD //////////
SD_CLK,
SD_CMD,
SD_DAT,
SD_WP_N,
//////////// VGA //////////
VGA_B,
VGA_BLANK_N,
VGA_CLK,
VGA_G,
VGA_HS,
VGA_R,
VGA_SYNC_N,
VGA_VS,
//////////// Audio //////////
AUD_ADCDAT,
AUD_ADCLRCK,
AUD_BCLK,
AUD_DACDAT,
AUD_DACLRCK,
AUD_XCK,
//////////// I2C for EEPROM //////////
EEP_I2C_SCLK,
EEP_I2C_SDAT,
//////////// I2C for Audio Tv-Decoder //////////
I2C_SCLK,
I2C_SDAT,
//////////// Ethernet 0 //////////
ENET0_GTX_CLK,
ENET0_INT_N,
ENET0_LINK100,
ENET0_MDC,
ENET0_MDIO,
ENET0_RST_N,
ENET0_RX_CLK,
ENET0_RX_COL,
ENET0_RX_CRS,
ENET0_RX_DATA,
ENET0_RX_DV,
ENET0_RX_ER,
ENET0_TX_CLK,
ENET0_TX_DATA,
ENET0_TX_EN,
ENET0_TX_ER,
ENETCLK_25,
//////////// Ethernet 1 //////////
ENET1_GTX_CLK,
ENET1_INT_N,
ENET1_LINK100,
ENET1_MDC,
ENET1_MDIO,
ENET1_RST_N,
ENET1_RX_CLK,
ENET1_RX_COL,
ENET1_RX_CRS,
ENET1_RX_DATA,
ENET1_RX_DV,
ENET1_RX_ER,
ENET1_TX_CLK,
ENET1_TX_DATA,
ENET1_TX_EN,
ENET1_TX_ER,
//////////// TV Decoder //////////
TD_CLK27,
TD_DATA,
TD_HS,
TD_RESET_N,
TD_VS,
//////////// USB 2.0 OTG //////////
OTG_ADDR,
OTG_CS_N,
OTG_DACK_N,
OTG_DATA,
OTG_DREQ,
OTG_FSPEED,
OTG_INT,
OTG_LSPEED,
OTG_RD_N,
OTG_RST_N,
OTG_WE_N,
//////////// IR Receiver //////////
IRDA_RXD,
//////////// SDRAM //////////
DRAM_ADDR,
DRAM_BA,
DRAM_CAS_N,
DRAM_CKE,
DRAM_CLK,
DRAM_CS_N,
DRAM_DQ,
DRAM_DQM,
DRAM_RAS_N,
DRAM_WE_N,
//////////// SRAM //////////
SRAM_ADDR,
SRAM_CE_N,
SRAM_DQ,
SRAM_LB_N,
SRAM_OE_N,
SRAM_UB_N,
SRAM_WE_N,
//////////// Flash //////////
FL_ADDR,
FL_CE_N,
FL_DQ,
FL_OE_N,
FL_RST_N,
FL_RY,
FL_WE_N,
FL_WP_N,
//////////// GPIO, GPIO connect to D5M - 5M Pixel Camera //////////
D5M_D,
D5M_FVAL,
D5M_LVAL,
D5M_PIXLCLK,
D5M_RESET_N,
D5M_SCLK,
D5M_SDATA,
D5M_STROBE,
D5M_TRIGGER,
D5M_XCLKIN
);
//=======================================================
// PARAMETER declarations
//=======================================================
//=======================================================
// PORT declarations
//=======================================================
//////////// CLOCK //////////
input CLOCK_50;
input CLOCK2_50;
input CLOCK3_50;
//////////// Sma //////////
input SMA_CLKIN;
output SMA_CLKOUT;
//////////// LED //////////
output [8:0] LEDG;
output [17:0] LEDR;
//////////// KEY //////////
input [3:0] KEY;
//////////// EJTAG //////////
inout [6:0] EX_IO;
//////////// SW //////////
input [17: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;
output [6:0] HEX6;
output [6:0] HEX7;
//////////// LCD //////////
output LCD_BLON;
inout [7:0] LCD_DATA;
output LCD_EN;
output LCD_ON;
output LCD_RS;
output LCD_RW;
//////////// RS232 //////////
output UART_CTS;
input UART_RTS;
input UART_RXD;
output UART_TXD;
//////////// PS2 for Keyboard and Mouse //////////
inout PS2_CLK;
inout PS2_CLK2;
inout PS2_DAT;
inout PS2_DAT2;
//////////// SDCARD //////////
output SD_CLK;
inout SD_CMD;
inout [3:0] SD_DAT;
input SD_WP_N;
//////////// VGA //////////
output [7:0] VGA_B;
output VGA_BLANK_N;
output VGA_CLK;
output [7:0] VGA_G;
output VGA_HS;
output [7:0] VGA_R;
output VGA_SYNC_N;
output VGA_VS;
//////////// Audio //////////
input AUD_ADCDAT;
inout AUD_ADCLRCK;
inout AUD_BCLK;
output AUD_DACDAT;
inout AUD_DACLRCK;
output AUD_XCK;
//////////// I2C for EEPROM //////////
output EEP_I2C_SCLK;
inout EEP_I2C_SDAT;
//////////// I2C for Audio Tv-Decoder //////////
output I2C_SCLK;
inout I2C_SDAT;
//////////// Ethernet 0 //////////
output ENET0_GTX_CLK;
input ENET0_INT_N;
input ENET0_LINK100;
output ENET0_MDC;
inout ENET0_MDIO;
output ENET0_RST_N;
input ENET0_RX_CLK;
input ENET0_RX_COL;
input ENET0_RX_CRS;
input [3:0] ENET0_RX_DATA;
input ENET0_RX_DV;
input ENET0_RX_ER;
input ENET0_TX_CLK;
output [3:0] ENET0_TX_DATA;
output ENET0_TX_EN;
output ENET0_TX_ER;
input ENETCLK_25;
//////////// Ethernet 1 //////////
output ENET1_GTX_CLK;
input ENET1_INT_N;
input ENET1_LINK100;
output ENET1_MDC;
inout ENET1_MDIO;
output ENET1_RST_N;
input ENET1_RX_CLK;
input ENET1_RX_COL;
input ENET1_RX_CRS;
input [3:0] ENET1_RX_DATA;
input ENET1_RX_DV;
input ENET1_RX_ER;
input ENET1_TX_CLK;
output [3:0] ENET1_TX_DATA;
output ENET1_TX_EN;
output ENET1_TX_ER;
//////////// TV Decoder //////////
input TD_CLK27;
input [7:0] TD_DATA;
input TD_HS;
output TD_RESET_N;
input TD_VS;
//////////// USB 2.0 OTG //////////
output [1:0] OTG_ADDR;
output OTG_CS_N;
output [1:0] OTG_DACK_N;
inout [15:0] OTG_DATA;
input [1:0] OTG_DREQ;
inout OTG_FSPEED;
input [1:0] OTG_INT;
inout OTG_LSPEED;
output OTG_RD_N;
output OTG_RST_N;
output OTG_WE_N;
//////////// IR Receiver //////////
input IRDA_RXD;
//////////// 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 [31:0] DRAM_DQ;
output [3:0] DRAM_DQM;
output DRAM_RAS_N;
output DRAM_WE_N;
//////////// SRAM //////////
output [19:0] SRAM_ADDR;
output SRAM_CE_N;
inout [15:0] SRAM_DQ;
output SRAM_LB_N;
output SRAM_OE_N;
output SRAM_UB_N;
output SRAM_WE_N;
//////////// Flash //////////
output [22:0] FL_ADDR;
output FL_CE_N;
inout [7:0] FL_DQ;
output FL_OE_N;
output FL_RST_N;
input FL_RY;
output FL_WE_N;
output FL_WP_N;
//////////// GPIO, GPIO connect to D5M - 5M Pixel Camera //////////
input [11:0] D5M_D;
input D5M_FVAL;
input D5M_LVAL;
input D5M_PIXLCLK;
output D5M_RESET_N;
output D5M_SCLK;
inout D5M_SDATA;
input D5M_STROBE;
output D5M_TRIGGER;
output D5M_XCLKIN;
//=======================================================
// REG/WIRE declarations
//=======================================================
wire [15:0] Read_DATA1;
wire [15:0] Read_DATA2;
wire [11:0] mCCD_DATA;
wire mCCD_DVAL;
wire mCCD_DVAL_d;
wire [15:0] X_Cont;
wire [15:0] Y_Cont;
wire [9:0] X_ADDR;
wire [31:0] Frame_Cont;
wire DLY_RST_0;
wire DLY_RST_1;
wire DLY_RST_2;
wire DLY_RST_3;
wire DLY_RST_4;
wire Read;
reg [11:0] rCCD_DATA;
reg rCCD_LVAL;
reg rCCD_FVAL;
wire [11:0] gCCD_R;
wire [11:0] gCCD_G;
wire [11:0] gCCD_B;
wire xCCD_DVAL;
wire sCCD_DVAL1;
wire sCCD_DVAL2;
wire [11:0] mCCD_G;
wire [11:0] sCCD_G1;
wire [11:0] sCCD_G2;
wire sdram_ctrl_clk;
wire [9:0] oVGA_R; // VGA Red[9:0]
wire [9:0] oVGA_G; // VGA Green[9:0]
wire [9:0] oVGA_B; // VGA Blue[9:0]
wire [7:0] ActivityGraph;
//power on start
wire auto_start;
//=======================================================
// Structural coding
//=======================================================
// D5M
assign D5M_TRIGGER = 1'b1; // tRIGGER
assign D5M_RESET_N = DLY_RST_1;
assign VGA_CTRL_CLK = ~VGA_CLK;
assign LEDR = SW;
assign LEDG[7:0] = ActivityGraph;
assign LEDG[8] = Y_Cont;
assign UART_TXD = UART_RXD;
//fetch the high 8 bits
assign VGA_R = oVGA_R[9:2];
assign VGA_G = oVGA_G[9:2];
assign VGA_B = oVGA_B[9:2];
//D5M read
always@(posedge D5M_PIXLCLK)
begin
rCCD_DATA <= D5M_D;
rCCD_LVAL <= D5M_LVAL;
rCCD_FVAL <= D5M_FVAL;
end
//auto start when power on
assign auto_start = ((KEY[0])&&(DLY_RST_3)&&(!DLY_RST_4))? 1'b1:1'b0;
//Reset module
Reset_Delay u2 ( .iCLK(CLOCK2_50),
.iRST(KEY[0]),
.oRST_0(DLY_RST_0),
.oRST_1(DLY_RST_1),
.oRST_2(DLY_RST_2),
.oRST_3(DLY_RST_3),
.oRST_4(DLY_RST_4)
);
//D5M image capture
CCD_Capture u3 ( .oDATA(mCCD_DATA),
.oDVAL(mCCD_DVAL),
.oX_Cont(X_Cont),
.oY_Cont(Y_Cont),
.oFrame_Cont(Frame_Cont),
.iDATA(rCCD_DATA),
.iFVAL(rCCD_FVAL),
.iLVAL(rCCD_LVAL),
.iSTART(!KEY[3]|auto_start),
.iEND(!KEY[2]),
.iCLK(~D5M_PIXLCLK),
.iRST(DLY_RST_2)
);
//D5M raw data convert to RGB data
RAW2RGB u4 ( .iCLK(D5M_PIXLCLK),
.iRST(DLY_RST_1),
.iDATA(mCCD_DATA),
.iDVAL(mCCD_DVAL),
.oRed(gCCD_R),
.oGreen(gCCD_G),
.oBlue(gCCD_B),
.oDVAL(xCCD_DVAL),
.iX_Cont(X_Cont),
.iY_Cont(Y_Cont)
);
// Convert RGB data to Grayscale
RGB2GRAY u5 ( .iRed(gCCD_R),
.iGreen(gCCD_G),
.iBlue(gCCD_B),
.oGray(mCCD_G)
);
// Memory Multiplexer
MEM_SWITCH u6 (.iGray(mCCD_G),
.iFrameCount(Frame_Cont[0]),
.iDVAL(xCCD_DVAL),
.oGray1(sCCD_G1),
.oGray2(sCCD_G2),
.oDVAL1(sCCD_DVAL1),
.oDVAL2(sCCD_DVAL2)
);
//Frame count display
SEG7_LUT_8 u7 ( .oSEG0(HEX0),.oSEG1(HEX1),
.oSEG2(HEX2),.oSEG3(HEX3),
.oSEG4(HEX4),.oSEG5(HEX5),
.oSEG6(HEX6),.oSEG7(HEX7),
.iDIG(Frame_Cont[31:0])
);
sdram_pll u8 (
.inclk0(CLOCK2_50),
.c0(sdram_ctrl_clk),
.c1(DRAM_CLK),
.c2(D5M_XCLKIN), //25M
`ifdef VGA_640x480p60
.c3(VGA_CLK) //25M
`else
.c4(VGA_CLK) //40M
`endif
);
//SDRam Read and Write as Frame Buffer
Sdram_Control u9 ( // HOST Side
.RESET_N(KEY[0]),
.CLK(sdram_ctrl_clk),
// FIFO Write Side 1
.WR1_DATA({4'b0,sCCD_G1[11:0]}),
.WR1(sCCD_DVAL1),
.WR1_ADDR(0),
.WR1_MAX_ADDR(640*480/2),
.WR1_LENGTH(8'h50),
.WR1_LOAD(!DLY_RST_0),
.WR1_CLK(D5M_PIXLCLK),
// FIFO Write Side 2
.WR2_DATA({4'b0,sCCD_G2[11:0]}),
.WR2(sCCD_DVAL2),
.WR2_ADDR(23'h100000),
.WR2_MAX_ADDR(23'h100000+640*480/2),
.WR2_LENGTH(8'h50),
.WR2_LOAD(!DLY_RST_0),
.WR2_CLK(D5M_PIXLCLK),
// FIFO Read Side 1
.RD1_DATA(Read_DATA1),
.RD1(Read),
.RD1_ADDR(0),
.RD1_MAX_ADDR(640*480/2),
.RD1_LENGTH(8'h50),
.RD1_LOAD(!DLY_RST_0),
.RD1_CLK(~VGA_CTRL_CLK),
// FIFO Read Side 2
.RD2_DATA(Read_DATA2),
.RD2(Read),
.RD2_ADDR(23'h100000),
.RD2_MAX_ADDR(23'h100000+640*480/2),
.RD2_LENGTH(8'h50),
.RD2_LOAD(!DLY_RST_0),
.RD2_CLK(~VGA_CTRL_CLK),
// SDRAM Side
.SA(DRAM_ADDR),
.BA(DRAM_BA),
.CS_N(DRAM_CS_N),
.CKE(DRAM_CKE),
.RAS_N(DRAM_RAS_N),
.CAS_N(DRAM_CAS_N),
.WE_N(DRAM_WE_N),
.DQ(DRAM_DQ),
.DQM(DRAM_DQM)
);
//D5M I2C control
I2C_CCD_Config u11 ( // Host Side
.iCLK(CLOCK2_50),
.iRST_N(DLY_RST_2),
.iEXPOSURE_ADJ(KEY[1]),
.iEXPOSURE_DEC_p(SW[17]),
.iZOOM_MODE_SW(SW[16]),
// I2C Side
.I2C_SCLK(D5M_SCLK),
.I2C_SDAT(D5M_SDATA)
);
//VGA DISPLAY
VGA_Controller u1 ( // Host Side
.oRequest(Read),
.iGrayMem1(Read_DATA1[11:2]),
.iGrayMem2(Read_DATA2[11:2]),
.iTrackMode(SW[9:0]),
// VGA Side
.oVGA_R(oVGA_R),
.oVGA_G(oVGA_G),
.oVGA_B(oVGA_B),
.oVGA_H_SYNC(VGA_HS),
.oVGA_V_SYNC(VGA_VS),
.oVGA_SYNC(VGA_SYNC_N),
.oVGA_BLANK(VGA_BLANK_N),
// Control Signal
.iCLK(VGA_CTRL_CLK),
.iRST_N(DLY_RST_2),
.iZOOM_MODE_SW(SW[16]),
.oActivityGraph(ActivityGraph)
);
endmodule