LCD_Driver通用时序模块

  1 //---------------  注意  --------------------------------------
2 //--- 水平扫描计数器、同步信号、DE 都是同步于dclk的上升沿-----
3 //--- 垂直扫描计数器、同步信号、DE_V都是同步于 hs 的下降沿-----
4 //-------------------------------------------------------------
5
6 `timescale 1ns/1ps
7 module LCD_Driver(
8 //---- SYS SIGNAL
9 sys_clk ,
10 sys_rst_n ,
11 rgb_data ,
12 //---- MCU AD BUS----
13
14 //----MCU Ctrl BUS----
15 //----LCD DRIVER-----
16 hs ,
17 vs ,
18 R ,
19 G ,
20 B ,
21 DE ,
22 dclk
23 );
24 //------ 480*272_60Fps@9MHz ---------
25 //---- LQ043T3DX02 参数
26 parameter HL = 41 ; //H:525
27 parameter HB = 2 ;
28 parameter HD = 480 ;
29 parameter HF = 2 ;
30 parameter VL = 10 ; //V:286
31 parameter VB = 2 ;
32 parameter VD = 272 ;
33 parameter VF = 2 ;
34 //-----------------------------------
35 input sys_clk ;
36 input sys_rst_n ;
37 input[15:0] rgb_data ;
38 output hs ;
39 output vs ;
40 output[4:0] R ; //5
41 output[5:0] G ; //6
42 output[4:0] B ; //5
43 output DE ;
44 output dclk ;
45
46 reg hs ;
47 reg vs ;
48 reg [4:0] R ; //5
49 reg [5:0] G ; //6
50 reg [4:0] B ; //5
51 reg DE ;
52 reg dclk ;
53 //--------------------------------
54 reg [1:0] div_freq_count ;
55 reg [9:0] h_count ;
56 reg [9:0] v_count ;
57 reg DE_V ;
58
59 //--------- dclk= sys_clk/6 ----------------
60 //--- 计数器0、1、2循环计数
61 //--- dclk每三个sys_clk取反
62 //--- 计数器在sys_clk的上升沿加1 -----------
63 always@(posedge sys_clk or negedge sys_rst_n)
64 if(!sys_rst_n)
65 div_freq_count <= 2'd0 ;
66 else
67 if(div_freq_count == 2'd2)
68 div_freq_count <= 2'd0 ;
69 else
70 div_freq_count <= div_freq_count + 2'd1 ;
71
72 always@(posedge sys_clk or negedge sys_rst_n)
73 if(!sys_rst_n)
74 dclk <= 2'd0 ;
75 else
76 if(div_freq_count == 2'd2)
77 dclk <= ~dclk ;
78
79 //--------- h_count -------------------
80 //--- 计数器1-->(HL+HB+HD+HF)循环计数
81 //--- 计数器在dclk的上升沿加1 ---------
82 always@(posedge dclk or negedge sys_rst_n)
83 if(!sys_rst_n)
84 h_count <= 10'd0 ;
85 else
86 if(h_count == (HL+HB+HD+HF))
87 h_count <= 10'd1 ;
88 else
89 h_count <= h_count + 10'd1 ;
90
91 //---------- hs ---------------------
92 //--- hs在dclk的上升沿跳变 ------------
93 always@(posedge dclk or negedge sys_rst_n) // 使用sys_clk还是dclk?
94 if(!sys_rst_n)
95 hs <= 1'd1 ;
96 else
97 case(h_count )
98 10'd0 : hs <= 1'd0 ;
99 HL : hs <= 1'd1 ;
100 HL+HB+HD+HF : hs <= 1'd0 ;
101 default: hs <= hs ;
102 endcase
103
104 //--------- DE --------------------------
105 //--- DE在dclk的上升沿跳变 ------------
106 always@(posedge dclk or negedge sys_rst_n) // 使用sys_clk还是dclk?
107 if(!sys_rst_n)
108 DE <= 1'd0 ;
109 else
110 case(h_count )
111 HL+HB : DE <= 1'd1 ;
112 HL+HB+HD : DE <= 1'd0 ;
113 default: DE <= DE ;
114 endcase
115 //--------- v_count ----------------
116 //--- 计数器1-->(VL+VB+VD+VF)循环计数
117 //--- 计数器在hs的下降沿加1 ---------
118 always@(negedge hs or negedge sys_rst_n)
119 if(!sys_rst_n)
120 v_count <= 10'd0 ;
121 else
122 if(v_count == (VL+VB+VD+VF) )
123 v_count <= 10'd1 ;
124 else
125 v_count <= v_count + 10'd1 ;
126
127 //---------- vs ---------------------
128 //--- hs在hs的下降沿跳变 --------------
129 always@(negedge hs or negedge sys_rst_n) // 使用d_clk还是hs?
130 if(!sys_rst_n)
131 vs <= 1'd1 ;
132 else
133 case(v_count )
134 10'd0 : vs <= 1'd0 ;
135 VL : vs <= 1'd1 ;
136 VL+VB+VD+VF : vs <= 1'd0 ;
137 default: vs <= vs ;
138 endcase
139
140 //--------- DE_V --------------------------
141 //--- DE_V在hs的下降沿跳变 ----------------
142 always@(negedge hs or negedge sys_rst_n) // 使用d_clk还是hs?
143 if(!sys_rst_n)
144 DE_V <= 1'd0 ;
145 else
146 case(v_count )
147 VL+VB : DE_V <= 1'd1 ;
148 VL+VB+VD : DE_V <= 1'd0 ;
149 default: DE_V <= DE_V ;
150 endcase
151 //------- R/G/B Data assign ----------------
152 always@(rgb_data) {R,G,B} = rgb_data ;
153
154 //------------------------------------------
155
156
157 endmodule

 

==========测试模块===========================

 1 `timescale 1ns/1ns
