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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64/] [rtl/] [bench/] [soc/] [video/] [HVCounter.v] - Blame information for rev 46

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//      2011  Robert Finch
4
//      robfinch@<remove>sympatico.ca
5
//
6
// HVCounter.v
7
// Horizontal / Vertical counter:
8
//
9
//
10
// This source file is free software: you can redistribute it and/or modify 
11
// it under the terms of the GNU Lesser General Public License as published 
12
// by the Free Software Foundation, either version 3 of the License, or     
13
// (at your option) any later version.                                      
14
//                                                                          
15
// This source file is distributed in the hope that it will be useful,      
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
18
// GNU General Public License for more details.                             
19
//                                                                          
20
// You should have received a copy of the GNU General Public License        
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
22
//                                                                          
23
// ============================================================================
24
 
25
// horizontal pixel prescale counter
26
// Each pixel may be multiple clocks wide
27
//
28
// 37 slices / 64 LUTs / 161.525 MHz
29
// 28 ff's / 1 Mult
30
 
31
module HVCounter(
32
        rst, vclk, pixcce, sync, cnt_offs, pixsz, maxpix, nxt_pix, pos, nxt_pos, ctr
33
);
34
input rst;
35
input vclk;                             // video clock
36
input pixcce;                   // pixel counter clock enable
37
input sync;                             // synchronization input (eol or eof)
38
input [11:0] cnt_offs;   // counter offset: top or left of display area
39
input [3:0] pixsz;               // size of a pixel in video clock
40
input [4:0] maxpix;              // maximum pixels for width / height of character
41
output nxt_pix;                 // when the next pixel will happen
42
output [11:0] pos;               // current row or column position
43
output nxt_pos;                 // flag: when the row or column is about to change
44
output [11:0] ctr;               // counter output
45
 
46
reg [11:0] pos;
47
reg [11:0] ctr;
48
reg nxt_pix;
49
 
50
wire [11:0] ctr1;
51
wire nxp;
52
reg [23:0] x4096;
53
wire pe_sync;
54
 
55
// Lookup reciprocal of number of pixels per character
56
// - used to calculate the column position
57
reg [11:0] inv;
58
always @(posedge vclk)
59
        case(maxpix)
60
        5'd00:  inv <= 12'd4095;
61
        5'd01:  inv <= 12'd2048;
62
        5'd02:  inv <= 12'd1365;
63
        5'd03:  inv <= 12'd1024;
64
        5'd04:  inv <= 12'd0819;
65
        5'd05:  inv <= 12'd0683;
66
        5'd06:  inv <= 12'd0585;
67
        5'd07:  inv <= 12'd0512;
68
        5'd08:  inv <= 12'd0455;
69
        5'd09:  inv <= 12'd0409;
70
        5'd10:  inv <= 12'd0372;
71
        5'd11:  inv <= 12'd0341;
72
        5'd12:  inv <= 12'd0315;
73
        5'd13:  inv <= 12'd0292;
74
        5'd14:  inv <= 12'd0273;
75
        5'd15:  inv <= 12'd0256;
76
        5'd16:  inv <= 12'd0240;
77
        5'd17:  inv <= 12'd0227;
78
        5'd18:  inv <= 12'd0215;
79
        5'd19:  inv <= 12'd0204;
80
        5'd20:  inv <= 12'd0195;
81
        5'd21:  inv <= 12'd0186;
82
        5'd22:  inv <= 12'd0178;
83
        5'd23:  inv <= 12'd0170;
84
        5'd24:  inv <= 12'd0163;
85
        5'd25:  inv <= 12'd0157;
86
        5'd26:  inv <= 12'd0151;
87
        5'd27:  inv <= 12'd0146;
88
        5'd28:  inv <= 12'd0141;
89
        5'd29:  inv <= 12'd0136;
90
        5'd30:  inv <= 12'd0132;
91
        5'd31:  inv <= 12'd0128;
92
        endcase
93
 
94
 
95
// Calculate character position
96
// - divide the raw count by the number of pixels per character
97
// - done by multiplying by the reciprocal
98
always @(posedge vclk)
99
        x4096 <= ctr * inv;
100
always @(x4096)
101
        pos <= x4096[23:12];
102
always @(posedge vclk)          // pipeline delay
103
        ctr <= ctr1;
104
always @(posedge vclk)
105
        nxt_pix <= nxp;
106
 
107
edge_det u4
108
(
109
        .rst(rst),
110
        .clk(vclk),
111
        .ce(1'b1),
112
        .i(sync),
113
        .pe(pe_sync),
114
        .ne(),
115
        .ee()
116
);
117
 
118
// Pixel width counter
119
// Controls number of clock cycles per pixel
120
VT163 #(4) u1
121
(
122
        .clk(vclk),
123
        .clr_n(!rst),
124
        .ent(pixcce),
125
        .enp(1'b1),
126
        .ld_n(!pe_sync & !nxp),         // synchronize count to start of scan
127
        .d(4'hF-pixsz),
128
        .q(),
129
        .rco(nxp)
130
);
131
 
132
 
133
// Pixel counter
134
// - raw pixel count
135
// - just increments every time the nxt_pix signal is active
136
// - synchronized to the end-of-line or end-of-frame signal
137
VT163 #(12) u2
138
(
139
        .clk(vclk),
140
        .clr_n(!rst),
141
        .ent(nxp),
142
        .enp(1'b1),
143
        .ld_n(!pe_sync),                                        // synchronize count to start of scan
144
        .d(12'h000-cnt_offs),
145
        .q(ctr1),
146
        .rco()
147
);
148
 
149
 
150
// Detect when the position changes
151
// - compare current pos to previous pos when the position might change
152
change_det #(12) u3
153
(
154
        .rst(rst),
155
        .clk(vclk),
156
        .ce(nxt_pix),
157
        .i(pos),
158
        .cd(nxt_pos)
159
);
160
 
161
endmodule

powered by: WebSVN 2.1.0

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