SAIFIINDUSTRIES commited on
Commit
4792bf1
·
verified ·
1 Parent(s): 2599665

Add Repo: WangXuan95_FPGA-HDMI

Browse files
WangXuan95_FPGA-HDMI/README.md ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ![语言](https://img.shields.io/badge/语言-verilog_(IEEE1364_2001)-9A90FD.svg) ![仿真](https://img.shields.io/badge/仿真-iverilog-green.svg) ![部署](https://img.shields.io/badge/部署-quartus-blue.svg) ![部署](https://img.shields.io/badge/部署-vivado-FF1010.svg)
2
+
3
+  
4
+
5
+ <span id="en">FPGA HDMI display controller</span>
6
+ ===========================
7
+
8
+ This repo offers an **FPGA**-based **HDMI** **display** **controller** to display videos via HDMI, features:
9
+
10
+ * Pure Verilog implementation, compatible with various FPGA platforms.
11
+ * Use a simple user interface to fetch pixels from user's logic.
12
+ * Internally implemented clock domain cross. Therefore, the clock frequency of the user interface can be independent of the HDMI clock.
13
+
14
+ | ![diagram](document/diagram.png) |
15
+ | :------------------------------: |
16
+ | Figure: diagram of this IP. |
17
+
18
+  
19
+
20
+  
21
+
22
+  
23
+
24
+ # Hardware Setup
25
+
26
+ ### Connection
27
+
28
+ You should connect 4 TMDS differential pairs (8 pins) from HDMI connector to FPGA chip:
29
+
30
+ - hdmi_clk_p, hdmi_clk_n
31
+ - hdmi_tx0_p, hdmi_tx0_n
32
+ - hdmi_tx1_p, hdmi_tx1_n
33
+ - hdmi_tx2_p, hdmi_tx2_n
34
+
35
+ ### Signal voltage level
36
+
37
+ Although these signals are 4 differential pairs, they are actually regarded as 8 single-ended IO pins in FPGA.
38
+
39
+ All 8 IO pins should be **2.5V** **voltage** **level** , and the corresponding **IO** **bank** **power** **should** **be** **2.5V** .
40
+
41
+ ### FPGA IO constraints
42
+
43
+ Correspondingly, in the FPGA development software, you should constrain all these 8 IO pins as LVCMOS-2.5V (or LVTTL-2.5V), neither pull-up nor pull-down.
44
+
45
+ Besides, don't forget to constrain the FPGA IO positions of these 8 pins (refer to the schematic of the FPGA board).
46
+
47
+ The format of IO constraint files varies among different FPGA manufacturers. Taking [GOWIN FPGA](https://www.gowinsemi.com.cn/) as an example, the CST constraint file may be written as follows:
48
+
49
+ ```
50
+ IO_LOC "hdmi_tx0_n" 29; IO_PORT "hdmi_tx0_n" IO_TYPE=LVCMOS25 PULL_MODE=NONE DRIVE=8;
51
+ IO_LOC "hdmi_tx0_p" 30; IO_PORT "hdmi_tx0_p" IO_TYPE=LVCMOS25 PULL_MODE=NONE DRIVE=8;
52
+
53
+ IO_LOC "hdmi_tx1_n" 31; IO_PORT "hdmi_tx1_n" IO_TYPE=LVCMOS25 PULL_MODE=NONE DRIVE=8;
54
+ IO_LOC "hdmi_tx1_p" 32; IO_PORT "hdmi_tx1_p" IO_TYPE=LVCMOS25 PULL_MODE=NONE DRIVE=8;
55
+
56
+ IO_LOC "hdmi_tx2_n" 34; IO_PORT "hdmi_tx2_n" IO_TYPE=LVCMOS25 PULL_MODE=NONE DRIVE=8;
57
+ IO_LOC "hdmi_tx2_p" 35; IO_PORT "hdmi_tx2_p" IO_TYPE=LVCMOS25 PULL_MODE=NONE DRIVE=8;
58
+
59
+ IO_LOC "hdmi_clk_n" 27; IO_PORT "hdmi_clk_n" IO_TYPE=LVCMOS25 PULL_MODE=NONE DRIVE=8;
60
+ IO_LOC "hdmi_clk_p" 28; IO_PORT "hdmi_clk_p" IO_TYPE=LVCMOS25 PULL_MODE=NONE DRIVE=8;
61
+ ```
62
+
63
+
64
+
65
+ ### Reference circuit schematic
66
+
67
+ For specific circuit schematic design, referred to [the schematic of Tang-Nano-4K FPGA board](https://wiki.sipeed.com/hardware/zh/tang/Tang-Nano-4K/Nano-4K.html#%E8%B5%84%E6%96%99)
68
+
69
+ | ![hardware](document/hardware_connection.png) |
70
+ | :-------------------------------------------: |
71
+ | Figure: Reference hardware design. |
72
+
73
+  
74
+
75
+  
76
+  
77
+
78
+ # Module Description
79
+
80
+ [hdmi_tx_top.v](./RTL/hdmi_tx_top.v) is the top design of this IP. The input and output signals are:
81
+
82
+ ```verilog
83
+ module hdmi_tx_top #(
84
+ // the parameter of request to response latency ---------------------------------------
85
+ parameter RESP_LATENCY = 1, // 1, 2, or 3
86
+ // paramter of video sizes ------------------------------------------------------------
87
+ parameter [13:0] H_TOTAL = 14'd800,
88
+ parameter [13:0] H_DRAW_START = 14'd0,
89
+ parameter [13:0] H_DRAW_WIDTH = 14'd640,
90
+ parameter [13:0] H_SYNC_START = 14'd656,
91
+ parameter [13:0] H_SYNC_WIDTH = 14'd96,
92
+ parameter [13:0] V_TOTAL = 14'd525,
93
+ parameter [13:0] V_DRAW_START = 14'd0,
94
+ parameter [13:0] V_DRAW_HEIGHT= 14'd480,
95
+ parameter [13:0] V_SYNC_START = 14'd490,
96
+ parameter [13:0] V_SYNC_HEIGHT= 14'd2
97
+ ) (
98
+ // user's clock and reset -------------------------------------------------------------
99
+ input wire rstn,
100
+ input wire clk, // can be asynchronous with pclk_x5. Its frequency must be slightly higher than f(pclk_x5) / 5
101
+ // user's pixel request interface (these signals synchronize with clk) ----------------
102
+ output reg req_en, // request for a pixel
103
+ output reg req_sof, // the requested pixel is at start of frame
104
+ output reg req_eof, // the requested pixel is at end of frame
105
+ output reg req_sol, // the requested pixel is at start of line
106
+ output reg req_eol, // the requested pixel is at end of line
107
+ // user's pixel response interface (these signals synchronize with clk) ---------------
108
+ input wire [7:0] resp_red,
109
+ input wire [7:0] resp_green,
110
+ input wire [7:0] resp_blue,
111
+ // HDMI driving clock, whose frequency must be 5 * pclk (pclk is the pixel clock) -----
112
+ input wire pclk_x5,
113
+ // HDMI TX out ------------------------------------------------------------------------
114
+ output wire hdmi_clk_p,
115
+ output wire hdmi_clk_n,
116
+ output wire hdmi_tx0_p,
117
+ output wire hdmi_tx0_n,
118
+ output wire hdmi_tx1_p,
119
+ output wire hdmi_tx1_n,
120
+ output wire hdmi_tx2_p,
121
+ output wire hdmi_tx2_n
122
+ );
123
+ ```
124
+
125
+  
126
+
127
+ ### Configure video resolution and frequency
128
+
129
+ The default parameter settings will generate a video of 640x480 @ 59.5Hz, which corresponds to a pixel frequency of 25MHz.
130
+
131
+ This configuration is referenced from another [FPGA HDMI project by FPGA4FUN](https://www.fpga4fun.com/HDMI.html) .
132
+
133
+ If you want other video resolution and frame rate, please refer to relevant specifications.
134
+
135
+  
136
+
137
+ ### Clocks
138
+
139
+ You should provide the following two clocks of this module :
140
+
141
+ | Clock name | `pclk_x5` | `clk` |
142
+ | :------------------: | :-------------------------------: | :------------------: |
143
+ | **description** | HDMI driving clock | user's clock |
144
+ | **frequency** | Five times of the pixel frequency | |
145
+ | **minimum freq.** | 125MHz | f(pclk_x5) / 5 |
146
+ | **typical freq.** | 125MHz (640x480 @ 59.5Hz) | 25MHz - 200MHz |
147
+ | **How to determine** | based on video resolution and FPS | based on user needs. |
148
+
149
+  
150
+
151
+ ### Pixel request&response interface
152
+
153
+ When the module is running, it will request for video pixels from outside (i.e. from user), so you should response these pixels according to the module's interface timing. The request and response signals are:
154
+
155
+ | Signal Name | Direction | Bit Width | Description |
156
+ | :--------------: | :-------: | :-------: | :---------------------------------------------------------: |
157
+ | **`req_en`** | output | 1 | Request for a pixel |
158
+ | **`req_sof`** | output | 1 | The requested pixels is the first pixel of the entire frame |
159
+ | **`req_eof`** | output | 1 | The requested pixels is the last pixel of the entire frame |
160
+ | **`req_sol`** | output | 1 | The requested pixels is the first pixel of a line |
161
+ | **`req_eol`** | output | 1 | The requested pixels is the last pixel of a line |
162
+ | **`resp_red`** | input | 8 | Red channel of the response pixel |
163
+ | **`resp_green`** | input | 8 | Green channel of the response pixel |
164
+ | **`resp_blue`** | input | 8 | Blue channel of the response pixel |
165
+
166
+ Note that **all request and response pixel signals should be operated in the clock domain of** **`clk`** .
167
+
168
+ The module requests pixels in raster order, that is, frame by frame, row, by row, from left to right.
169
+
170
+ Whenever `req_en` =1, it indicates that the module is requesting a pixel, and you need to make this pixel appear on the response signals (**`resp_red, resp_green, resp_blue`**) in the *N*th cycle thereafter. Where *N* is the response latency, which can be configured as 1, 2, or 3, achieved by configuring the `RESP_LATENCY` parameter.
171
+
172
+ The module also provide several auxiliary request signals:
173
+
174
+ - When the requested pixel is the first pixel of a entire frame, `req_sof`=1
175
+ - When the requested pixel is the last pixel of a entire frame, `req_eof`=1
176
+ - When the requested pixel is the first pixel of a row, `req_sol`=1
177
+ - When the requested pixel is the first pixel of a row, `req_eol`=1
178
+
179
+  
180
+
181
+  
182
+
183
+  
184
+
185
+ # FPGA Example
186
+
187
+ Here we provide a simple FPGA example that can display scrolling green to purple stripes on the screen.
188
+
189
+ The top Verilog file of this example is [fpga_top.v](./fpga_example/RTL/fpga_top.v)
190
+
191
+ This example can directly run on [GOWIN Tang-Nano-4K FPGA board](https://wiki.sipeed.com/hardware/zh/tang/Tang-Nano-4K/Nano-4K.html). Just open the project file ([fpga_example/hdmi.gprj](./fpga_example/hdmi.gprj)) use the [GOWIN FPGA Designer Software](https://www.gowinsemi.com.cn/faq.aspx#1), compile the project and program the FPGA.
192
+
193
+ If you want to run this example on FPGA from other manufacturers, you only need to rewrite the constraint file, without modifying the Verilog code.
194
+
195
+ The following figure is the block diagram of this example.
196
+
197
+ | ![hardware](document/fpga_example_diagram.png) |
198
+ | :--------------------------------------------: |
199
+ | Figure: block diagram of the FPGA example. |
200
+
201
+  
202
+
203
+  
204
+
205
+  
206
+
207
+ # Simulation and Verification
208
+
209
+ The simulation design is in the [SIM](./SIM) folder.
210
+
211
+ The following figure is the block diagram of the simulation.
212
+
213
+ | ![hardware](document/simulation_diagram.png) |
214
+ | :------------------------------------------: |
215
+ | Figure: block diagram of the simulation. |
216
+
217
+  
218
+
219
+  
220
+
221
+  
222
+
223
+ # Reference
224
+
225
+ [1] FPGA HDMI project: https://www.fpga4fun.com/HDMI.html , FPGA4FUN.
226
+
227
+ [2] GOWIN Tang Nano 4K FPGA development board: https://wiki.sipeed.com/hardware/zh/tang/Tang-Nano-4K/Nano-4K.html , Sipeed.
228
+
229
+ [3] HDMI Specification Version 1.3a: https://ez.analog.com/cfs-file/__key/telligent-evolution-components-attachments/00-317-00-00-00-05-21-37/HDMISpecification13a.pdf
230
+
231
+ [4] HDMI Specification Version 1.4b: https://www.hdmi.org/spec/hdmi1_4b
WangXuan95_FPGA-HDMI/RTL/hdmi_async_fifo.v ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ //--------------------------------------------------------------------------------------------------------
3
+ // Module : hdmi_async_fifo
4
+ // Type : synthesizable, IP's sub module
5
+ // Standard: Verilog 2001 (IEEE1364-2001)
6
+ // Function: cross TMDS data from user's clock domain to HDMI clock domain.
7
+ //--------------------------------------------------------------------------------------------------------
8
+
9
+ module hdmi_async_fifo #(
10
+ parameter DW = 8,
11
+ parameter EA = 10
12
+ ) (
13
+ //
14
+ input wire i_rstn,
15
+ input wire i_clk,
16
+ output wire i_tready,
17
+ input wire i_tvalid,
18
+ input wire [DW-1:0] i_tdata,
19
+ //
20
+ input wire o_rstn,
21
+ input wire o_clk,
22
+ input wire o_tready,
23
+ output reg o_tvalid,
24
+ output reg [DW-1:0] o_tdata,
25
+ //
26
+ output wire w_half_empty
27
+ );
28
+
29
+
30
+ reg [DW-1:0] buffer [(1<<EA)-1:0]; // may automatically synthesize to BRAM
31
+
32
+ reg [EA:0] wptr=0, wq_wptr_grey=0, rq1_wptr_grey=0, rq2_wptr_grey=0;
33
+ reg [EA:0] rptr=0, rq_rptr_grey=0, wq1_rptr_grey=0, wq2_rptr_grey=0;
34
+ reg [EA:0] rptr_a1 = {{EA{1'b0}}, 1'b1}; // rptr_a1 always equal to rptr+1, but using register to optimize timing
35
+ wire [EA:0] rptr_next = (o_tvalid & o_tready) ? rptr_a1 : rptr;
36
+
37
+ wire [EA:0] wptr_grey = (wptr >> 1) ^ wptr;
38
+ wire [EA:0] rptr_grey = (rptr >> 1) ^ rptr;
39
+ wire [EA:0] rptr_next_grey = (rptr_next >> 1) ^ rptr_next;
40
+
41
+ always @ (posedge i_clk or negedge i_rstn)
42
+ if(~i_rstn)
43
+ wq_wptr_grey <= 0;
44
+ else
45
+ wq_wptr_grey <= wptr_grey;
46
+
47
+ always @ (posedge o_clk or negedge o_rstn)
48
+ if(~o_rstn)
49
+ {rq2_wptr_grey, rq1_wptr_grey} <= 0;
50
+ else
51
+ {rq2_wptr_grey, rq1_wptr_grey} <= {rq1_wptr_grey, wq_wptr_grey};
52
+
53
+ always @ (posedge o_clk or negedge o_rstn)
54
+ if(~o_rstn)
55
+ rq_rptr_grey <= 0;
56
+ else
57
+ rq_rptr_grey <= rptr_grey;
58
+
59
+ always @ (posedge i_clk or negedge i_rstn)
60
+ if(~i_rstn)
61
+ {wq2_rptr_grey, wq1_rptr_grey} <= 0;
62
+ else
63
+ {wq2_rptr_grey, wq1_rptr_grey} <= {wq1_rptr_grey, rq_rptr_grey};
64
+
65
+ wire w_full = (wq2_rptr_grey == {~wptr_grey[EA:EA-1], wptr_grey[EA-2:0]} );
66
+ wire r_empty = (rq2_wptr_grey == rptr_next_grey );
67
+
68
+ assign i_tready = ~w_full;
69
+
70
+
71
+
72
+ always @ (posedge i_clk or negedge i_rstn)
73
+ if(~i_rstn) begin
74
+ wptr <= 0;
75
+ end else begin
76
+ if(i_tvalid & ~w_full)
77
+ wptr <= wptr + {{EA{1'b0}}, 1'b1};
78
+ end
79
+
80
+ always @ (posedge i_clk)
81
+ if(i_tvalid & ~w_full)
82
+ buffer[wptr[EA-1:0]] <= i_tdata;
83
+
84
+
85
+
86
+ initial o_tvalid = 1'b0;
87
+
88
+ always @ (posedge o_clk or negedge o_rstn)
89
+ if (~o_rstn) begin
90
+ rptr <= 0;
91
+ rptr_a1 <= {{EA{1'b0}}, 1'b1};
92
+ o_tvalid <= 1'b0;
93
+ end else begin
94
+ rptr <= rptr_next;
95
+ rptr_a1 <= rptr_next + {{EA{1'b0}}, 1'b1};
96
+ o_tvalid <= ~r_empty;
97
+ end
98
+
99
+ always @ (posedge o_clk)
100
+ o_tdata <= buffer[rptr_next[EA-1:0]];
101
+
102
+
103
+
104
+ /////////////////////////////////////////////////////////////////////////////////////////////
105
+ // judge half full
106
+ /////////////////////////////////////////////////////////////////////////////////////////////
107
+
108
+ function [EA:0] gray_to_binary;
109
+ input [EA:0] gray;
110
+ integer i;
111
+ begin
112
+ gray_to_binary[EA] = gray[EA];
113
+ for (i = EA-1; i >= 0; i = i - 1) begin
114
+ gray_to_binary[i] = gray_to_binary[i+1] ^ gray[i];
115
+ end
116
+ end
117
+ endfunction
118
+
119
+ wire [EA-2:0] TMP = 0;
120
+ wire [EA:0] PTR_QUARTER = {2'b01, TMP};
121
+
122
+ reg [EA:0] wq2_rptr = 0;
123
+
124
+ always @ (posedge i_clk or negedge i_rstn)
125
+ if (~i_rstn)
126
+ wq2_rptr <= 0;
127
+ else
128
+ wq2_rptr <= gray_to_binary(wq1_rptr_grey);
129
+
130
+ wire [EA:0] wr_delta = wptr - wq2_rptr;
131
+ assign w_half_empty = (wr_delta < PTR_QUARTER);
132
+
133
+ endmodule
134
+
WangXuan95_FPGA-HDMI/RTL/hdmi_tddr.v ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ //--------------------------------------------------------------------------------------------------------
3
+ // Module : hdmi_tddr
4
+ // Type : synthesizable, IP's sub module
5
+ // Standard: Verilog 2001 (IEEE1364-2001)
6
+ // Function: ODDR for hdmi_tx_top.v
7
+ //--------------------------------------------------------------------------------------------------------
8
+
9
+ module hdmi_tddr (
10
+ input wire clk,
11
+ input wire [1:0] din,
12
+ output wire dout
13
+ );
14
+
15
+ reg d0, d1, d1r;
16
+
17
+ always @ (posedge clk) {d1, d0} <= din;
18
+
19
+ always @ (negedge clk) d1r <= d1;
20
+
21
+ assign dout = clk ? d1r : d0;
22
+
23
+ endmodule
24
+
WangXuan95_FPGA-HDMI/RTL/hdmi_tmds_encode.v ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ //--------------------------------------------------------------------------------------------------------
3
+ // Module : hdmi_tmds_encode
4
+ // Type : synthesizable, IP's sub module
5
+ // Standard: Verilog 2001 (IEEE1364-2001)
6
+ // Function: encode VSYNC, HSYNC and pixels to 10-bit TMDS data.
7
+ //--------------------------------------------------------------------------------------------------------
8
+
9
+ module hdmi_tmds_encode (
10
+ input wire rstn,
11
+ input wire clk,
12
+ input wire i_en,
13
+ input wire i_vde, // video data enable, to choose between cd (when vde=0) and i_vd (when vde=1)
14
+ input wire [7:0] i_vd, // video data (red, green or blue)
15
+ input wire [1:0] i_cd, // control data
16
+ output wire o_en,
17
+ output wire [9:0] o_tmds_bits
18
+ );
19
+
20
+
21
+ wire [3:0] i_n1bs = {3'd0,i_vd[0]} + {3'd0,i_vd[1]} + {3'd0,i_vd[2]} + {3'd0,i_vd[3]} + {3'd0,i_vd[4]} + {3'd0,i_vd[5]} + {3'd0,i_vd[6]} + {3'd0,i_vd[7]};
22
+
23
+
24
+
25
+ /////////////////////////////////////////////////////////////////////////////////////////////
26
+ // stage E
27
+ /////////////////////////////////////////////////////////////////////////////////////////////
28
+
29
+ reg e_en = 1'b0;
30
+ reg e_vde = 1'b0;
31
+ reg [7:0] e_vd = 8'd0;
32
+ reg [1:0] e_cd = 2'd0;
33
+ reg e_bxnor = 1'b0;
34
+
35
+ always @ (posedge clk or negedge rstn)
36
+ if (~rstn) begin
37
+ e_en <= 1'b0;
38
+ e_vde <= 1'b0;
39
+ e_vd <= 8'd0;
40
+ e_cd <= 2'd0;
41
+ e_bxnor <= 1'b0;
42
+ end else begin
43
+ e_en <= i_en;
44
+ e_vde <= i_vde;
45
+ e_vd <= i_vd;
46
+ e_cd <= i_cd;
47
+ e_bxnor <= (i_n1bs>4'd4) || ((i_n1bs==4'd4) && (i_vd[0]==1'b0));
48
+ end
49
+
50
+ wire [8:0] d_qm;
51
+ assign d_qm[0] = e_vd[0];
52
+ assign d_qm[1] = e_vd[1] ^ e_bxnor ^ d_qm[0];
53
+ assign d_qm[2] = e_vd[2] ^ e_bxnor ^ d_qm[1];
54
+ assign d_qm[3] = e_vd[3] ^ e_bxnor ^ d_qm[2];
55
+ assign d_qm[4] = e_vd[4] ^ e_bxnor ^ d_qm[3];
56
+ assign d_qm[5] = e_vd[5] ^ e_bxnor ^ d_qm[4];
57
+ assign d_qm[6] = e_vd[6] ^ e_bxnor ^ d_qm[5];
58
+ assign d_qm[7] = e_vd[7] ^ e_bxnor ^ d_qm[6];
59
+ assign d_qm[8] = ~e_bxnor;
60
+
61
+
62
+
63
+ /////////////////////////////////////////////////////////////////////////////////////////////
64
+ // stage F
65
+ /////////////////////////////////////////////////////////////////////////////////////////////
66
+
67
+ reg f_en = 1'b0;
68
+ reg f_vde = 1'b0;
69
+ reg [1:0] f_cd = 2'd0;
70
+ reg [8:0] f_qm = 9'd0;
71
+
72
+ always @ (posedge clk or negedge rstn)
73
+ if (~rstn) begin
74
+ f_en <= 1'b0;
75
+ f_vde <= 1'b0;
76
+ f_cd <= 2'd0;
77
+ f_qm <= 9'd0;
78
+ end else begin
79
+ f_en <= e_en;
80
+ f_vde <= e_vde;
81
+ f_cd <= e_cd;
82
+ f_qm <= d_qm;
83
+ end
84
+
85
+ wire [3:0] f_bal = {3'd0,f_qm[0]} + {3'd0,f_qm[1]} + {3'd0,f_qm[2]} + {3'd0,f_qm[3]} + {3'd0,f_qm[4]} + {3'd0,f_qm[5]} + {3'd0,f_qm[6]} + {3'd0,f_qm[7]} - 4'd4;
86
+
87
+
88
+
89
+ /////////////////////////////////////////////////////////////////////////////////////////////
90
+ // stage G
91
+ /////////////////////////////////////////////////////////////////////////////////////////////
92
+
93
+ reg g_en = 1'b0;
94
+ reg g_vde = 1'b0;
95
+ reg [1:0] g_cd = 2'd0;
96
+ reg [8:0] g_qm = 9'd0;
97
+ reg [3:0] g_bal = 4'd0;
98
+ reg g_bal0 = 1'b0;
99
+
100
+ always @ (posedge clk or negedge rstn)
101
+ if (~rstn) begin
102
+ g_en <= 1'b0;
103
+ g_vde <= 1'b0;
104
+ g_cd <= 2'd0;
105
+ g_qm <= 9'd0;
106
+ g_bal <= 4'd0;
107
+ g_bal0 <= 1'b0;
108
+ end else begin
109
+ g_en <= f_en;
110
+ g_vde <= f_vde;
111
+ g_cd <= f_cd;
112
+ g_qm <= f_qm;
113
+ g_bal <= f_bal;
114
+ g_bal0 <= (f_bal == 4'd0);
115
+ end
116
+
117
+
118
+
119
+ /////////////////////////////////////////////////////////////////////////////////////////////
120
+ // stage H
121
+ /////////////////////////////////////////////////////////////////////////////////////////////
122
+
123
+ reg h_en = 1'b0;
124
+ reg [3:0] h_acc = 4'd0;
125
+ reg [9:0] h_tmds_bits = 10'd0;
126
+
127
+ wire eq_0 = (g_bal0 || (h_acc==4'd0));
128
+ wire eq_sign = (g_bal[3] == h_acc[3]);
129
+ wire invert_qm = eq_0 ? (~g_qm[8]) : eq_sign;
130
+ wire change = (g_qm[8] ^ ~eq_sign) & ~eq_0;
131
+ wire [3:0] acc_inc = g_bal - {3'd0, change};
132
+ wire [3:0] acc_new = invert_qm ? (h_acc - acc_inc) : (h_acc + acc_inc);
133
+ wire [7:0] tmds_datal= g_qm[7:0] ^ {8{invert_qm}};
134
+ wire [9:0] tmds_data = {invert_qm, g_qm[8], tmds_datal};
135
+
136
+ wire [9:0] tmds_ctrl = (g_cd == 2'b00) ? 10'b1101010100 :
137
+ (g_cd == 2'b01) ? 10'b0010101011 :
138
+ (g_cd == 2'b10) ? 10'b0101010100 :
139
+ 10'b1010101011 ;
140
+
141
+ always @ (posedge clk or negedge rstn)
142
+ if (~rstn) begin
143
+ h_en <= 1'b0;
144
+ h_acc <= 4'd0;
145
+ h_tmds_bits <= 10'd0;
146
+ end else begin
147
+ h_en <= g_en;
148
+ if (g_en) begin
149
+ h_acc <= g_vde ? acc_new : 4'd0;
150
+ h_tmds_bits <= g_vde ? tmds_data : tmds_ctrl;
151
+ end
152
+ end
153
+
154
+
155
+
156
+ /////////////////////////////////////////////////////////////////////////////////////////////
157
+ // assign output
158
+ /////////////////////////////////////////////////////////////////////////////////////////////
159
+
160
+ assign o_en = h_en;
161
+ assign o_tmds_bits = h_tmds_bits;
162
+
163
+
164
+ endmodule
165
+
WangXuan95_FPGA-HDMI/RTL/hdmi_tx_top.v ADDED
@@ -0,0 +1,346 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ //--------------------------------------------------------------------------------------------------------
3
+ // Module : hdmi_tx_top
4
+ // Type : synthesizable, IP's top
5
+ // Standard: Verilog 2001 (IEEE1364-2001)
6
+ // Function: A HDMI TX (display) controller.
7
+ // It can fetch video pixels from user-specified clock domain, cross them to the HDMI clock domain.
8
+ // Then, display the video to HDMI (following DVI TMDS timing specification).
9
+ //--------------------------------------------------------------------------------------------------------
10
+
11
+ module hdmi_tx_top #(
12
+ // the parameter of request to response latency ---------------------------------------
13
+ parameter RESP_LATENCY = 1, // 1, 2, or 3
14
+ // paramter of video sizes ------------------------------------------------------------
15
+ parameter [13:0] H_TOTAL = 14'd800,
16
+ parameter [13:0] H_DRAW_START = 14'd0,
17
+ parameter [13:0] H_DRAW_WIDTH = 14'd640,
18
+ parameter [13:0] H_SYNC_START = 14'd656,
19
+ parameter [13:0] H_SYNC_WIDTH = 14'd96,
20
+ parameter [13:0] V_TOTAL = 14'd525,
21
+ parameter [13:0] V_DRAW_START = 14'd0,
22
+ parameter [13:0] V_DRAW_HEIGHT= 14'd480,
23
+ parameter [13:0] V_SYNC_START = 14'd490,
24
+ parameter [13:0] V_SYNC_HEIGHT= 14'd2
25
+ ) (
26
+ // user's clock and reset -------------------------------------------------------------
27
+ input wire rstn,
28
+ input wire clk, // can be asynchronous with pclk_x5. Its frequency must be slightly higher than f(pclk_x5) / 5
29
+ // user's pixel request interface (these signals synchronize with clk) ----------------
30
+ output reg req_en, // request for a pixel
31
+ output reg req_sof, // the requested pixel is at start of frame
32
+ output reg req_eof, // the requested pixel is at end of frame
33
+ output reg req_sol, // the requested pixel is at start of line
34
+ output reg req_eol, // the requested pixel is at end of line
35
+ // user's pixel response interface (these signals synchronize with clk) ---------------
36
+ input wire [7:0] resp_red,
37
+ input wire [7:0] resp_green,
38
+ input wire [7:0] resp_blue,
39
+ // HDMI driving clock, whose frequency must be 5 * pclk (pclk is the pixel clock) -----
40
+ input wire pclk_x5,
41
+ // HDMI TX out ------------------------------------------------------------------------
42
+ output wire hdmi_clk_p,
43
+ output wire hdmi_clk_n,
44
+ output wire hdmi_tx0_p,
45
+ output wire hdmi_tx0_n,
46
+ output wire hdmi_tx1_p,
47
+ output wire hdmi_tx1_n,
48
+ output wire hdmi_tx2_p,
49
+ output wire hdmi_tx2_n
50
+ );
51
+
52
+
53
+
54
+ reg [13:0] hcnt = 14'd0;
55
+ reg [13:0] vcnt = 14'd0;
56
+
57
+ reg a_en = 1'b0;
58
+ reg a_hsync = 1'b0;
59
+ reg a_vsync = 1'b0;
60
+
61
+ reg b_en = 1'b0;
62
+ reg b_hsync = 1'b0;
63
+ reg b_vsync = 1'b0;
64
+ reg b_vde = 1'b0;
65
+
66
+ reg c_en = 1'b0;
67
+ reg c_hsync = 1'b0;
68
+ reg c_vsync = 1'b0;
69
+ reg c_vde = 1'b0;
70
+
71
+ reg d_en = 1'b0;
72
+ reg d_hsync = 1'b0;
73
+ reg d_vsync = 1'b0;
74
+ reg d_vde = 1'b0;
75
+
76
+ reg [ 7:0] d_red, d_green, d_blue;
77
+
78
+ //wire h_rdy;
79
+ wire h_en;
80
+ wire [ 9:0] h_tmds0_bits;
81
+ wire [ 9:0] h_tmds1_bits;
82
+ wire [ 9:0] h_tmds2_bits;
83
+
84
+ wire j_en;
85
+ wire [ 9:0] j_tmds0_bits;
86
+ wire [ 9:0] j_tmds1_bits;
87
+ wire [ 9:0] j_tmds2_bits;
88
+
89
+ reg [ 2:0] j_cnt5 = 3'd0; // HDMI control counter, period=5 (j_cnt5 = 0 -> 1 -> 2 -> 3 -> 4 -> 0)
90
+ reg j_fetch_start = 1'b0;
91
+ reg j_fetch = 1'b0;
92
+
93
+ wire half_empty;
94
+
95
+ reg [ 9:0] k_tmds0_bits = 10'd0;
96
+ reg [ 9:0] k_tmds1_bits = 10'd0;
97
+ reg [ 9:0] k_tmds2_bits = 10'd0;
98
+ reg [ 9:0] k_tmdsc_bits = 10'd0;
99
+
100
+
101
+
102
+ /////////////////////////////////////////////////////////////////////////////////////////////
103
+ // reset synchronize
104
+ /////////////////////////////////////////////////////////////////////////////////////////////
105
+
106
+ reg [3:0] rstn_x5_shift = 4'd0;
107
+ wire rstn_x5 = rstn_x5_shift[3];
108
+
109
+ always @ (posedge pclk_x5 or negedge rstn)
110
+ if (~rstn) rstn_x5_shift <= 4'd0;
111
+ else rstn_x5_shift <= {rstn_x5_shift[2:0], 1'b1};
112
+
113
+ reg [3:0] rstn_main_shift = 4'd0;
114
+ wire rstn_main = rstn_main_shift[3];
115
+
116
+ always @ (posedge clk or negedge rstn_x5)
117
+ if (~rstn_x5) rstn_main_shift <= 4'd0;
118
+ else rstn_main_shift <= {rstn_main_shift[2:0], 1'b1};
119
+
120
+
121
+
122
+ /////////////////////////////////////////////////////////////////////////////////////////////
123
+ // pixel coordinate counter
124
+ /////////////////////////////////////////////////////////////////////////////////////////////
125
+
126
+ always @ (posedge clk or negedge rstn_main)
127
+ if (~rstn_main) begin
128
+ hcnt <= 14'd0;
129
+ vcnt <= 14'd0;
130
+ end else begin
131
+ if (half_empty) begin
132
+ if (hcnt < (H_TOTAL - 14'd1)) begin
133
+ hcnt <= hcnt + 14'd1;
134
+ end else begin
135
+ hcnt <= 14'd0;
136
+ vcnt <= (vcnt < (V_TOTAL - 14'd1)) ? (vcnt + 14'd1) : 14'd0;
137
+ end
138
+ end
139
+ end
140
+
141
+ wire hsync = (hcnt >= H_SYNC_START) && (hcnt < (H_SYNC_START+H_SYNC_WIDTH) );
142
+ wire vsync = (vcnt >= V_SYNC_START) && (vcnt < (V_SYNC_START+V_SYNC_HEIGHT));
143
+ wire draw = (hcnt >= H_DRAW_START) && (hcnt < (H_DRAW_START+H_DRAW_WIDTH) ) && (vcnt >= V_DRAW_START) && (vcnt < (V_DRAW_START+V_DRAW_HEIGHT));
144
+ wire hfirst = (hcnt == H_DRAW_START);
145
+ wire hlast = (hcnt == (H_DRAW_START+H_DRAW_WIDTH-14'd1));
146
+ wire vfirst = (vcnt == V_DRAW_START);
147
+ wire vlast = (vcnt == (V_DRAW_START+V_DRAW_HEIGHT-14'd1));
148
+
149
+
150
+
151
+ /////////////////////////////////////////////////////////////////////////////////////////////
152
+ // stage A : generate HSYNC, VSYNC, and request signals
153
+ /////////////////////////////////////////////////////////////////////////////////////////////
154
+
155
+ initial {req_en, req_sol, req_eol, req_sof, req_eof} = 5'b0;
156
+
157
+ always @ (posedge clk or negedge rstn_main)
158
+ if (~rstn_main) begin
159
+ {a_en, a_hsync, a_vsync} <= 3'b0;
160
+ {req_en, req_sol, req_eol, req_sof, req_eof} <= 5'b0;
161
+ end else begin
162
+ a_en <= half_empty;
163
+ a_hsync <= hsync;
164
+ a_vsync <= vsync;
165
+ req_en <= half_empty & draw;
166
+ req_sol <= half_empty & draw & hfirst;
167
+ req_eol <= half_empty & draw & hlast;
168
+ req_sof <= half_empty & draw & hfirst & vfirst;
169
+ req_eof <= half_empty & draw & hlast & vlast;
170
+ end
171
+
172
+
173
+
174
+ /////////////////////////////////////////////////////////////////////////////////////////////
175
+ // stage B - D : get user response
176
+ /////////////////////////////////////////////////////////////////////////////////////////////
177
+
178
+ always @ (posedge clk or negedge rstn_main)
179
+ if (~rstn_main) begin
180
+ {b_en, b_hsync, b_vsync, b_vde} <= 4'b0;
181
+ {c_en, c_hsync, c_vsync, c_vde} <= 4'b0;
182
+ {d_en, d_hsync, d_vsync, d_vde} <= 4'b0;
183
+ end else begin
184
+ {b_en, b_hsync, b_vsync, b_vde} <= {a_en, a_hsync, a_vsync, req_en};
185
+ {c_en, c_hsync, c_vsync, c_vde} <= {b_en, b_hsync, b_vsync, b_vde};
186
+ {d_en, d_hsync, d_vsync, d_vde} <= {c_en, c_hsync, c_vsync, c_vde};
187
+ end
188
+
189
+ generate
190
+ if (RESP_LATENCY >= 3) begin
191
+ always @ (*)
192
+ {d_red, d_green, d_blue} = {resp_red, resp_green, resp_blue};
193
+
194
+ end else if (RESP_LATENCY == 2) begin
195
+ always @ (posedge clk)
196
+ {d_red, d_green, d_blue} <= {resp_red, resp_green, resp_blue};
197
+
198
+ end else begin
199
+ reg [ 7:0] c_red, c_green, c_blue;
200
+ always @ (posedge clk) begin
201
+ {c_red, c_green, c_blue} <= {resp_red, resp_green, resp_blue};
202
+ {d_red, d_green, d_blue} <= {c_red, c_green, c_blue};
203
+ end
204
+ end
205
+ endgenerate
206
+
207
+
208
+
209
+ /////////////////////////////////////////////////////////////////////////////////////////////
210
+ // stage E - H : TMDS encoding
211
+ /////////////////////////////////////////////////////////////////////////////////////////////
212
+
213
+ hdmi_tmds_encode u_tmds_encode_red (
214
+ .rstn ( rstn_main ),
215
+ .clk ( clk ),
216
+ .i_en ( d_en ),
217
+ .i_vde ( d_vde ),
218
+ .i_vd ( d_red ),
219
+ .i_cd ( 2'b00 ),
220
+ .o_en ( ),
221
+ .o_tmds_bits ( h_tmds2_bits )
222
+ );
223
+
224
+ hdmi_tmds_encode u_tmds_encode_green (
225
+ .rstn ( rstn_main ),
226
+ .clk ( clk ),
227
+ .i_en ( d_en ),
228
+ .i_vde ( d_vde ),
229
+ .i_vd ( d_green ),
230
+ .i_cd ( 2'b00 ),
231
+ .o_en ( ),
232
+ .o_tmds_bits ( h_tmds1_bits )
233
+ );
234
+
235
+ hdmi_tmds_encode u_tmds_encode_blue (
236
+ .rstn ( rstn_main ),
237
+ .clk ( clk ),
238
+ .i_en ( d_en ),
239
+ .i_vde ( d_vde ),
240
+ .i_vd ( d_blue ),
241
+ .i_cd ( {d_vsync, d_hsync} ),
242
+ .o_en ( h_en ),
243
+ .o_tmds_bits ( h_tmds0_bits )
244
+ );
245
+
246
+
247
+
248
+ /////////////////////////////////////////////////////////////////////////////////////////////
249
+ // stage J : cross to clock domain pclk_x5
250
+ /////////////////////////////////////////////////////////////////////////////////////////////
251
+
252
+ hdmi_async_fifo #(
253
+ .DW ( 30 ),
254
+ .EA ( 5 )
255
+ ) u_hdmi_async_fifo (
256
+ .i_rstn ( rstn_main ),
257
+ .i_clk ( clk ),
258
+ .i_tready ( /*h_rdy*/ ),
259
+ .i_tvalid ( h_en ),
260
+ .i_tdata ( {h_tmds0_bits, h_tmds1_bits, h_tmds2_bits} ),
261
+ .o_rstn ( rstn_x5 ),
262
+ .o_clk ( pclk_x5 ),
263
+ .o_tready ( j_fetch ),
264
+ .o_tvalid ( j_en ),
265
+ .o_tdata ( {j_tmds0_bits, j_tmds1_bits, j_tmds2_bits} ),
266
+ .w_half_empty ( half_empty )
267
+ );
268
+
269
+
270
+
271
+ /////////////////////////////////////////////////////////////////////////////////////////////
272
+ // stage H : fetch control
273
+ /////////////////////////////////////////////////////////////////////////////////////////////
274
+
275
+ always @ (posedge pclk_x5 or negedge rstn_x5)
276
+ if (~rstn_x5) begin
277
+ j_cnt5 <= 3'd0;
278
+ j_fetch_start <= 1'b0;
279
+ j_fetch <= 1'b0;
280
+ end else begin
281
+ j_cnt5 <= j_cnt5[2] ? 3'd0 : (j_cnt5 + 3'd1);
282
+ if (j_en & j_cnt5[2]) j_fetch_start <= 1'b1;
283
+ j_fetch <= j_cnt5[2] & j_fetch_start;
284
+ end
285
+
286
+
287
+
288
+ /////////////////////////////////////////////////////////////////////////////////////////////
289
+ // stage J : assert that u_hdmi_async_fifo never empty (only for simulation)
290
+ /////////////////////////////////////////////////////////////////////////////////////////////
291
+ /*
292
+ always @ (posedge pclk_x5 or negedge rstn_x5)
293
+ if (~rstn_x5) begin
294
+ end else begin
295
+ if (j_fetch & ~j_en) begin
296
+ $display("error : u_hdmi_async_fifo empty");
297
+ $finish;
298
+ end
299
+ end*/
300
+
301
+
302
+
303
+ /////////////////////////////////////////////////////////////////////////////////////////////
304
+ // stage H : assert that u_hdmi_async_fifo never full (only for simulation)
305
+ /////////////////////////////////////////////////////////////////////////////////////////////
306
+ /*
307
+ always @ (posedge clk or negedge rstn_main)
308
+ if (~rstn_main) begin
309
+ end else begin
310
+ if (~h_rdy & h_en) begin
311
+ $display("error : u_hdmi_async_fifo full");
312
+ $finish;
313
+ end
314
+ end*/
315
+
316
+
317
+
318
+ /////////////////////////////////////////////////////////////////////////////////////////////
319
+ // stage K : serialize TMDS signals
320
+ /////////////////////////////////////////////////////////////////////////////////////////////
321
+
322
+ always @ (posedge pclk_x5)
323
+ if (j_fetch) begin
324
+ k_tmds0_bits <= j_tmds0_bits;
325
+ k_tmds1_bits <= j_tmds1_bits;
326
+ k_tmds2_bits <= j_tmds2_bits;
327
+ k_tmdsc_bits <= 10'b0000011111;
328
+ end else begin
329
+ k_tmds0_bits <= k_tmds0_bits >> 2;
330
+ k_tmds1_bits <= k_tmds1_bits >> 2;
331
+ k_tmds2_bits <= k_tmds2_bits >> 2;
332
+ k_tmdsc_bits <= k_tmdsc_bits >> 2;
333
+ end
334
+
335
+ hdmi_tddr u0p_ddr (pclk_x5, k_tmds0_bits[1:0], hdmi_tx0_p);
336
+ hdmi_tddr u0n_ddr (pclk_x5, ~k_tmds0_bits[1:0], hdmi_tx0_n);
337
+ hdmi_tddr u1p_ddr (pclk_x5, k_tmds1_bits[1:0], hdmi_tx1_p);
338
+ hdmi_tddr u1n_ddr (pclk_x5, ~k_tmds1_bits[1:0], hdmi_tx1_n);
339
+ hdmi_tddr u2p_ddr (pclk_x5, k_tmds2_bits[1:0], hdmi_tx2_p);
340
+ hdmi_tddr u2n_ddr (pclk_x5, ~k_tmds2_bits[1:0], hdmi_tx2_n);
341
+ hdmi_tddr u3p_ddr (pclk_x5, k_tmdsc_bits[1:0], hdmi_clk_p);
342
+ hdmi_tddr u3n_ddr (pclk_x5, ~k_tmdsc_bits[1:0], hdmi_clk_n);
343
+
344
+
345
+ endmodule
346
+
WangXuan95_FPGA-HDMI/SIM/pixel_generate.v ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ //--------------------------------------------------------------------------------------------------------
3
+ // Module : pixel_generate
4
+ // Type : synthesizable
5
+ // Standard: Verilog 2001 (IEEE1364-2001)
6
+ // Function: generate green->purple scroll bars to test hdmi_tx_top.v
7
+ //--------------------------------------------------------------------------------------------------------
8
+
9
+ module pixel_generate # (
10
+ // the parameter of request to response latency ---------------------------------------
11
+ parameter RESP_LATENCY = 1 // 1, 2, or 3
12
+ ) (
13
+ // user's clock -----------------------------------------------------------------------
14
+ input wire clk,
15
+ // user's pixel request interface (these signals synchronize with clk) ----------------
16
+ input wire req_en,
17
+ input wire req_sof,
18
+ input wire req_sol,
19
+ // user's pixel response interface (these signals synchronize with clk) ---------------
20
+ output wire [7:0] resp_red,
21
+ output wire [7:0] resp_green,
22
+ output wire [7:0] resp_blue
23
+ );
24
+
25
+
26
+ reg [7:0] nrow;
27
+ reg [7:0] nframe = 8'h0;
28
+
29
+ reg [7:0] resp1_red, resp1_green, resp1_blue;
30
+ reg [7:0] resp2_red, resp2_green, resp2_blue;
31
+ reg [7:0] resp3_red, resp3_green, resp3_blue;
32
+
33
+
34
+ generate
35
+ if (RESP_LATENCY <= 1) assign {resp_red, resp_green, resp_blue} = {resp1_red, resp1_green, resp1_blue};
36
+ else if (RESP_LATENCY == 2) assign {resp_red, resp_green, resp_blue} = {resp2_red, resp2_green, resp2_blue};
37
+ else assign {resp_red, resp_green, resp_blue} = {resp3_red, resp3_green, resp3_blue};
38
+ endgenerate
39
+
40
+
41
+ always @ (posedge clk)
42
+ if (req_en) begin
43
+ if (req_sof) begin
44
+ nrow <= nframe + 8'd1;
45
+ nframe <= nframe + 8'd1;
46
+ resp1_red <= nframe;
47
+ resp1_green <= 8'hFF - nframe;
48
+ resp1_blue <= nframe;
49
+ end else if (req_sol) begin
50
+ nrow <= nrow + 8'h1;
51
+ resp1_red <= nrow;
52
+ resp1_green <= 8'hFF - nrow;
53
+ resp1_blue <= nrow;
54
+ end else begin
55
+ resp1_red <= resp1_red + 8'h1;
56
+ resp1_green <= resp1_green - 8'h1;
57
+ resp1_blue <= resp1_blue + 8'h1;
58
+ end
59
+ end
60
+
61
+
62
+ always @ (posedge clk) begin
63
+ {resp2_red, resp2_green, resp2_blue} <= {resp1_red, resp1_green, resp1_blue};
64
+ {resp3_red, resp3_green, resp3_blue} <= {resp2_red, resp2_green, resp2_blue};
65
+ end
66
+
67
+
68
+ endmodule
69
+
WangXuan95_FPGA-HDMI/SIM/tb_clkgen.v ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ //--------------------------------------------------------------------------------------------------------
3
+ // Module : tb_clkgen
4
+ // Type : simulation, sub module
5
+ // Standard: Verilog 2001 (IEEE1364-2001)
6
+ // Function: Generate clock with jitter (non-synthesizable!!!, only for simulation)
7
+ //--------------------------------------------------------------------------------------------------------
8
+
9
+ module tb_clkgen #(
10
+ parameter OFFSET = 0,
11
+ parameter PERIOD = 10000,
12
+ parameter JITTER = 0
13
+ ) (
14
+ output reg clk
15
+ );
16
+
17
+ integer T = PERIOD / 2;
18
+ integer t0 = 0;
19
+ integer t1 = 0;
20
+
21
+ initial begin
22
+ clk = 1'b0;
23
+ # (OFFSET);
24
+ while (1) begin
25
+ t1 = $random;
26
+ t1 = (t1 < 0) ? -t1 : t1;
27
+ t1 = (t1 % (2 * JITTER + 1)) - JITTER;
28
+ # (T - t0 + t1);
29
+ clk = ~clk;
30
+ t0 = t1;
31
+ end
32
+ end
33
+
34
+ endmodule
35
+
WangXuan95_FPGA-HDMI/SIM/tb_hdmi_tx_top.v ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ //--------------------------------------------------------------------------------------------------------
3
+ // Module : tb_hdmi_tx_top
4
+ // Type : simulation, top
5
+ // Standard: Verilog 2001 (IEEE1364-2001)
6
+ // Function: testbench for hdmi_tx_top.v
7
+ //--------------------------------------------------------------------------------------------------------
8
+
9
+ module tb_hdmi_tx_top ();
10
+
11
+
12
+ //initial $dumpvars(1, tb_hdmi_tx_top);
13
+
14
+ initial begin repeat(10000000) @ (posedge clk); $finish; end
15
+
16
+
17
+
18
+ /////////////////////////////////////////////////////////////////////////////////////////////
19
+ // generate two clocks (clk and pclk_x5)
20
+ /////////////////////////////////////////////////////////////////////////////////////////////
21
+
22
+ localparam CLK_PEROID = 37037; // T=37037ps f=27MHz
23
+ localparam PCLK_X5_PEROID = 8000; // T=4000ps f=125MHz
24
+
25
+ wire clk;
26
+ wire pclk_x5;
27
+
28
+ tb_clkgen #(0, CLK_PEROID, 200) u1_clkgen (clk); // jitter=200ps
29
+ tb_clkgen #(0, PCLK_X5_PEROID, 200) u2_clkgen (pclk_x5); // jitter=200ps
30
+
31
+
32
+
33
+ /////////////////////////////////////////////////////////////////////////////////////////////
34
+ // generate reset_n
35
+ /////////////////////////////////////////////////////////////////////////////////////////////
36
+
37
+ reg rstn = 1'b0;
38
+ initial begin repeat (4) @(posedge clk); rstn <= 1'b1; end
39
+
40
+
41
+
42
+ /////////////////////////////////////////////////////////////////////////////////////////////
43
+ // signals
44
+ /////////////////////////////////////////////////////////////////////////////////////////////
45
+
46
+ wire req_en, req_sof, req_sol; // request for pixel
47
+ wire [7:0] resp_red, resp_green, resp_blue; // response pixel
48
+ wire hdmi_clk_p, hdmi_tx0_p, hdmi_tx1_p, hdmi_tx2_p;
49
+
50
+
51
+
52
+ /////////////////////////////////////////////////////////////////////////////////////////////
53
+ // generate green->purple scroll bars to test hdmi_tx_top
54
+ /////////////////////////////////////////////////////////////////////////////////////////////
55
+
56
+ localparam RESP_LATENCY = 1; // request to response latency
57
+
58
+ pixel_generate # (
59
+ .RESP_LATENCY ( RESP_LATENCY )
60
+ ) u_pixel_generate (
61
+ .clk ( clk ),
62
+ .req_en ( req_en ),
63
+ .req_sof ( req_sof ),
64
+ .req_sol ( req_sol ),
65
+ .resp_red ( resp_red ),
66
+ .resp_green ( resp_green ),
67
+ .resp_blue ( resp_blue )
68
+ );
69
+
70
+
71
+
72
+ /////////////////////////////////////////////////////////////////////////////////////////////
73
+ // HDMI TX (display) controller.
74
+ /////////////////////////////////////////////////////////////////////////////////////////////
75
+
76
+ hdmi_tx_top #(
77
+ .RESP_LATENCY ( RESP_LATENCY )
78
+ ) u_hdmi_tx_top (
79
+ // user's clock and reset -------------------------------------------------------------
80
+ .rstn ( rstn ),
81
+ .clk ( clk ),
82
+ // user's pixel request interface (these signals synchronize with clk) ----------------
83
+ .req_en ( req_en ),
84
+ .req_sof ( req_sof ),
85
+ .req_eof ( ),
86
+ .req_sol ( req_sol ),
87
+ .req_eol ( ),
88
+ // user's pixel response interface (these signals synchronize with clk) ---------------
89
+ .resp_red ( resp_red ),
90
+ .resp_green ( resp_green ),
91
+ .resp_blue ( resp_blue ),
92
+ // HDMI driving clock, whose frequency must be 5 * pclk (pclk is the pixel clock) -----
93
+ .pclk_x5 ( pclk_x5 ),
94
+ // HDMI TX out ------------------------------------------------------------------------
95
+ .hdmi_clk_p ( hdmi_clk_p ),
96
+ .hdmi_clk_n ( ),
97
+ .hdmi_tx0_p ( hdmi_tx0_p ),
98
+ .hdmi_tx0_n ( ),
99
+ .hdmi_tx1_p ( hdmi_tx1_p ),
100
+ .hdmi_tx1_n ( ),
101
+ .hdmi_tx2_p ( hdmi_tx2_p ),
102
+ .hdmi_tx2_n ( )
103
+ );
104
+
105
+
106
+
107
+ /////////////////////////////////////////////////////////////////////////////////////////////
108
+ // decode three TMDS channels (non-synthesizable!!!, only for simulation)
109
+ /////////////////////////////////////////////////////////////////////////////////////////////
110
+
111
+ wire dec_vde, dec_vsync, dec_hsync;
112
+ wire [7:0] dec_red, dec_green, dec_blue;
113
+
114
+ tb_tmds_decode # ( // only for simulation
115
+ .HDMI_CLK_PEROID ( PCLK_X5_PEROID * 5 )
116
+ ) u_tmds_decode_red (
117
+ .tmds_clk ( hdmi_clk_p ),
118
+ .tmds_dat ( hdmi_tx2_p ),
119
+ .decoded_vde ( ),
120
+ .decoded_vsync ( ),
121
+ .decoded_hsync ( ),
122
+ .decoded_data ( dec_red )
123
+ );
124
+
125
+ tb_tmds_decode # ( // only for simulation
126
+ .HDMI_CLK_PEROID ( PCLK_X5_PEROID * 5 )
127
+ ) u_tmds_decode_green (
128
+ .tmds_clk ( hdmi_clk_p ),
129
+ .tmds_dat ( hdmi_tx1_p ),
130
+ .decoded_vde ( ),
131
+ .decoded_vsync ( ),
132
+ .decoded_hsync ( ),
133
+ .decoded_data ( dec_green )
134
+ );
135
+
136
+ tb_tmds_decode # ( // only for simulation
137
+ .HDMI_CLK_PEROID ( PCLK_X5_PEROID * 5 )
138
+ ) u_tmds_decode_blue (
139
+ .tmds_clk ( hdmi_clk_p ),
140
+ .tmds_dat ( hdmi_tx0_p ),
141
+ .decoded_vde ( dec_vde ),
142
+ .decoded_vsync ( dec_vsync ),
143
+ .decoded_hsync ( dec_hsync ),
144
+ .decoded_data ( dec_blue )
145
+ );
146
+
147
+
148
+
149
+ /////////////////////////////////////////////////////////////////////////////////////////////
150
+ // Check if the decoded pixels match the pixels generated by pixel_generate.v
151
+ /////////////////////////////////////////////////////////////////////////////////////////////
152
+
153
+ tb_pixel_verify u_tb_pixel_verify (
154
+ .clk ( hdmi_clk_p ),
155
+ .vde ( dec_vde ),
156
+ .vsync ( dec_vsync ),
157
+ .red ( dec_red ),
158
+ .green ( dec_green ),
159
+ .blue ( dec_blue )
160
+ );
161
+
162
+
163
+ endmodule
164
+
WangXuan95_FPGA-HDMI/SIM/tb_pixel_verify.v ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ //--------------------------------------------------------------------------------------------------------
3
+ // Module : tb_pixel_verify
4
+ // Type : simulation, sub module
5
+ // Standard: Verilog 2001 (IEEE1364-2001)
6
+ // Function: Check if the decoded pixels match the pixels generated by pixel_generate.v
7
+ //--------------------------------------------------------------------------------------------------------
8
+
9
+ module tb_pixel_verify (
10
+ input wire clk,
11
+ input wire vde,
12
+ input wire vsync,
13
+ input wire [7:0] red,
14
+ input wire [7:0] green,
15
+ input wire [7:0] blue
16
+ );
17
+
18
+
19
+ reg vde_r=0, vsync_r=0;
20
+
21
+ always @ (posedge clk) {vde_r, vsync_r} <= {vde, vsync};
22
+
23
+ integer nrow=0, nframe=0;
24
+
25
+ reg [7:0] expect_red, expect_green, expect_blue;
26
+
27
+
28
+ always @ (posedge clk)
29
+ if (vde) begin
30
+ if (~vde_r) begin // pixel: start of line
31
+ nrow <= nrow + 1;
32
+
33
+ $write(" %4d", nrow);
34
+
35
+ expect_red = nrow + nframe;
36
+ expect_green = 8'hFF - (nrow + nframe);
37
+ expect_blue = nrow + nframe;
38
+ end else begin // pixel
39
+ expect_red = expect_red + 8'h1;
40
+ expect_green = expect_green - 8'h1;
41
+ expect_blue = expect_blue + 8'h1;
42
+ end
43
+
44
+ if (expect_red !== red ) begin $display("mismatch on RED" ); $finish; end
45
+ if (expect_green !== green) begin $display("mismatch on GREEN"); $finish; end
46
+ if (expect_blue !== blue ) begin $display("mismatch on BLUE" ); $finish; end
47
+
48
+ end else if (~vsync_r & vsync) begin // new frame
49
+ nrow <= 0;
50
+ nframe <= nframe + 1;
51
+
52
+ $display("\n\n\n------ frame %6d ------", (nframe+1) );
53
+ end
54
+
55
+
56
+ endmodule
57
+
WangXuan95_FPGA-HDMI/SIM/tb_tmds_decode.v ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ //--------------------------------------------------------------------------------------------------------
3
+ // Module : tb_tmds_decode
4
+ // Type : simulation, sub module
5
+ // Standard: Verilog 2001 (IEEE1364-2001)
6
+ // Function: Decode a TMDS channel (non-synthesizable!!!, only for simulation)
7
+ //--------------------------------------------------------------------------------------------------------
8
+
9
+ module tb_tmds_decode # (
10
+ parameter HDMI_CLK_PEROID = 3145
11
+ ) (
12
+ // input
13
+ input wire tmds_clk,
14
+ input wire tmds_dat,
15
+ // output decoded data
16
+ output wire decoded_vde,
17
+ output wire decoded_vsync,
18
+ output wire decoded_hsync,
19
+ output wire [7:0] decoded_data
20
+ );
21
+
22
+ localparam L1 = HDMI_CLK_PEROID / 20;
23
+ localparam L2 = HDMI_CLK_PEROID / 10;
24
+
25
+ reg [ 9:0] tmds_data = 10'd0;
26
+ reg [10:0] decoded = 11'd0;
27
+ reg started = 1'b0;
28
+
29
+ assign {decoded_vde, decoded_vsync, decoded_hsync, decoded_data} = decoded;
30
+
31
+ initial begin
32
+ while(1) begin
33
+ @ (posedge tmds_clk);
34
+
35
+ if (started) begin
36
+ case (tmds_data)
37
+ 10'b1101010100 : decoded <= 11'b0_00_00000000;
38
+ 10'b0010101011 : decoded <= 11'b0_01_00000000;
39
+ 10'b0101010100 : decoded <= 11'b0_10_00000000;
40
+ 10'b1010101011 : decoded <= 11'b0_11_00000000;
41
+
42
+ default : begin
43
+ tmds_data[8] = ~tmds_data[8];
44
+ if (tmds_data[9])
45
+ tmds_data[7:0] = ~tmds_data[7:0];
46
+
47
+ decoded[7] <= tmds_data[7] ^ tmds_data[6] ^ tmds_data[8];
48
+ decoded[6] <= tmds_data[6] ^ tmds_data[5] ^ tmds_data[8];
49
+ decoded[5] <= tmds_data[5] ^ tmds_data[4] ^ tmds_data[8];
50
+ decoded[4] <= tmds_data[4] ^ tmds_data[3] ^ tmds_data[8];
51
+ decoded[3] <= tmds_data[3] ^ tmds_data[2] ^ tmds_data[8];
52
+ decoded[2] <= tmds_data[2] ^ tmds_data[1] ^ tmds_data[8];
53
+ decoded[1] <= tmds_data[1] ^ tmds_data[0] ^ tmds_data[8];
54
+ decoded[0] <= tmds_data[0];
55
+
56
+ decoded[10:8] <= 3'b1_00;
57
+ end
58
+ endcase
59
+ end
60
+
61
+ started = 1'b1;
62
+
63
+ #(L1) tmds_data[0] = tmds_dat;
64
+ #(L2) tmds_data[1] = tmds_dat;
65
+ #(L2) tmds_data[2] = tmds_dat;
66
+ #(L2) tmds_data[3] = tmds_dat;
67
+ #(L2) tmds_data[4] = tmds_dat;
68
+ #(L2) tmds_data[5] = tmds_dat;
69
+ #(L2) tmds_data[6] = tmds_dat;
70
+ #(L2) tmds_data[7] = tmds_dat;
71
+ #(L2) tmds_data[8] = tmds_dat;
72
+ #(L2) tmds_data[9] = tmds_dat;
73
+ end
74
+ end
75
+
76
+ endmodule
77
+
WangXuan95_FPGA-HDMI/fpga_example/RTL/fpga_top.v ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ //--------------------------------------------------------------------------------------------------------
3
+ // Module : fpga_top
4
+ // Type : synthesizable, fpga top
5
+ // Standard: Verilog 2001 (IEEE1364-2001)
6
+ // Function: example for hdmi_tx_top.v
7
+ //--------------------------------------------------------------------------------------------------------
8
+
9
+ module fpga_top (
10
+ input wire resetn, // reset button
11
+ input wire clk, // 27MHz
12
+ output wire hdmi_clk_p,
13
+ output wire hdmi_clk_n,
14
+ output wire hdmi_tx0_p,
15
+ output wire hdmi_tx0_n,
16
+ output wire hdmi_tx1_p,
17
+ output wire hdmi_tx1_n,
18
+ output wire hdmi_tx2_p,
19
+ output wire hdmi_tx2_n
20
+ );
21
+
22
+
23
+ localparam RESP_LATENCY = 1;
24
+
25
+ wire rstn;
26
+ wire pclk_x5; // 125MHz
27
+
28
+ wire req_en, req_sof, req_sol; // request for pixel
29
+ wire [7:0] resp_red, resp_green, resp_blue; // response pixel
30
+
31
+
32
+ /////////////////////////////////////////////////////////////////////////////////////////////
33
+ // use PLL to generate pclk_x5 (125MHz)
34
+ /////////////////////////////////////////////////////////////////////////////////////////////
35
+
36
+ Gowin_PLLVR u_pll (
37
+ .clkout ( pclk_x5 ),
38
+ .lock ( rstn ),
39
+ .reset ( ~resetn ),
40
+ .clkin ( clk )
41
+ );
42
+
43
+
44
+ /////////////////////////////////////////////////////////////////////////////////////////////
45
+ // generate green->purple scroll bars to test hdmi_tx_top
46
+ /////////////////////////////////////////////////////////////////////////////////////////////
47
+
48
+ pixel_generate # (
49
+ .RESP_LATENCY ( RESP_LATENCY )
50
+ ) u_pixel_generate (
51
+ .clk ( clk ),
52
+ .req_en ( req_en ),
53
+ .req_sof ( req_sof ),
54
+ .req_sol ( req_sol ),
55
+ .resp_red ( resp_red ),
56
+ .resp_green ( resp_green ),
57
+ .resp_blue ( resp_blue )
58
+ );
59
+
60
+
61
+ /////////////////////////////////////////////////////////////////////////////////////////////
62
+ // HDMI TX (display) controller.
63
+ /////////////////////////////////////////////////////////////////////////////////////////////
64
+
65
+ hdmi_tx_top #(
66
+ .RESP_LATENCY ( RESP_LATENCY )
67
+ ) u_hdmi_tx_top (
68
+ .rstn ( rstn ),
69
+ .clk ( clk ),
70
+ .req_en ( req_en ),
71
+ .req_sof ( req_sof ),
72
+ .req_eof ( ),
73
+ .req_sol ( req_sol ),
74
+ .req_eol ( ),
75
+ .resp_red ( resp_red ),
76
+ .resp_green ( resp_green ),
77
+ .resp_blue ( resp_blue ),
78
+ .pclk_x5 ( pclk_x5 ),
79
+ .hdmi_clk_p ( hdmi_clk_p ),
80
+ .hdmi_clk_n ( hdmi_clk_n ),
81
+ .hdmi_tx0_p ( hdmi_tx0_p ),
82
+ .hdmi_tx0_n ( hdmi_tx0_n ),
83
+ .hdmi_tx1_p ( hdmi_tx1_p ),
84
+ .hdmi_tx1_n ( hdmi_tx1_n ),
85
+ .hdmi_tx2_p ( hdmi_tx2_p ),
86
+ .hdmi_tx2_n ( hdmi_tx2_n )
87
+ );
88
+
89
+
90
+ endmodule
91
+
WangXuan95_FPGA-HDMI/fpga_example/RTL/gowin_pllvr/gowin_pllvr.v ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //Copyright (C)2014-2023 Gowin Semiconductor Corporation.
2
+ //All rights reserved.
3
+ //File Title: IP file
4
+ //GOWIN Version: V1.9.8.11
5
+ //Part Number: GW1NSR-LV4CQN48PC6/I5
6
+ //Device: GW1NSR-4C
7
+ //Created Time: Sun Aug 20 22:10:09 2023
8
+
9
+ module Gowin_PLLVR (clkout, lock, reset, clkin);
10
+
11
+ output clkout;
12
+ output lock;
13
+ input reset;
14
+ input clkin;
15
+
16
+ wire clkoutp_o;
17
+ wire clkoutd_o;
18
+ wire clkoutd3_o;
19
+ wire gw_vcc;
20
+ wire gw_gnd;
21
+
22
+ assign gw_vcc = 1'b1;
23
+ assign gw_gnd = 1'b0;
24
+
25
+ PLLVR pllvr_inst (
26
+ .CLKOUT(clkout),
27
+ .LOCK(lock),
28
+ .CLKOUTP(clkoutp_o),
29
+ .CLKOUTD(clkoutd_o),
30
+ .CLKOUTD3(clkoutd3_o),
31
+ .RESET(reset),
32
+ .RESET_P(gw_gnd),
33
+ .CLKIN(clkin),
34
+ .CLKFB(gw_gnd),
35
+ .FBDSEL({gw_gnd,gw_gnd,gw_gnd,gw_gnd,gw_gnd,gw_gnd}),
36
+ .IDSEL({gw_gnd,gw_gnd,gw_gnd,gw_gnd,gw_gnd,gw_gnd}),
37
+ .ODSEL({gw_gnd,gw_gnd,gw_gnd,gw_gnd,gw_gnd,gw_gnd}),
38
+ .PSDA({gw_gnd,gw_gnd,gw_gnd,gw_gnd}),
39
+ .DUTYDA({gw_gnd,gw_gnd,gw_gnd,gw_gnd}),
40
+ .FDLY({gw_gnd,gw_gnd,gw_gnd,gw_gnd}),
41
+ .VREN(gw_vcc)
42
+ );
43
+
44
+ defparam pllvr_inst.FCLKIN = "27";
45
+ defparam pllvr_inst.DYN_IDIV_SEL = "false";
46
+ defparam pllvr_inst.IDIV_SEL = 7;
47
+ defparam pllvr_inst.DYN_FBDIV_SEL = "false";
48
+ defparam pllvr_inst.FBDIV_SEL = 36;
49
+ defparam pllvr_inst.DYN_ODIV_SEL = "false";
50
+ defparam pllvr_inst.ODIV_SEL = 8;
51
+ defparam pllvr_inst.PSDA_SEL = "0000";
52
+ defparam pllvr_inst.DYN_DA_EN = "true";
53
+ defparam pllvr_inst.DUTYDA_SEL = "1000";
54
+ defparam pllvr_inst.CLKOUT_FT_DIR = 1'b1;
55
+ defparam pllvr_inst.CLKOUTP_FT_DIR = 1'b1;
56
+ defparam pllvr_inst.CLKOUT_DLY_STEP = 0;
57
+ defparam pllvr_inst.CLKOUTP_DLY_STEP = 0;
58
+ defparam pllvr_inst.CLKFB_SEL = "internal";
59
+ defparam pllvr_inst.CLKOUT_BYPASS = "false";
60
+ defparam pllvr_inst.CLKOUTP_BYPASS = "false";
61
+ defparam pllvr_inst.CLKOUTD_BYPASS = "false";
62
+ defparam pllvr_inst.DYN_SDIV_SEL = 2;
63
+ defparam pllvr_inst.CLKOUTD_SRC = "CLKOUT";
64
+ defparam pllvr_inst.CLKOUTD3_SRC = "CLKOUT";
65
+ defparam pllvr_inst.DEVICE = "GW1NSR-4C";
66
+
67
+ endmodule //Gowin_PLLVR
WangXuan95_FPGA-HDMI/fpga_example/RTL/gowin_pllvr/gowin_pllvr_tmp.v ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //Copyright (C)2014-2023 Gowin Semiconductor Corporation.
2
+ //All rights reserved.
3
+ //File Title: Template file for instantiation
4
+ //GOWIN Version: V1.9.8.11
5
+ //Part Number: GW1NSR-LV4CQN48PC6/I5
6
+ //Device: GW1NSR-4C
7
+ //Created Time: Sun Aug 20 22:10:09 2023
8
+
9
+ //Change the instance name and port connections to the signal names
10
+ //--------Copy here to design--------
11
+
12
+ Gowin_PLLVR your_instance_name(
13
+ .clkout(clkout_o), //output clkout
14
+ .lock(lock_o), //output lock
15
+ .reset(reset_i), //input reset
16
+ .clkin(clkin_i) //input clkin
17
+ );
18
+
19
+ //--------Copy end-------------------
WangXuan95_FPGA-HDMI/fpga_example/RTL/pixel_generate.v ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ //--------------------------------------------------------------------------------------------------------
3
+ // Module : pixel_generate
4
+ // Type : synthesizable
5
+ // Standard: Verilog 2001 (IEEE1364-2001)
6
+ // Function: generate green->purple scroll bars to test hdmi_tx_top.v
7
+ //--------------------------------------------------------------------------------------------------------
8
+
9
+ module pixel_generate # (
10
+ // the parameter of request to response latency ---------------------------------------
11
+ parameter RESP_LATENCY = 1 // 1, 2, or 3
12
+ ) (
13
+ // user's clock -----------------------------------------------------------------------
14
+ input wire clk,
15
+ // user's pixel request interface (these signals synchronize with clk) ----------------
16
+ input wire req_en,
17
+ input wire req_sof,
18
+ input wire req_sol,
19
+ // user's pixel response interface (these signals synchronize with clk) ---------------
20
+ output wire [7:0] resp_red,
21
+ output wire [7:0] resp_green,
22
+ output wire [7:0] resp_blue
23
+ );
24
+
25
+
26
+ reg [7:0] nrow;
27
+ reg [7:0] nframe = 8'h0;
28
+
29
+ reg [7:0] resp1_red, resp1_green, resp1_blue;
30
+ reg [7:0] resp2_red, resp2_green, resp2_blue;
31
+ reg [7:0] resp3_red, resp3_green, resp3_blue;
32
+
33
+
34
+ generate
35
+ if (RESP_LATENCY <= 1) assign {resp_red, resp_green, resp_blue} = {resp1_red, resp1_green, resp1_blue};
36
+ else if (RESP_LATENCY == 2) assign {resp_red, resp_green, resp_blue} = {resp2_red, resp2_green, resp2_blue};
37
+ else assign {resp_red, resp_green, resp_blue} = {resp3_red, resp3_green, resp3_blue};
38
+ endgenerate
39
+
40
+
41
+ always @ (posedge clk)
42
+ if (req_en) begin
43
+ if (req_sof) begin
44
+ nrow <= nframe + 8'd1;
45
+ nframe <= nframe + 8'd1;
46
+ resp1_red <= nframe;
47
+ resp1_green <= 8'hFF - nframe;
48
+ resp1_blue <= nframe;
49
+ end else if (req_sol) begin
50
+ nrow <= nrow + 8'h1;
51
+ resp1_red <= nrow;
52
+ resp1_green <= 8'hFF - nrow;
53
+ resp1_blue <= nrow;
54
+ end else begin
55
+ resp1_red <= resp1_red + 8'h1;
56
+ resp1_green <= resp1_green - 8'h1;
57
+ resp1_blue <= resp1_blue + 8'h1;
58
+ end
59
+ end
60
+
61
+
62
+ always @ (posedge clk) begin
63
+ {resp2_red, resp2_green, resp2_blue} <= {resp1_red, resp1_green, resp1_blue};
64
+ {resp3_red, resp3_green, resp3_blue} <= {resp2_red, resp2_green, resp2_blue};
65
+ end
66
+
67
+
68
+ endmodule
69
+
WangXuan95_FPGA-HDMI/fpga_example/readme.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ This example can run on (but not only on) Tang-Nano-4K FPGA board,
2
+ see https://wiki.sipeed.com/hardware/zh/tang/Tang-Nano-4K
WangXuan95_FPGA-HDMI/fpga_example/top.sdc ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+
2
+ create_clock -name clk27 -period 37.037 [get_ports {clk}]
3
+
4
+ create_clock -name clk125 -period 8.000 [get_pins {u_pll/pllvr_inst/CLKOUT}]
5
+
6
+ set_clock_groups -asynchronous -group {clk27} -group {clk125}