2 //`define VCD_FILE_RECORD 1
3
4 module TB();
5
6 //------------产生波形文件-------------------
7 `ifdef VCD_FILE_RECORD
8 initial
9 begin
10 $dumpfile("test.vcd");
11 $dumpvars(-1,TB);
12 end
13 `endif
14
15 //----------系统时钟信号 ---------------
16 wire clk ;
17 wire rst_n ;
18 gSignal Inst_gSignal(
19 .gCLK (clk),
20 .gRST_N (rst_n)
21 );
22 defparam Inst_gSignal.CLK_PERIOD = 20; //50MHz
23 //---------- 复位控制 -----------------
24 initial
25 begin
26 Inst_gSignal.sys_rst_n(168); //复位134ns
27 #27457200
28 Inst_gSignal.sys_rst_n(168); //复位134ns
29 end
30 //
31 //--------- LCD Driver 例化 ----------
32 wire hs ;
33 wire vs ;
34 wire[4:0] R ;
35 wire[5:0] G ;
36 wire[4:0] B ;
37 wire DE ;
38 wire dclk ;
39 reg [15:0] rgb_data ;
40 LCD_Driver i_LCD_Driver(
41 //---- SYS SIGNAL
42 .sys_clk (clk ),
43 .sys_rst_n (rst_n ),
44 .rgb_data (rgb_data ),
45 //---- MCU AD BUS----
46
47 //----MCU Ctrl BUS----
48 //----LCD DRIVER-----
49 .hs (hs ) ,
50 .vs (vs ) ,
51 .R (R ) ,
52 .G (G ) ,
53 .B (B ) ,
54 .DE (DE ) ,
55 .dclk (dclk )
56 );
57
58 //----------- RGB Data------------------
59
60 always@(posedge dclk or negedge rst_n) // dclk同步
61 if(!rst_n)
62 rgb_data <= 16'd0 ;
63 else
64 if(DE==1'b1)
65 rgb_data <= rgb_data+ 16'd1 ;
66 else
67 rgb_data <= 16'd0 ;
68
69
70
71
72 endmodule


========= wave.do===============

 1 onerror {resume}
2 quietly WaveActivateNextPane {} 0
3 add wave -noupdate -divider TB
4 add wave -noupdate -format Logic /TB/clk
5 add wave -noupdate -format Logic /TB/rst_n
6 add wave -noupdate -format Logic /TB/dclk
7 add wave -noupdate -format Literal -radix unsigned /TB/rgb_data
8 add wave -noupdate -format Logic /TB/DE
9 add wave -noupdate -format Logic /TB/hs
10 add wave -noupdate -format Logic /TB/vs
11 add wave -noupdate -format Literal -radix unsigned /TB/R
12 add wave -noupdate -format Literal -radix unsigned /TB/G
13 add wave -noupdate -format Literal -radix unsigned /TB/B
14 add wave -noupdate -divider LCD_Driver
15 add wave -noupdate -format Logic /TB/i_LCD_Driver/sys_clk
16 add wave -noupdate -format Logic /TB/i_LCD_Driver/sys_rst_n
17 add wave -noupdate -color {Green Yellow} -format Literal -radix unsigned /TB/i_LCD_Driver/div_freq_count
18 add wave -noupdate -color {Green Yellow} -format Logic -radix unsigned /TB/i_LCD_Driver/dclk
19 add wave -noupdate -color Gold -format Literal -radix unsigned /TB/i_LCD_Driver/h_count
20 add wave -noupdate -color Gold -format Logic -radix unsigned /TB/i_LCD_Driver/hs
21 add wave -noupdate -color Gold -format Logic -radix unsigned /TB/i_LCD_Driver/DE
22 add wave -noupdate -color Orchid -format Literal -radix unsigned /TB/i_LCD_Driver/v_count
23 add wave -noupdate -color Orchid -format Logic -radix unsigned /TB/i_LCD_Driver/vs
24 add wave -noupdate -color Orchid -format Logic -radix unsigned /TB/i_LCD_Driver/DE_V
25 add wave -noupdate -format Literal -radix unsigned /TB/i_LCD_Driver/R
26 add wave -noupdate -format Literal -radix unsigned /TB/i_LCD_Driver/G
27 add wave -noupdate -format Literal -radix unsigned /TB/i_LCD_Driver/B
28 add wave -noupdate -format Literal -radix unsigned /TB/i_LCD_Driver/rgb_data
29 TreeUpdate [SetDefaultTree]
30 WaveRestoreCursors {{Cursor 1} {246795 ps} 0}
31 configure wave -namecolwidth 200
32 configure wave -valuecolwidth 100
33 configure wave -justifyvalue left
34 configure wave -signalnamewidth 0
35 configure wave -snapdistance 10
36 configure wave -datasetprefix 0
37 configure wave -rowmargin 4
38 configure wave -childrowmargin 2
39 configure wave -gridoffset 0
40 configure wave -gridperiod 1
41 configure wave -griddelta 40
42 configure wave -timeline 0
43 configure wave -timelineunits ns
44 update
45 WaveRestoreZoom {0 ps} {1050 ns}



posted @ 2012-03-11 22:38  fishplj2000  阅读(340)  评论(0编辑  收藏  举报