OpenCores
URL https://opencores.org/ocsvn/othellogame/othellogame/trunk

Subversion Repositories othellogame

[/] [othellogame/] [trunk/] [rtl/] [hvsync_gen.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 marius_mtm
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Company: 
4
// Engineer: 
5
// 
6
// Create Date:    18:01:50 04/13/2009 
7
// Design Name:    HV sync generator
8
// Module Name:    hvsync_gen 
9
// Project Name:   The FPGA Othello Game
10
// Target Devices: Spartan3E
11
// Tool versions: 
12
// Description: 
13
//                           designed for 640x480@60Hz
14
// Dependencies: 
15
//
16
// Revision: 
17
// Revision 0.01 - File Created
18
// Additional Comments: 
19
//    it works, using 50MHz clock
20
// Marius TIVADAR.
21
//
22
//////////////////////////////////////////////////////////////////////////////////
23
module hvsync_gen(
24
                        clk,
25
                        h_sync,
26
                        v_sync,
27
                        wcntX,
28
                        wcntY
29
                 );
30
 
31
 
32
/* input clock */
33
input clk;
34
 
35
/* output h_sync */
36
output h_sync;
37
/* output v_sync */
38
output v_sync;
39
/* output X pixel cnt */
40
output [9:0] wcntX;
41
/* output Y pixel cnt */
42
output [8:0] wcntY;
43
 
44
/* 25.175 MHz pixel clock */
45
parameter PIXEL_CLOCK = 25;
46
 
47
/* ~50Mhz global clock frequency */
48
parameter GLOBAL_CLOCK = 50;
49
 
50
/* clock frequency not equal with pixel clock, so we multiply the parameters */
51
parameter MULT_FACTOR = GLOBAL_CLOCK / PIXEL_CLOCK;
52
 
53
parameter VGA_H_SYNC_PULSE  = 96 * MULT_FACTOR;
54
parameter VGA_H_FRONT_PORCH = 16 * MULT_FACTOR;
55
parameter VGA_H_BACK_PORCH  = 48 * MULT_FACTOR;
56
parameter VGA_H_PIXEL_COUNT = 800 * MULT_FACTOR;
57
 
58
parameter VGA_V_SYNC_PULSE  = 2;
59
parameter VGA_V_FRONT_PORCH = 10;
60
parameter VGA_V_BACK_PORCH  = 33;
61
parameter VGA_V_LINE_COUNT  = 525;
62
 
63
/* internal registers for H/V sync */
64
reg vga_HS;
65
reg vga_VS;
66
 
67
/* internal counters */
68
reg [10:0] cntX;
69
reg [9:0]  cntY;
70
 
71
/* window counters, H visible area: 640, V visible area: 480 */
72
reg [9:0] wcntX;
73
reg [8:0] wcntY;
74
 
75
wire cntXmaxed = (cntX == VGA_H_PIXEL_COUNT - 1);
76
wire cntYmaxed = (cntY == VGA_V_LINE_COUNT - 1);
77
 
78
/* update counters*/
79
always @(posedge clk) begin
80
        if(cntYmaxed) begin
81
                         cntY <= 0;
82
                        wcntY <= 0;
83
        end
84
 
85
        if(cntXmaxed) begin
86
             cntX <= 0;
87
                  cntY <= cntY + 1;
88
                 wcntX <= 0;
89
 
90
                 if (   (cntY > VGA_V_SYNC_PULSE + VGA_V_FRONT_PORCH)
91
                          && (cntY < VGA_V_LINE_COUNT - VGA_V_BACK_PORCH)
92
                                )
93
                 begin
94
                     wcntY <= wcntY + 1;
95
                 end
96
 
97
        end
98
        else begin
99
                 if (   (cntX[10:0] > VGA_H_SYNC_PULSE + VGA_H_FRONT_PORCH)
100
                          && (cntX[10:0] < VGA_H_PIXEL_COUNT  - VGA_H_BACK_PORCH)
101
                          && (cntX[0] == 0)  // count 2 by 2 (because global clock is 2*pixel_clock)
102
                         )
103
                  begin
104
                                wcntX <= wcntX + 1;
105
                  end
106
 
107
                  cntX <= cntX + 1;
108
        end
109
 
110
end
111
 
112
/* generate HS and VS */
113
always @(posedge clk)
114
begin
115
        vga_HS <= (cntX[10:0] < VGA_H_SYNC_PULSE);
116
        vga_VS <= (cntY[9:0] < VGA_V_SYNC_PULSE);
117
end
118
 
119
/* polarity negative */
120
assign h_sync = ~vga_HS;
121
assign v_sync = ~vga_VS;
122
 
123
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.