-
Notifications
You must be signed in to change notification settings - Fork 4
/
ov7670_registers.v
331 lines (253 loc) · 15.2 KB
/
ov7670_registers.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
// VHDL code: http://hamsterworks.co.nz/mediawiki/index.php/OV7670_camera
//
// Description: Register settings for the OV7670 Caamera (partially from OV7670.c
// in the Linux Kernel
//
module ov7670_registers(
input clk, //: in STD_LOGIC;
input resend, //: in STD_LOGIC;
input advance, //: in STD_LOGIC;
output [15:0] command, //: out std_logic_vector(15 downto 0);
output finished //: out STD_LOGIC
);
reg [15:0] sreg; // : std_logic_vector(15 downto 0);
reg [8:0] address = 'h0; //: std_logic_vector(7 downto 0) := (others => '0');
reg r_resend_old = 0;
always@(posedge clk) begin
r_resend_old <= resend;
end
always@(posedge clk) begin
if (r_resend_old == 1 && resend == 0 ) begin
address <= 'h0;
end
else if (advance == 1) begin
address <= address + 1;
end
case (address)
// // new settings
// 8'h00 : sreg <= 16'h1280; // COM7 Reset
// 8'h01 : sreg <= 16'h1280; // COM7 Reset
// 8'h02 : sreg <= 16'h1204; // COM7 Size & RGB output
// 8'h03 : sreg <= 16'h1100; // CLKRC Prescaler - Fin/(1+1)
// 8'h04 : sreg <= 16'h0C00; // COM3 Lots of stuff, enable scaling, all others off
// 8'h05 : sreg <= 16'h3E00; // COM14 PCLK scaling off
// 8'h06 : sreg <= 16'h8C00; // RGB444 Set RGB format
// 8'h07 : sreg <= 16'h0400; // COM1 no CCIR601
// 8'h08 : sreg <= 16'h4010; // COM15 Full 0-255 output, RGB 565
// 8'h09 : sreg <= 16'h3a04; // TSLB Set UV ordering, do not auto-reset window
// 8'h0A : sreg <= 16'h1438; // COM9 - AGC Celling
// 8'h0B : sreg <= 16'h4fb3; // MTX1 - colour conversion matrix
// 8'h0C : sreg <= 16'h50b3; // MTX2 - colour conversion matrix
// 8'h0D : sreg <= 16'h5100; // MTX3 - colour conversion matrix
// 8'h0E : sreg <= 16'h523d; // MTX4 - colour conversion matrix
// 8'h0F : sreg <= 16'h53a7; // MTX5 - colour conversion matrix
// 8'h10 : sreg <= 16'h54e4; // MTX6 - colour conversion matrix
// 8'h11 : sreg <= 16'h589e; // MTXS - Matrix sign and auto contrast
// 8'h12 : sreg <= 16'h3dc0; // COM13 - Turn on GAMMA and UV Auto adjust
// 8'h13 : sreg <= 16'h1100; // CLKRC Prescaler - Fin/(1+1)
// 8'h14 : sreg <= 16'h1713; // HSTART HREF start (high 8 bits)
// 8'h15 : sreg <= 16'h1801; // HSTOP HREF stop (high 8 bits)
// 8'h16 : sreg <= 16'h32b6; // HREF Edge offset and low 3 bits of HSTART and HSTOP
// 8'h17 : sreg <= 16'h1902; // VSTART VSYNC start (high 8 bits)
// 8'h18 : sreg <= 16'h1A7a; // VSTOP VSYNC stop (high 8 bits)
// 8'h19 : sreg <= 16'h030a; // VREF VSYNC low two bits
// 8'h1A : sreg <= 16'h0e61; // COM5(0x0E) 0x61
// 8'h1B : sreg <= 16'h0f4b; // COM6(0x0F) 0x4B
// 8'h1C : sreg <= 16'h1602; //
// 8'h1D : sreg <= 16'h1e37; // MVFP (0x1E) 0x07 -- FLIP AND MIRROR IMAGE 0x3x
// 8'h1E : sreg <= 16'h2102;
// 8'h1F : sreg <= 16'h2291;
// 8'h20 : sreg <= 16'h2907;
// 8'h21 : sreg <= 16'h330b;
// 8'h22 : sreg <= 16'h350b;
// 8'h23 : sreg <= 16'h371d;
// 8'h24 : sreg <= 16'h3871;
// 8'h25 : sreg <= 16'h392a;
// 8'h26 : sreg <= 16'h3c78; // COM12 (0x3C) 0x78
// 8'h27 : sreg <= 16'h4d40;
// 8'h28 : sreg <= 16'h4e20;
// 8'h29 : sreg <= 16'h6900; // GFIX (0x69) 0x00
// 8'h2A : sreg <= 16'h6b4a;
// 8'h2B : sreg <= 16'h7410;
// 8'h2C : sreg <= 16'h8d4f;
// 8'h2D : sreg <= 16'h8e00;
// 8'h2E : sreg <= 16'h8f00;
// 8'h2F : sreg <= 16'h9000;
// 8'h30 : sreg <= 16'h9100;
// 8'h31 : sreg <= 16'h9600;
// 8'h32 : sreg <= 16'h9a00;
// 8'h33 : sreg <= 16'hb084;
// 8'h34 : sreg <= 16'hb10c;
// 8'h35 : sreg <= 16'hb20e;
// 8'h36 : sreg <= 16'hb382;
// 8'h37 : sreg <= 16'hb80a;
// // settings added by me
// 8'h38 : sreg <= 16'h13e7; // enable AWB from sw aplication notes
// 8'h39 : sreg <= 16'h6f9f; // Simple White Balance from sw aplication notes
// 8'h40 : sreg <= 16'h411A; // De-noise auto-adjustment + AWB gain enable + Color matrix coefficient double option 0: Original matrix
// 8'h41 : sreg <= 16'h7700; // Register 77 Bit[7:0]:Offset, de-noise range control
// // old settings
8'd00 : sreg <= 16'h1280; // COM7 Reset
8'd01 : sreg <= 16'h1280; // COM7 Reset
8'd02 : sreg <= 16'h1204; // COM7 Size & RGB output
8'd03 : sreg <= 16'h1100; // CLKRC Prescaler - Fin/(1+1)
8'd04 : sreg <= 16'h0C00; // COM3 Lots of stuff, enable scaling, all others off
8'd05 : sreg <= 16'h3E00; // COM14 PCLK scaling off
8'd06 : sreg <= 16'h8C00; // RGB444 Set RGB format
8'd07 : sreg <= 16'h0400; // COM1 no CCIR601
8'd08 : sreg <= 16'h4010; // COM15 Full 0-255 output, RGB 565
8'd09 : sreg <= 16'h3a04; // TSLB Set UV ordering, do not auto-reset window
8'd10 : sreg <= 16'h1438; // COM9 - AGC Celling
8'd11 : sreg <= 16'h4fb3; // MTX1 - colour conversion matrix
8'd12 : sreg <= 16'h50b3; // MTX2 - colour conversion matrix
8'd13 : sreg <= 16'h5100; // MTX3 - colour conversion matrix
8'd14 : sreg <= 16'h523d; // MTX4 - colour conversion matrix
8'd15 : sreg <= 16'h53a7; // MTX5 - colour conversion matrix
8'd16 : sreg <= 16'h54e4; // MTX6 - colour conversion matrix
8'd17 : sreg <= 16'h581e; // 16'h589e; // MTXS - Matrix sign and auto contrast
8'd18 : sreg <= 16'h3dc0; // COM13 - Turn on GAMMA and UV Auto adjust
8'd19 : sreg <= 16'h1713; // HSTART HREF start (high 8 bits)
8'd20 : sreg <= 16'h1801; // HSTOP HREF stop (high 8 bits)
8'd21 : sreg <= 16'h32b6; // HREF Edge offset and low 3 bits of HSTART and HSTOP
8'd22 : sreg <= 16'h1902; // VSTART VSYNC start (high 8 bits)
8'd23 : sreg <= 16'h1A7a; // VSTOP VSYNC stop (high 8 bits)
8'd24 : sreg <= 16'h030a; // VREF VSYNC low two bits
//
// 8'd26 : sreg <= 16'h0e61; // COM5(0x0E) 0x61
// 8'd27 : sreg <= 16'h0f4b; // COM6(0x0F) 0x4B
// 8'd28 : sreg <= 16'h1602; //
// 8'd29 : sreg <= 16'h1e37; // MVFP (0x1E) 0x07 // FLIP AND MIRROR IMAGE 0x3x
// 8'd30 : sreg <= 16'h2102;
// 8'd31 : sreg <= 16'h2291;
// 8'd32 : sreg <= 16'h2907;
// 8'd33 : sreg <= 16'h330b;
// 8'd34 : sreg <= 16'h350b;
// 8'd35 : sreg <= 16'h371d;
// 8'd36 : sreg <= 16'h3871;
// 8'd37 : sreg <= 16'h392a;
// 8'd26 : sreg <= 16'h3c78;
//
// 8'd38 : sreg <= 16'h3c78; // COM12 (0x3C) 0x78
// 8'd39 : sreg <= 16'h4d40;
// 8'd40 : sreg <= 16'h4e20;
// 8'd41 : sreg <= 16'h6900; // GFIX (0x69) 0x00
// 8'd42 : sreg <= 16'h6b4a;
// 8'd43 : sreg <= 16'h7410;
// 8'd44 : sreg <= 16'h8d4f;
// 8'd45 : sreg <= 16'h8e00;
// 8'd26 : sreg <= 16'h8f00;
// 8'd27 : sreg <= 16'h9000;
//
8'd25 : sreg <= 16'h9100;
8'd26 : sreg <= 16'h9600;
8'd27 : sreg <= 16'h9a00;
8'd28 : sreg <= 16'hb084;
8'd29 : sreg <= 16'hb10c;
8'd30 : sreg <= 16'hb20e;
8'd31 : sreg <= 16'hb382;
8'd32 : sreg <= 16'hb80a;
// setings form fpga4students
// 8'd00 : sreg <= 16'h1280; // COM7 Reset
// 8'd01 : sreg <= 16'h1280; // COM7 Reset
// 8'd02 : sreg <= 16'h1206; // COM7 Size & RGB output
// // 8'd03 : sreg <= 16'h1100; // CLKRC Prescaler - Fin/(1+1)
// // 8'd04 : sreg <= 16'h0C00; // COM3 Lots of stuff, enable scaling, all others off
// // 8'h05 : sreg <= 16'h3E00; // COM14 PCLK scaling off
// 8'd06 : sreg <= 16'h8C00; // RGB444 Set RGB format
// // 8'd07 : sreg <= 16'h0400; // COM1 no CCIR601
// // 8'd08 : sreg <= 16'h4010; // COM15 Full 0-255 output, RGB 565
// // 8'd09 : sreg <= 16'h3a04; // TSLB Set UV ordering, do not auto-reset window
// // 8'd10 : sreg <= 16'h1438; // COM9 - AGC Celling
// // // 8'h0B : sreg <= 16'h4fb3; // MTX1 - colour conversion matrix
// // // 8'h0C : sreg <= 16'h50b3; // MTX2 - colour conversion matrix
// // // 8'd11 : sreg <= 16'h5100; // MTX3 - colour conversion matrix
// // // 8'd11 : sreg <= 16'h523d; // MTX4 - colour conversion matrix
// // // 8'h0F : sreg <= 16'h53a7; // MTX5 - colour conversion matrix
// // // 8'h10 : sreg <= 16'h54e4; // MTX6 - colour conversion matrix
// // // 8'd11 : sreg <= 16'h589e; // MTXS - Matrix sign and auto contrast
// // 8'd11 : sreg <= 16'h3dc0; // COM13 - Turn on GAMMA and UV Auto adjust
// // 8'd12 : sreg <= 16'h1100; // CLKRC Prescaler - Fin/(1+1)
// 8'd13 : sreg <= 16'h1713; // HSTART HREF start (high 8 bits)
// 8'd14 : sreg <= 16'h1801; // HSTOP HREF stop (high 8 bits)
// 8'd15 : sreg <= 16'h32b6; // HREF Edge offset and low 3 bits of HSTART and HSTOP
// 8'd16 : sreg <= 16'h1902; // VSTART VSYNC start (high 8 bits)
// 8'd17 : sreg <= 16'h1A7a; // VSTOP VSYNC stop (high 8 bits)
// 8'd18 : sreg <= 16'h030a; // VREF VSYNC low two bits
// // 8'h1A : sreg <= 16'h0e61; // COM5(0x0E) 0x61
// // 8'h1B : sreg <= 16'h0f4b; // COM6(0x0F) 0x4B
// // 8'h1C : sreg <= 16'h1602; //
// // 8'h1D : sreg <= 16'h1e37; // MVFP (0x1E) 0x07 // FLIP AND MIRROR IMAGE 0x3x
// // 8'h1E : sreg <= 16'h2102;
// // 8'h1F : sreg <= 16'h2291;
// // 8'h20 : sreg <= 16'h2907;
// // 8'h21 : sreg <= 16'h330b;
// // 8'h22 : sreg <= 16'h350b;
// // 8'h23 : sreg <= 16'h371d;
// // 8'h24 : sreg <= 16'h3871;
// // 8'h25 : sreg <= 16'h392a;
// // 8'h26 : sreg <= 16'h3c78; // COM12 (0x3C) 0x78
// // 8'h27 : sreg <= 16'h4d40;
// // 8'h28 : sreg <= 16'h4e20;
// // 8'h29 : sreg <= 16'h6900; // GFIX (0x69) 0x00
// // 8'h2A : sreg <= 16'h6b4a;
// // 8'h2B : sreg <= 16'h7410;
// // 8'h2C : sreg <= 16'h8d4f;
// // 8'h2D : sreg <= 16'h8e00;
// // 8'h2E : sreg <= 16'h8f00;
// // 8'h2F : sreg <= 16'h9000;
// // 8'h30 : sreg <= 16'h9100;
// // 8'h31 : sreg <= 16'h9600;
// // 8'h32 : sreg <= 16'h9a00;
// // 8'h33 : sreg <= 16'hb084;
// // 8'h34 : sreg <= 16'hb10c;
// // 8'h35 : sreg <= 16'hb20e;
// // 8'h36 : sreg <= 16'hb382;
// // 8'h37 : sreg <= 16'hb80a;
// // settings added by me
// 8'd19 : sreg <= 16'h13e7; // enable AWB from sw aplication notes
// 8'd20 : sreg <= 16'h6f9f; // Simple White Balance from sw aplication notes
// 8'd21 : sreg <= 16'h411A; // De-noise auto-adjustment + AWB gain enable + Color matrix coefficient double option 0: Original matrix
// 8'd22 : sreg <= 16'h7700; // Register 77 Bit[7:0]:Offset, de-noise range control
// // Saturation + 2
// // i2c_salve_Address = 0x42;
// // write_i2c(0x4f, 0xc0);
// // write_i2c(0x50, 0xc0);
// // write_i2c(0x51, 0x00);
// // write_i2c(0x52, 0x33);
// // write_i2c(0x53, 0x8d);
// // write_i2c(0x54, 0xc0);
// // write_i2c(0x58, 0x9e);
// 8'd23 : sreg <= 16'h4fb3; // MTX1 - colour conversion matrix
// 8'd24 : sreg <= 16'h50b3; // MTX2 - colour conversion matrix
// 8'd25 : sreg <= 16'h5100; // MTX3 - colour conversion matrix
// 8'd26 : sreg <= 16'h523d; // MTX4 - colour conversion matrix
// 8'd27 : sreg <= 16'h53a7; // MTX5 - colour conversion matrix
// 8'd28 : sreg <= 16'h54e4; // MTX6 - colour conversion matrix
// 8'd29 : sreg <= 16'h589e; // MTXS - Matrix sign and auto contrast
// // setings from : http://hamsterworks.co.nz/mediawiki/index.php/OV7670_camera
// 8'h00 : sreg <= 16'h1280; //COM7 Reset
// 8'h01 : sreg <= 16'h1280; //COM7 Reset
// 8'h02 : sreg <= 16'h1100; //CLKRC Prescaler - Fin/(1+1)
// 8'h03 : sreg <= 16'h1204; //COM7 QIF + RGB output
// 8'h04 : sreg <= 16'h0C04; //COM3 Lots of stuff, enable scaling, all others off
// 8'h05 : sreg <= 16'h3E19; //COM14 PCLK scaling = 0
// 8'h06 : sreg <= 16'h4010; //COM15 Full 0-255 output, RGB 565
// 8'h07 : sreg <= 16'h3a04; //TSLB Set UV ordering, do not auto-reset window
// 8'h08 : sreg <= 16'h8C00; //RGB444 Set RGB format
// 8'h09 : sreg <= 16'h1714; //HSTART HREF start (high 8 bits)
// 8'h0a : sreg <= 16'h1802; //HSTOP HREF stop (high 8 bits)
// 8'h0b : sreg <= 16'h32A4; //HREF Edge offset and low 3 bits of HSTART and HSTOP
// 8'h0c : sreg <= 16'h1903; //VSTART VSYNC start (high 8 bits)
// 8'h0d : sreg <= 16'h1A7b; //VSTOP VSYNC stop (high 8 bits)
// 8'h0e : sreg <= 16'h030a; //VREF VSYNC low two bits
// 8'h0f : sreg <= 16'h703a; //SCALING_XSC
// 8'h10 : sreg <= 16'h7135; //SCALING_YSC
// 8'h11 : sreg <= 16'h7211; //SCALING_DCWCTR
// 8'h12 : sreg <= 16'h73f1; //SCALING_PCLK_DIV
// 8'h13 : sreg <= 16'ha202; //SCALING_PCLK_DELAY PCLK scaling = 4, must match COM14
default : sreg <= 16'hffff;
endcase;
end
assign command = sreg;
assign finished = (sreg == 16'hffff) ? 1'b1 : 1'b0;
endmodule