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

Subversion Repositories rtftextcontroller

[/] [rtftextcontroller/] [trunk/] [rtl/] [verilog/] [HVCounter.v] - Blame information for rev 32

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 robfinch
// HVCounter.v
2
// Horizontal / Vertical counter:
3
//
4
// horizontal pixel prescale counter
5
// Each pixel may be multiple clocks wide
6
//
7
// 37 slices / 64 LUTs / 161.525 MHz
8
// 28 ff's / 1 Mult
9
 
10
module HVCounter(
11
        rst, vclk, pixcce, sync, cnt_offs, pixsz, maxpix, nxt_pix, pos, nxt_pos, ctr
12
);
13
input rst;
14
input vclk;                             // video clock
15
input pixcce;                   // pixel counter clock enable
16
input sync;                             // synchronization input (eol or eof)
17
input [11:0] cnt_offs;   // counter offset: top or left of display area
18
input [3:0] pixsz;               // size of a pixel in video clock
19
input [4:0] maxpix;              // maximum pixels for width / height of character
20
output nxt_pix;                 // when the next pixel will happen
21
output [11:0] pos;               // current row or column position
22
output nxt_pos;                 // flag: when the row or column is about to change
23
output [11:0] ctr;               // counter output
24
 
25
reg [11:0] pos;
26
reg [11:0] ctr;
27
reg nxt_pix;
28
 
29
wire [11:0] ctr1;
30
wire nxp;
31
reg [23:0] x4096;
32
 
33
// Lookup reciprocal of number of pixels per character
34
// - used to calculate the column position
35
reg [11:0] inv;
36
always @(posedge vclk)
37
        case(maxpix)
38
        5'd00:  inv <= 12'd4095;
39
        5'd01:  inv <= 12'd2048;
40
        5'd02:  inv <= 12'd1365;
41
        5'd03:  inv <= 12'd1024;
42
        5'd04:  inv <= 12'd0819;
43
        5'd05:  inv <= 12'd0683;
44
        5'd06:  inv <= 12'd0585;
45
        5'd07:  inv <= 12'd0512;
46
        5'd08:  inv <= 12'd0455;
47
        5'd09:  inv <= 12'd0409;
48
        5'd10:  inv <= 12'd0372;
49
        5'd11:  inv <= 12'd0341;
50
        5'd12:  inv <= 12'd0315;
51
        5'd13:  inv <= 12'd0292;
52
        5'd14:  inv <= 12'd0273;
53
        5'd15:  inv <= 12'd0256;
54
        5'd16:  inv <= 12'd0240;
55
        5'd17:  inv <= 12'd0227;
56
        5'd18:  inv <= 12'd0215;
57
        5'd19:  inv <= 12'd0204;
58
        5'd20:  inv <= 12'd0195;
59
        5'd21:  inv <= 12'd0186;
60
        5'd22:  inv <= 12'd0178;
61
        5'd23:  inv <= 12'd0170;
62
        5'd24:  inv <= 12'd0163;
63
        5'd25:  inv <= 12'd0157;
64
        5'd26:  inv <= 12'd0151;
65
        5'd27:  inv <= 12'd0146;
66
        5'd28:  inv <= 12'd0141;
67
        5'd29:  inv <= 12'd0136;
68
        5'd30:  inv <= 12'd0132;
69
        5'd31:  inv <= 12'd0128;
70
        endcase
71
 
72
 
73
// Calculate character position
74
// - divide the raw count by the number of pixels per character
75
// - done by multiplying by the reciprocal
76
always @(posedge vclk)
77
        x4096 <= ctr * inv;
78
always @(x4096)
79
        pos <= x4096[23:12];
80
always @(posedge vclk)          // pipeline delay
81
        ctr <= ctr1;
82
always @(posedge vclk)
83
        nxt_pix <= nxp;
84
 
85
// Pixel width counter
86
// Controls number of clock cycles per pixel
87
VT163 #(4) u1
88
(
89
        .clk(vclk),
90
        .clr_n(!rst),
91
        .ent(pixcce),
92
        .enp(1'b1),
93
        .ld_n(!sync & !nxp),            // synchronize count to start of scan
94
        .d(4'hF-pixsz),
95
        .q(),
96
        .rco(nxp)
97
);
98
 
99
 
100
// Pixel counter
101
// - raw pixel count
102
// - just increments every time the nxt_pix signal is active
103
// - synchronized to the end-of-line or end-of-frame signal
104
VT163 #(12) u2
105
(
106
        .clk(vclk),
107
        .clr_n(!rst),
108
        .ent(nxp),
109
        .enp(1'b1),
110
        .ld_n(!sync),                                   // synchronize count to start of scan
111
        .d(12'h000-cnt_offs),
112
        .q(ctr1),
113
        .rco()
114
);
115
 
116
 
117
// Detect when the position changes
118
// - compare current pos to previous pos when the position might change
119
change_det #(12) u3
120
(
121
        .rst(rst),
122
        .clk(vclk),
123
        .ce(nxt_pix),
124
        .i(pos),
125
        .cd(nxt_pos)
126
);
127
 
128
endmodule

powered by: WebSVN 2.1.0

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