forked from nikkatsa7/SpaceInvadersFpgaGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hsync.v
60 lines (53 loc) · 970 Bytes
/
hsync.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
module horizontal(clk,rst,haddr,hsync,display_area);
input clk,rst;
output reg [9:0] haddr; //mapped address
reg divide_counter; //1/5 divider
reg [10:0] counter;
output reg display_area;
output hsync;
always@(posedge clk or posedge rst)
begin
if(rst)
begin
counter = 11'b0;
end
else
begin
if(counter == 11'b110_0011_1111)//1599
begin
counter = 11'b00;
end
else
begin
counter = counter + 1'b1;
end
end
end
assign hsync = (counter < 11'b000_1100_0000)? 0 : 1;//192
always@(posedge clk or posedge rst)
begin
if(rst)
begin
divide_counter <= 0;
haddr <= 7'b0;
display_area <= 0;
end
else
begin
if((counter > 11'd289) && (counter < 11'd1568))//rgb up
begin
display_area <= 1'b1;
divide_counter <= divide_counter + 1'b1;
if(divide_counter == 0)begin
haddr <= haddr + 1'b1;
end
end
else
begin
haddr = 7'b0;
divide_counter <= 0;
display_area <= 0;
end
end
end
endmodule