-
Notifications
You must be signed in to change notification settings - Fork 1
/
vgac.v
74 lines (74 loc) · 2.91 KB
/
vgac.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 00:27:04 01/02/2016
// Design Name:
// Module Name: vgac
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module vgac (vga_clk,clrn,d_in,row_addr,col_addr,rdn,r,g,b,hs,vs); // vgac
input [11:0] d_in; // bbbb_gggg_rrrr, pixel
input vga_clk; // 25MHz
input clrn;
output reg [8:0] row_addr; // pixel ram row address, 480 (512) lines
output reg [9:0] col_addr; // pixel ram col address, 640 (1024) pixels
output reg [3:0] r,g,b; // red, green, blue colors
output reg rdn; // read pixel RAM (active_low)
output reg hs,vs; // horizontal and vertical synchronization
// h_count: VGA horizontal counter (0-799)
reg [9:0] h_count; // VGA horizontal counter (0-799): pixels
always @ (posedge vga_clk) begin
if (!clrn) begin
h_count <= 10'h0;
end else if (h_count == 10'd799) begin
h_count <= 10'h0;
end else begin
h_count <= h_count + 10'h1;
end
end
// v_count: VGA vertical counter (0-524)
reg [9:0] v_count; // VGA vertical counter (0-524): lines
always @ (posedge vga_clk or negedge clrn) begin
if (!clrn) begin
v_count <= 10'h0;
end else if (h_count == 10'd799) begin
if (v_count == 10'd524) begin
v_count <= 10'h0;
end else begin
v_count <= v_count + 10'h1;
end
end
end
// signals, will be latched for outputs
wire [9:0] row = v_count - 10'd35; // pixel ram row addr
wire [9:0] col = h_count - 10'd143; // pixel ram col addr
wire h_sync = (h_count > 10'd95); // 96 -> 799
wire v_sync = (v_count > 10'd1); // 2 -> 524
wire read = (h_count > 10'd142) && // 143 -> 782
(h_count < 10'd783) && // 640 pixels
(v_count > 10'd34) && // 35 -> 514
(v_count < 10'd515); // 480 lines
// vga signals
always @ (posedge vga_clk) begin
row_addr <= row[8:0]; // pixel ram row address
col_addr <= col; // pixel ram col address
rdn <= ~read; // read pixel (active low)
hs <= h_sync; // horizontal synchronization
vs <= v_sync; // vertical synchronization
r <= rdn ? 4'h0 : d_in[3:0]; // 4-bit red
g <= rdn ? 4'h0 : d_in[7:4]; // 4-bit green
b <= rdn ? 4'h0 : d_in[11:8]; // 4-bit blue
end
endmodule