-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcd_timing_controller.v
More file actions
201 lines (181 loc) · 5.55 KB
/
lcd_timing_controller.v
File metadata and controls
201 lines (181 loc) · 5.55 KB
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
// --------------------------------------------------------------------
// Copyright (c) 2005 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: support@terasic.com
//
// --------------------------------------------------------------------
//
// Major Functions: DE2 LTM module Timing control and output image data
// form sdram
//
// --------------------------------------------------------------------
//
// Revision History :
// --------------------------------------------------------------------
// Ver :| Author :| Mod. Date :| Changes Made:
// V1.0 :| Johnny Fan :| 07/06/30 :| Initial Revision
// --------------------------------------------------------------------
module lcd_timing_controller (
iCLK, // LCD display clock
iRST_n, // systen reset
// SDRAM SIDE
iRed,
iGreen,
iBlue,
oREAD_SDRAM_EN, // read sdram data control signal
//LCD SIDE
oHD, // LCD Horizontal sync
oVD, // LCD Vertical sync
oDEN, // LCD Data Enable
oLCD_R, // LCD Red color data
oLCD_G, // LCD Green color data
oLCD_B // LCD Blue color data
);
//============================================================================
// PARAMETER declarations
//============================================================================
parameter H_LINE = 1056;
parameter V_LINE = 525;
parameter Hsync_Blank = 216;
parameter Hsync_Front_Porch = 40;
parameter Vertical_Back_Porch = 35;
parameter Vertical_Front_Porch = 10;
//===========================================================================
// PORT declarations
//===========================================================================
input iCLK;
input iRST_n;
input [7:0] iRed;
input [7:0] iGreen;
input [7:0] iBlue;
output oREAD_SDRAM_EN;
output [7:0] oLCD_R;
output [7:0] oLCD_G;
output [7:0] oLCD_B;
output oHD;
output oVD;
output oDEN;
//=============================================================================
// REG/WIRE declarations
//=============================================================================
reg [10:0] x_cnt;
reg [9:0] y_cnt;
wire [7:0] read_red;
wire [7:0] read_green;
wire [7:0] read_blue;
wire display_area;
wire oREAD_SDRAM_EN;
reg mhd;
reg mvd;
reg oHD;
reg oVD;
reg oDEN;
reg [7:0] oLCD_R;
reg [7:0] oLCD_G;
reg [7:0] oLCD_B;
//=============================================================================
// Structural coding
//=============================================================================
// This signal control reading data form SDRAM , if high read color data form sdram .
assign oREAD_SDRAM_EN = ( (x_cnt>Hsync_Blank-2)&&
(x_cnt<(H_LINE-Hsync_Front_Porch-1))&&
(y_cnt>(Vertical_Back_Porch-1))&&
(y_cnt<(V_LINE - Vertical_Front_Porch))
)? 1'b1 : 1'b0;
// This signal indicate the lcd display area .
assign display_area = ((x_cnt>(Hsync_Blank-1)&& //>215
(x_cnt<(H_LINE-Hsync_Front_Porch))&& //< 1016
(y_cnt>(Vertical_Back_Porch-1))&&
(y_cnt<(V_LINE - Vertical_Front_Porch))
)) ? 1'b1 : 1'b0;
assign read_red = display_area ? /*x_cnt[7:0]*/iRed : 8'b0;
assign read_green = display_area ? /*y_cnt[7:0]*/iGreen: 8'b0;
assign read_blue = display_area ? /*x_cnt[8:1]*/iBlue : 8'b0;
///////////////////////// x y counter and lcd hd generator //////////////////
always@(posedge iCLK or negedge iRST_n)
begin
if (!iRST_n)
begin
x_cnt <= 11'd0;
mhd <= 1'd0;
end
else if (x_cnt == (H_LINE-1))
begin
x_cnt <= 11'd0;
mhd <= 1'd0;
end
else
begin
x_cnt <= x_cnt + 11'd1;
mhd <= 1'd1;
end
end
always@(posedge iCLK or negedge iRST_n)
begin
if (!iRST_n)
y_cnt <= 10'd0;
else if (x_cnt == (H_LINE-1))
begin
if (y_cnt == (V_LINE-1))
y_cnt <= 10'd0;
else
y_cnt <= y_cnt + 10'd1;
end
end
////////////////////////////// touch panel timing //////////////////
always@(posedge iCLK or negedge iRST_n)
begin
if (!iRST_n)
mvd <= 1'b1;
else if (y_cnt == 10'd0)
mvd <= 1'b0;
else
mvd <= 1'b1;
end
always@(posedge iCLK or negedge iRST_n)
begin
if (!iRST_n)
begin
oHD <= 1'd0;
oVD <= 1'd0;
oDEN <= 1'd0;
oLCD_R <= 8'd0;
oLCD_G <= 8'd0;
oLCD_B <= 8'd0;
end
else
begin
oHD <= mhd;
oVD <= mvd;
oDEN <= display_area;
oLCD_R <= read_red;
oLCD_G <= read_green;
oLCD_B <= read_blue;
end
end
endmodule