OV2640 Software Application Notes 1.03
OV2640 Software Application Notes 1.03
OV2640 Software Application Notes 1.03
l
ia
e nt
id
nf
Co
T
V
OmniVision Technologies, Inc. reserves the right to make changes without further notice to
any product herein to improve reliability, function or design. OmniVision does not assume
any liability arising out of the application or use of any project, circuit described herein;
neither does it convey any license under its patent nor the right of others.
This document contains information of a proprietary nature. None of this information shall be
divulged to persons other than OmniVision Technologies, Inc. employee authorized by the nature of
their duties to receive such information, or individuals or organizations authorized by OmniVision
Technologies, Inc.
1 Company Confidential
OV2640 Camera Module Software Application Notes
Table of Contents
OV2640 Camera Module..................................................................................................................... 1
Software Application Notes................................................................................................................. 1
1. How to Select Output format?..................................................................................................... 4
1.1 Back-end with full ISP.......................................................................................................... 4
1.2 Back-end with YCbCr ISP.................................................................................................... 5
1.3 Back-end without ISP........................................................................................................... 5
1.4 Equations to Convert from One Format to Another............................................................. 5
2. How to Select Output Resolution?...............................................................................................6
2.1 back-end with ISP................................................................................................................. 6
2.2 back-end without ISP............................................................................................................ 6
3. How to Adjust frame rate.............................................................................................................6
3.1 SVGA Preview, 30fps, 24Mhz input clock...........................................................................6
3.2 SVGA Preview, 15fps, 24 Mhz input clock..........................................................................7
3.3 SVGA Preview, 25fps, 24 Mhz input clock..........................................................................7
l
3.4 SVGA Preview, 14.3fps, 24 Mhz input clock.......................................................................7
ia
3.5 UXGA Capture, 7.5fps, 24 Mhz input clock........................................................................ 7
3.6 UXGA Capture, 7.14fps, 24 Mhz input clock...................................................................... 8
nt
4. How to set Night Mode Preview..................................................................................................8
4.1 Night Mode with Fixed Frame Rate..................................................................................... 8
e
4.2 Night Mode with Auto Frame Rate.......................................................................................8
id
5. How to Remove Light Band in Preview Mode............................................................................9
5.1 Light Band.............................................................................................................................9
nf
8. BLC............................................................................................................................................13
9. Video Mode............................................................................................................................... 13
10. Digital zoom............................................................................................................................ 14
11. OV2640 Functions...................................................................................................................14
11.1 Light Mode........................................................................................................................14
11.2 Color Saturation................................................................................................................ 15
11.3 Brightness..........................................................................................................................16
11.4 Contrast............................................................................................................................. 17
11.5 Special effects................................................................................................................... 18
11.6 YUV Sequence..................................................................................................................20
12. Deal with Lens......................................................................................................................... 21
12.1 Light fall off...................................................................................................................... 21
12.2 Dark corner....................................................................................................................... 21
12.3 Resolution......................................................................................................................... 21
2 Company Confidential
OV2640 Camera Module Software Application Notes
l
14.5.1 Preview......................................................................................................................37
ia
14.5.2 Capture...................................................................................................................... 37
nt
14.6 Auto frame rate................................................................................................................. 37
14.7 Capture Sequence..............................................................................................................37
e
14.7.1 Preview......................................................................................................................37
id
14.7.2 Stop Preview..............................................................................................................38
14.7.3 Calculate Capture Exposure...................................................................................... 38
nf
14.7.6 Capture...................................................................................................................... 41
14.7.7 Back to preview.........................................................................................................41
T
V
O
3 Company Confidential
OV2640 Camera Module Software Application Notes
OV2640 support 4 output format: YcbCr422,YCbCr420, RGB565, Bayer raw RGB and GRB,
YUV422 Compression. How to choose the right output format for camera phone design or other
applications? Let's look at the back-end chip first.
YCbCr X RGB
l
RGB
ia
Bayer raw RGB
nt
Processed raw RGB
Compression Mode e
id
Memory Interface JPEG
nf
The data format at LCD driver are always RGB. For example, RGB444, RGB565, RGB555,
Co
RGB888 etc. The data format and memory interface are always Compression. The Compression
data is compressed from YCbCr data. So Both RGB and YCbCr data are needed inside the back-
end chip. The “X” block is different for different back-end chips.
T
This kind of back-end has full ISP. It takes raw RGB input, doing interpolation to generate
RGB24 and doing translation to generate YCbCr. This kind of back-end could take Bayer raw RGB
or processed raw RGB.
The advantage of processed raw RGB over Bayer raw RGB is the output data are processed.
Sensor functions such as defect pixel correction, lens correction, gamma, color matrix, de-noise,
sharpness, BLC etc. could be applied. Since the life time of back-end chip is longer than image
sensor, sometimes back-end chips could not fix defects of new sensors if taken Bayer raw RGB.
But the defects of new sensors could be fixed in processed raw RGB output.
If back-end take Bayer raw RGB format from sensor, all the image process operations such as
defect pixel correction, lens correction, gamma, color matrix, de-noise, sharpness, BCL etc should
be done by back-end. If back-end take processed raw RGB format from sensor, the image process
operations such as defect pixel correction, lens correction, gamma, color matrix, de-noise,
4 Company Confidential
OV2640 Camera Module Software Application Notes
sharpness, BCL etc could be done either inside sensor or by back-end chips. In other words, user
could select the image process operation be done by which side.
This kind of back-end has ISP, but could take only YCbCr format. The ISP could convert YCbCr
to RGB format for LCD display and compress YCbCr for storage.
This kind of back-end doesn't have ISP built-in. It can not convert from one format to another by
hardware. Actually the format conversion is done by software. There are 3 possible solution for this
kind of back-end chips.
l
ia
a. Sensor output YCbCr. back-end chip convert YCbCr to RGB for display by software.
nt
b. Sensor output RGB565. Back-end chip convert RGB565 to YCbCR for compression.
c. Sensor output RGB565 for preview, output YCbCr for capture ( compression).
e
id
Solution a. provide the best picture quality. Since the input data is 24-bit RGB equivalent. It
could converted to RGB888 for LCD display. Solution b. provide the worst picture quality. Since
nf
the input data is only 16-bit RGB565, even it is converted to YCbCr, the color depth is still 16-bit.
The solution c. provide similar picture quality as solution a. But since preview is RGB565, capture
Co
is YCbCr, preview picture may looks a little different than captured picture.
YCbCr to RGB24
V
RGB24 to YcbCr
R = Y + 1.371(Cr – 128)
G = Y – 0.698(Cr – 128) – 0.336(Cb – 128)
5 Company Confidential
OV2640 Camera Module Software Application Notes
B = Y + 1.732(Cb – 128)
l
ia
nt
2.2 back-end without ISP
e
If back-end chip doesn't have image scale capability, then the LCD scaler of OV2640 must be
id
used to scale output resolution exactly the LCD size. For example, if the LCD size is 176x220, then
the LCD scaler will scale the output size to 176x220.
nf
In this case, OV2640 output small resolution for preview, and several other resolution for
Co
capture. The resolution for capture may include: QQVGA, QVGA, QCIF, CIF, VGA,
SVGA,SXGA,UXGA.
The recommended frame rates are 30fps and 15fps preview for 60Hz light environment, 25fps
and 14.3fps preview for 50Hz light environment. The recommended frame rate for capture is 7.5fps
V
for 60hz light environment and 7.14fps for 50hz light environment. The frame rate for night mode
is lower, we'll discuss night mode later.
O
6 Company Confidential
OV2640 Camera Module Software Application Notes
l
write_SCCB(0x12, 0x40);
ia
write_SCCB(0x2a, 0x00);
nt
write_SCCB(0x2b, 0x00);
write_SCCB(0x46, 0x87); e
write_SCCB(0x47, 0x00);
id
write_SCCB(0x3d, 0x38);
nf
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x01);
write_SCCB(0x11, 0x01);
write_SCCB(0x12, 0x40);
write_SCCB(0x2a, 0x00);
T
write_SCCB(0x2b, 0x00);
V
write_SCCB(0x46, 0x22);
write_SCCB(0x47, 0x00);
O
write_SCCB(0x3d, 0x38);
7 Company Confidential
OV2640 Camera Module Software Application Notes
l
ia
rate is decreased to 3.75fps.
write_SCCB(0x11, 0x07);
Co
3.125fps night mode for 50Hz light environment, 24Mhz clock input
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x01);
write_SCCB(0x11, 0x07);
T
30fps ~ 3.75fps night mode for 60Hz light environment, 24Mhz clock input
O
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x01);
write_SCCB(0x11, 0x00);
write_SCCB(0x0f, 0x4b);
write_SCCB(0x03, 0xcf);
15fps ~ 3.75fps night mode for 60Hz light environment, 24Mhz clock input
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x01);
write_SCCB(0x11, 0x01);
write_SCCB(0x0f, 0x4b);
write_SCCB(0x03, 0x8f);
25fps ~ 3.125fps night mode for 50Hz light environment, 24Mhz clock input
SCCB_salve_Address = 0x60;
8 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0xff, 0x01);
write_SCCB(0x11, 0x00);
write_SCCB(0x0f, 0x4b);
write_SCCB(0x03, 0xcf);
14.3fps ~ 3.6fps night mode for 50Hz light environment, 24Mhz clock input
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x01);
write_SCCB(0x11, 0x01);
write_SCCB(0x0f, 0x4b);
write_SCCB(0x03, 0x8f);
l
ia
5.1 Light Band
AC e nt
id
nf
Light
Co
Exposure
Not n/100, has band = n/100, no band
T
V
The strength of office light is not even. It changes with AC frequency. For example, if the AC
frequency is 50Hz, the light changes strength at 100hz.
O
9 Company Confidential
OV2640 Camera Module Software Application Notes
Different frame rate could be used for different light frequency. So the frame rate is optimized for
both 50hz light condition and 60hz light condition.
Banding filter setting for 30fps SVGA preview, 24Mhz input clock
l
SCCB_salve_Address = 0x60;
ia
write_SCCB(0xff, 0x01); //select bank1
write_SCCB(0x13, 0xe5); bit[5]enable banding filter
nt
write_SCCB(0x0c, 0x38); //select 60hz banding filter ,bit[1]control auto, set 0, close auto banding
write_SCCB(0x4f, 0xca); //50Hz banding filter e
write_SCCB(0x50, 0xa8); //60Hz banding filter
id
write_SCCB(0x5a, 0x23); //3 step for 50hz,4 step for 60hz
nf
banding filter setting for 15fps SVGA preview, 24Mhz input clock
SCCB_salve_Address = 0x60;
Co
banding filter setting for 25fps SVGA preview, 24Mhz input clock
O
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x01); //select bank1
write_SCCB(0x13, 0xe5); bit[5]enable banding filter
write_SCCB(0x0c, 0x3c); //select 50hz banding filter ,bit[1]control auto, set 0, close auto banding
write_SCCB(0x4f, 0xa8); //50Hz banding filter
write_SCCB(0x50, 0x8c); //60Hz banding filter
write_SCCB(0x5a, 0x33); //4 step for 50hz,4 step for 60hz
banding filter setting for 14.3fps SVGA preview, 24Mhz input clock
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x01); //select bank1
write_SCCB(0x13, 0xe5); bit[5]enable banding filter
write_SCCB(0x0c, 0x3c); //select 50hz banding filter ,bit[1]control auto, set 0, close auto banding
write_SCCB(0x4f, 0x54); //50Hz banding filter
10 Company Confidential
OV2640 Camera Module Software Application Notes
Automatic select banding filter for 30fps SVGA preview, 24Mhz input clock
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x01); //select bank1
write_SCCB(0x13, 0xe5); bit[5]enable banding filter
write_SCCB(0x0c, 0x3a); //Automatically select banding filter
write_SCCB(0x4f, 0xca); //50Hz banding filter
write_SCCB(0x50, 0xa8); //60Hz banding filter
l
write_SCCB(0x5a, 0x23); //3 step for 50hz,4 step for 60hz
ia
Automatic select banding filter for 15fsp SVGA preview, 24Mhz input clock
nt
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x01); //select bank1 e
write_SCCB(0x13, 0xe5); bit[5]enable banding filter
id
write_SCCB(0x0c, 0x3a); //Automatically select banding filter
write_SCCB(0x4f, 0x65); //50Hz banding filter
nf
Automatic select banding filter for 25fps SVGA preview, 24Mhz input clock
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x01); //select bank1
T
Automatic select banding filter for 14.3fsp SVGA preview, 24Mhz input clock
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x01); //select bank1
write_SCCB(0x13, 0xe5); bit[5]enable banding filter
write_SCCB(0x0c, 0x3a); //Automatically select banding filter
write_SCCB(0x4f, 0x60); //50Hz banding filter
write_SCCB(0x50, 0x50); //60Hz banding filter
write_SCCB(0x5a, 0x67); //7 step for 50hz,8step for 60hz
11 Company Confidential
OV2640 Camera Module Software Application Notes
capture. If capture uses different resolution or different frame rate as preview, then the light band
should be removed in capture by exposure calculation. Please read section 14.7.3.
But there is some special conditions such as mix light of sun light and office light, take picture of
florescent light, the light band can not removed. The reason is the exposure time is less than 1/100
second for 50hz light environment and less than 1/120 second for 60hz light environment, so the
light band can not be removed.
The light band is this conditions could not be removed for all CMOS sensors, not only OV2640.
So there is no way to remove light band in this condition.
l
6. White Balance
ia
OV2640 support simple white balance and advanced balance.
The color is not accurate in conditions where “gray world” not true. For example the background
V
has a huge red, blue or green etc. the color of the foreground is not accurate. If the camera target
single color such as red, blue, green, the simple white balance will make the single color gray.
O
Settings
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00); //Select bank0
write_SCCB(0xc7, 0x10); // Simple AWB
12 Company Confidential
OV2640 Camera Module Software Application Notes
Settings
Contact with OmniVision local FAE.
l
ia
Defect pixel include dead pixel and wounded pixel.
nt
Dead pixel include white dead pixel and black dead pixel. White dead pixel is always white no
matter the actual picture is bright or dark. Black dead pixel is always black no matter the actual
e
picture is bright or dark.
id
Wounded pixel may change with light, but not as much as normal pixel. White wounded pixels
nf
are much brighter then normal pixels, but not complete white. Black wounded pixels are much
darker than normal pixels, but not complete black.
Co
OV2640 has built-in defect pixel correction function. If OV2640 output YCbCr, RGB565,
Processed raw RGB, the defect pixel correction function could be enabled to fix defect pixels. But if
Bayer raw RGB is used, the defect pixel correction function of sensor could not be used. The defect
T
Please pay attention to the defect pixel correction function of back-end chip. Some back-end chip
O
8. BLC
The function of Black Level Calibration (BLC) is to product accurate color in the dark area of
picture. There is automatic BLC function built-in OV2640. It should always be turned on.
9. Video Mode
Video mode need high frame rate, usually fixed 15fps. There is no night mode for video mode.
13 Company Confidential
OV2640 Camera Module Software Application Notes
If back-end chip support scale up, then more zoom level could be supported.
l
Auto
ia
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00)
write_SCCB(0xc7, 0x00); //AWB on
Sunny
e nt
id
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00)
nf
write_SCCB(0xcd, 0x41);
write_SCCB(0xce, 0x54);
Cloudy
T
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00)
V
write_SCCB(0xcd, 0x41);
write_SCCB(0xce, 0x4f);
Office
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00)
write_SCCB(0xc7, 0x40); //AWB off
write_SCCB(0xcc, 0x52);
write_SCCB(0xcd, 0x41);
write_SCCB(0xce, 0x66);
Home
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00)
14 Company Confidential
OV2640 Camera Module Software Application Notes
The color saturation of OV2640 could be adjusted. High color saturation would make the picture
looks more vivid, but the side effect is the bigger noise and not accurate skin color.
Saturation + 2
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
write_SCCB(0x7c, 0x00);
write_SCCB(0x7d, 0x02);
l
write_SCCB(0x7c, 0x03);
ia
write_SCCB(0x7d, 0x68);
write_SCCB(0x7d, 0x68);
Saturation + 1
e nt
id
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
nf
write_SCCB(0x7c, 0x00);
write_SCCB(0x7d, 0x02);
Co
write_SCCB(0x7c, 0x03);
write_SCCB(0x7d, 0x58);
write_SCCB(0x7d, 0x58);
T
Saturation 0
SCCB_salve_Address = 0x60;
V
write_SCCB(0xff, 0x00);
write_SCCB(0x7c, 0x00);
O
write_SCCB(0x7d, 0x02);
write_SCCB(0x7c, 0x03);
write_SCCB(0x7d, 0x48);
write_SCCB(0x7d, 0x48);
Saturation -1
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
write_SCCB(0x7c, 0x00);
write_SCCB(0x7d, 0x02);
write_SCCB(0x7c, 0x03);
write_SCCB(0x7d, 0x38);
write_SCCB(0x7d, 0x38);
15 Company Confidential
OV2640 Camera Module Software Application Notes
Saturation - 2
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
write_SCCB(0x7c, 0x00);
write_SCCB(0x7d, 0x02);
write_SCCB(0x7c, 0x03);
write_SCCB(0x7d, 0x28);
write_SCCB(0x7d, 0x28);
11.3 Brightness
The brightness of OV2640 could be adjusted. Higher brightness will make the picture more
bright. The side effect of higher brightness is the picture looks foggy.
Brightness +2
l
SCCB_salve_Address = 0x60;
ia
write_SCCB(0xff, 0x00);
write_SCCB(0x7c, 0x00);
nt
write_SCCB(0x7d, 0x04);
write_SCCB(0x7c, 0x09); e
write_SCCB(0x7d, 0x40);
id
write_SCCB(0x7d, 0x00);
nf
Brightness +1
SCCB_salve_Address = 0x60;
Co
write_SCCB(0xff, 0x00);
write_SCCB(0x7c, 0x00);
write_SCCB(0x7d, 0x04);
write_SCCB(0x7c, 0x09);
T
write_SCCB(0x7d, 0x30);
write_SCCB(0x7d, 0x00);
V
Brightness 0
O
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
write_SCCB(0x7c, 0x00);
write_SCCB(0x7d, 0x04);
write_SCCB(0x7c, 0x09);
write_SCCB(0x7d, 0x20);
write_SCCB(0x7d, 0x00);
Brightness -1
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
write_SCCB(0x7c, 0x00);
write_SCCB(0x7d, 0x04);
write_SCCB(0x7c, 0x09);
16 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0x7d, 0x10);
write_SCCB(0x7d, 0x00);
Brightness -2
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
write_SCCB(0x7c, 0x00);
write_SCCB(0x7d, 0x04);
write_SCCB(0x7c, 0x09);
write_SCCB(0x7d, 0x00);
write_SCCB(0x7d, 0x00);
11.4 Contrast
The contrast of OV2640 could be adjusted. Higher contrast will make the picture sharp. But the
l
side effect is loosing dynamic range.
ia
Contrast +2
nt
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00); e
write_SCCB(0x7c, 0x00);
id
write_SCCB(0x7d, 0x04);
write_SCCB(0x7c, 0x07);
nf
write_SCCB(0x7d, 0x20);
write_SCCB(0x7d, 0x28);
Co
write_SCCB(0x7d, 0x0c);
write_SCCB(0x7d, 0x06);
Contrast +1
T
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
V
write_SCCB(0x7c, 0x00);
write_SCCB(0x7d, 0x04);
O
write_SCCB(0x7c, 0x07);
write_SCCB(0x7d, 0x20);
write_SCCB(0x7d, 0x24);
write_SCCB(0x7d, 0x16);
write_SCCB(0x7d, 0x06);
Contrast 0
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
write_SCCB(0x7c, 0x00);
write_SCCB(0x7d, 0x04);
write_SCCB(0x7c, 0x07);
write_SCCB(0x7d, 0x20);
write_SCCB(0x7d, 0x20);
17 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0x7d, 0x20);
write_SCCB(0x7d, 0x06);
Contrast -1
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
write_SCCB(0x7c, 0x00);
write_SCCB(0x7d, 0x04);
write_SCCB(0x7c, 0x07);
write_SCCB(0x7d, 0x20);
write_SCCB(0x7d, 0x1c);
write_SCCB(0x7d, 0x2a);
write_SCCB(0x7d, 0x06);
Contrast -2
SCCB_salve_Address = 0x60;
l
write_SCCB(0xff, 0x00);
ia
write_SCCB(0x7c, 0x00);
nt
write_SCCB(0x7d, 0x04);
write_SCCB(0x7c, 0x07); e
write_SCCB(0x7d, 0x20);
id
write_SCCB(0x7d, 0x18);
write_SCCB(0x7d, 0x34);
nf
write_SCCB(0x7d, 0x06);
Co
Antique
V
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
O
write_SCCB(0x7c 0x00);
write_SCCB(0x7d, 0x18);
write_SCCB(0x7c 0x05);
write_SCCB(0x7d, 0x40);
write_SCCB(0x7d, 0xa6);
Bluish
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
write_SCCB(0x7c 0x00);
write_SCCB(0x7d, 0x18);
write_SCCB(0x7c 0x05);
write_SCCB(0x7d, 0xa0);
write_SCCB(0x7d, 0x40);
18 Company Confidential
OV2640 Camera Module Software Application Notes
Greenish
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
write_SCCB(0x7c 0x00);
write_SCCB(0x7d, 0x18);
write_SCCB(0x7c 0x05);
write_SCCB(0x7d, 0x40);
write_SCCB(0x7d, 0x40);
Reddish
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
write_SCCB(0x7c 0x00);
write_SCCB(0x7d, 0x18);
write_SCCB(0x7c 0x05);
l
write_SCCB(0x7d, 0x40);
ia
write_SCCB(0x7d, 0xc0);
B&W
SCCB_salve_Address = 0x60;
e nt
id
write_SCCB(0xff, 0x00);
write_SCCB(0x7c 0x00);
nf
write_SCCB(0x7d, 0x18);
write_SCCB(0x7c 0x05);
Co
write_SCCB(0x7d, 0x80);
write_SCCB(0x7d, 0x80);
Negative
SCCB_salve_Address = 0x60;
T
write_SCCB(0xff, 0x00);
write_SCCB(0x7c 0x00);
V
write_SCCB(0x7d, 0x40);
O
write_SCCB(0x7c 0x05);
write_SCCB(0x7d, 0x80);
write_SCCB(0x7d, 0x80;
B&W negative
SCCB_salve_Address = 0x60;
write_SCCB(0xff, 0x00);
write_SCCB(0x7c 0x00);
write_SCCB(0x7d, 0x58);
write_SCCB(0x7c 0x05);
write_SCCB(0x7d, 0x80);
write_SCCB(0x7d, 0x80;
Normal
SCCB_salve_Address = 0x60;
19 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0xff, 0x00);
write_SCCB(0x7c 0x00);
write_SCCB(0x7d, 0x00);
write_SCCB(0x7c 0x05);
write_SCCB(0x7d, 0x80);
write_SCCB(0x7d, 0x80;
YUYV
SCCB_slave_address = 0x60;
write_SCCB(0xff, 0x00);
l
ia
write_SCCB(0xda, temp);
nt
temp = read_SCCB(0xda); //register 0xc2 bit 4 to '0'
temp &= 0xef; e
write_SCCB(0xda, temp);
id
nf
YVYU
SCCB_slave_address = 0x60;
Co
write_SCCB(0xff, 0x00);
write_SCCB(0xda, temp);
VYUY
SCCB_slave_address = 0x60;
write_SCCB(0xff, 0x00);
20 Company Confidential
OV2640 Camera Module Software Application Notes
UYVY
SCCB_slave_address = 0x60;
write_SCCB(0xff, 0x00);
l
ia
12.1 Light fall off
nt
Light fall off means the corner of image is darker than center of image. It is caused by the lens.
The lens shading correction function of OV2640 could be turned on to compensate the corner
e
brightness and make the whole picture looks same bright.
id
12.2 Dark corner
nf
Some lens may have dark corner. Dark corner means the color of picture looks almost black. It is
not possible to correct dark corner with lens correction. So the module with dark corner is NG, it
Co
12.3 Resolution
T
The resolution of camera module depends on lens design, focus adjustment and sensor resolution
as well. The focus adjustment is very important for camera module assembly.
V
O
For OV2640 the focus distance is about 120~150cm. The depth of field is about from 60~75cm
to infinite. If checking resolution of camera module, the resolution chart should be placed 120~150
cm away.
21 Company Confidential
OV2640 Camera Module Software Application Notes
l
ia
write_SCCB(0xff, 0x01);
write_SCCB(0x12, 0x80);
nt
delay(1ms);
write_SCCB(0xff, 0x00); e
write_SCCB(0x2c, 0xff);
id
write_SCCB(0x2e, 0xdf);
write_SCCB(0xff, 0x01);
nf
write_SCCB(0x3c, 0x32);
//
Co
write_SCCB(0x11, 0x01);
write_SCCB(0x09, 0x02);
write_SCCB(0x04, 0x28);
write_SCCB(0x13, 0xe0);
write_SCCB(0x14, 0x48);
T
write_SCCB(0x2c, 0x0c);
V
write_SCCB(0x33, 0x78);
write_SCCB(0x3a, 0x33);
O
write_SCCB(0x3b, 0xfB);
//
write_SCCB(0x3e, 0x00);
write_SCCB(0x43, 0x11);
write_SCCB(0x16, 0x10);
//
write_SCCB(0x39, 0x92);
//
write_SCCB(0x35, 0xda);
write_SCCB(0x22, 0x1a);
write_SCCB(0x37, 0xc3);
write_SCCB(0x23, 0x00);
write_SCCB(0x34, 0xc0);
write_SCCB(0x36, 0x1a);
write_SCCB(0x06, 0x88);
22 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0x07, 0xc0);
write_SCCB(0x0d, 0x87);
write_SCCB(0x0e, 0x41);
write_SCCB(0x4c, 0x00);
write_SCCB(0x48, 0x00);
write_SCCB(0x5B, 0x00);
write_SCCB(0x42, 0x03);
//
write_SCCB(0x4a, 0x81);
write_SCCB(0x21, 0x99);
//
write_SCCB(0x24, 0x40);
write_SCCB(0x25, 0x38);
write_SCCB(0x26, 0x82);
write_SCCB(0x5c, 0x00);
write_SCCB(0x63, 0x00);
l
write_SCCB(0x61, 0x70);
ia
write_SCCB(0x62, 0x80);
nt
write_SCCB(0x7c, 0x05);
// e
write_SCCB(0x20, 0x80);
id
write_SCCB(0x28, 0x30);
write_SCCB(0x6c, 0x00);
nf
write_SCCB(0x6d, 0x80);
write_SCCB(0x6e, 0x00);
Co
write_SCCB(0x70, 0x02);
write_SCCB(0x71, 0x94);
write_SCCB(0x73, 0xc1);
//
write_SCCB(0x12, 0x40);
T
write_SCCB(0x17, 0x11);
write_SCCB(0x18, 0x43);
V
write_SCCB(0x19, 0x00);
O
write_SCCB(0x1a, 0x4b);
write_SCCB(0x32, 0x09);
write_SCCB(0x37, 0xc0);
write_SCCB(0x4f, 0x60);
write_SCCB(0x50, 0xa8);
write_SCCB(0x6d, 0x00);
write_SCCB(0x3d, 0x38);
//
write_SCCB(0x46, 0x3f);
write_SCCB(0x4f, 0x60);
write_SCCB(0x0c, 0x3c);
//
write_SCCB(0xff, 0x00);
write_SCCB(0xe5, 0x7f);
write_SCCB(0xf9, 0xc0);
23 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0x41, 0x24);
write_SCCB(0xe0, 0x14);
write_SCCB(0x76, 0xff);
write_SCCB(0x33, 0xa0);
write_SCCB(0x42, 0x20);
write_SCCB(0x43, 0x18);
write_SCCB(0x4c, 0x00);
write_SCCB(0x87, 0xd5);
write_SCCB(0x88, 0x3f);
write_SCCB(0xd7, 0x03);
write_SCCB(0xd9, 0x10);
write_SCCB(0xd3, 0x82);
//
write_SCCB(0xc8, 0x08);
write_SCCB(0xc9, 0x80);
//
l
write_SCCB(0x7c, 0x00);
ia
write_SCCB(0x7d, 0x00);
nt
write_SCCB(0x7c, 0x03);
write_SCCB(0x7d, 0x48); e
write_SCCB(0x7d, 0x48);
id
write_SCCB(0x7c, 0x08);
write_SCCB(0x7d, 0x20);
nf
write_SCCB(0x7d, 0x10);
write_SCCB(0x7d, 0x0e);
Co
//
write_SCCB(0x90, 0x00);
write_SCCB(0x91, 0x0e);
write_SCCB(0x91, 0x1a);
write_SCCB(0x91, 0x31);
T
write_SCCB(0x91, 0x5a);
write_SCCB(0x91, 0x69);
V
write_SCCB(0x91, 0x75);
O
write_SCCB(0x91, 0x7e);
write_SCCB(0x91, 0x88);
write_SCCB(0x91, 0x8f);
write_SCCB(0x91, 0x96);
write_SCCB(0x91, 0xa3);
write_SCCB(0x91, 0xaf);
write_SCCB(0x91, 0xc4);
write_SCCB(0x91, 0xd7);
write_SCCB(0x91, 0xe8);
write_SCCB(0x91, 0x20);
//
write_SCCB(0x92, 0x00);
write_SCCB(0x93, 0x06);
write_SCCB(0x93, 0xe3);
write_SCCB(0x93, 0x05);
24 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0x93, 0x05);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x04);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
//
write_SCCB(0x96, 0x00);
write_SCCB(0x97, 0x08);
write_SCCB(0x97, 0x19);
write_SCCB(0x97, 0x02);
write_SCCB(0x97, 0x0c);
l
write_SCCB(0x97, 0x24);
ia
write_SCCB(0x97, 0x30);
nt
write_SCCB(0x97, 0x28);
write_SCCB(0x97, 0x26); e
write_SCCB(0x97, 0x02);
id
write_SCCB(0x97, 0x98);
write_SCCB(0x97, 0x80);
nf
write_SCCB(0x97, 0x00);
write_SCCB(0x97, 0x00);
Co
//
write_SCCB(0xc3, 0xed);
write_SCCB(0xa4, 0x00);
write_SCCB(0xa8, 0x00);
write_SCCB(0xc5, 0x11);
T
write_SCCB(0xc6, 0x51);
write_SCCB(0xbf, 0x80);
V
write_SCCB(0xc7, 0x10);
O
write_SCCB(0xb6, 0x66);
write_SCCB(0xb8, 0xA5);
write_SCCB(0xb7, 0x64);
write_SCCB(0xb9, 0x7C);
write_SCCB(0xb3, 0xaf);
write_SCCB(0xb4, 0x97);
write_SCCB(0xb5, 0xFF);
write_SCCB(0xb0, 0xC5);
write_SCCB(0xb1, 0x94);
write_SCCB(0xb2, 0x0f);
write_SCCB(0xc4, 0x5c);
//
write_SCCB(0xc0, 0x64);
write_SCCB(0xc1, 0x4B);
write_SCCB(0x8c, 0x00);
25 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0x86, 0x3D);
write_SCCB(0x50, 0x00);
write_SCCB(0x51, 0xC8);
write_SCCB(0x52, 0x96);
write_SCCB(0x53, 0x00);
write_SCCB(0x54, 0x00);
write_SCCB(0x55, 0x00);
write_SCCB(0x5a, 0xC8);
write_SCCB(0x5b, 0x96);
write_SCCB(0x5c, 0x00);
write_SCCB(0xd3, 0x82);
//
write_SCCB(0xc3, 0xed);
write_SCCB(0x7f, 0x00);
//
write_SCCB(0xda, 0x00);
l
//
ia
write_SCCB(0xe5, 0x1f);
nt
write_SCCB(0xe1, 0x67);
write_SCCB(0xe0, 0x00); e
write_SCCB(0xdd, 0x7f);
id
write_SCCB(0x05, 0x00);
nf
write_SCCB(0x12, 0x80);
V
delay(1ms)
write_SCCB(0xff, 0x00);
O
write_SCCB(0x2c, 0xff);
write_SCCB(0x2e, 0xdf);
write_SCCB(0xff, 0x01);
write_SCCB(0x3c, 0x32);
//
write_SCCB(0x11, 0x01);
write_SCCB(0x09, 0x02);
write_SCCB(0x04, 0x28);
write_SCCB(0x13, 0xe5);
write_SCCB(0x14, 0x48);
write_SCCB(0x2c, 0x0c);
write_SCCB(0x33, 0x78);
write_SCCB(0x3a, 0x33);
write_SCCB(0x3b, 0xfB);
//
26 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0x3e, 0x00);
write_SCCB(0x43, 0x11);
write_SCCB(0x16, 0x10);
//
write_SCCB(0x39, 0x82);
//
write_SCCB(0x35, 0x88);
write_SCCB(0x22, 0x0a);
write_SCCB(0x37, 0x40);
write_SCCB(0x23, 0x00);
write_SCCB(0x34, 0xa0);
write_SCCB(0x36, 0x1a);
write_SCCB(0x06, 0x02);
write_SCCB(0x07, 0xc0);
write_SCCB(0x0d, 0xb7);
write_SCCB(0x0e, 0x01);
l
write_SCCB(0x4c, 0x00);
ia
write_SCCB(0x48, 0x00);
nt
write_SCCB(0x5B, 0x00);
write_SCCB(0x42, 0x83); e
//
id
write_SCCB(0x4a, 0x81);
write_SCCB(0x21, 0x99);
nf
//
write_SCCB(0x24, 0x40);
Co
write_SCCB(0x25, 0x38);
write_SCCB(0x26, 0x82);
write_SCCB(0x5c, 0x00);
write_SCCB(0x63, 0x00);
write_SCCB(0x46, 0x00);
T
write_SCCB(0x0c, 0x38);
//
V
write_SCCB(0x61, 0x70);
O
write_SCCB(0x62, 0x80);
write_SCCB(0x7c, 0x05);
//
write_SCCB(0x20, 0x80);
write_SCCB(0x28, 0x30);
write_SCCB(0x6c, 0x00);
write_SCCB(0x6d, 0x80);
write_SCCB(0x6e, 0x00);
write_SCCB(0x70, 0x02);
write_SCCB(0x71, 0x94);
write_SCCB(0x73, 0xc1);
//
write_SCCB(0x3d, 0x34);
write_SCCB(0x5a, 0x57);
write_SCCB(0x4f, 0xbb);
27 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0x50, 0x9c);
//
//
write_SCCB(0xff, 0x00);
write_SCCB(0xe5, 0x7f);
write_SCCB(0xf9, 0xc0);
write_SCCB(0x41, 0x24);
write_SCCB(0xe0, 0x14);
write_SCCB(0x76, 0xff);
write_SCCB(0x33, 0xa0);
write_SCCB(0x42, 0x20);
write_SCCB(0x43, 0x18);
write_SCCB(0x4c, 0x00);
write_SCCB(0x87, 0xd0);
write_SCCB(0x88, 0x3f);
write_SCCB(0xd7, 0x03);
l
write_SCCB(0xd9, 0x10);
ia
write_SCCB(0xd3, 0x82);
nt
//
write_SCCB(0xc8, 0x08); e
write_SCCB(0xc9, 0x80);
id
//
write_SCCB(0x7c, 0x00);
nf
write_SCCB(0x7d, 0x00);
write_SCCB(0x7c, 0x03);
Co
write_SCCB(0x7d, 0x48);
write_SCCB(0x7d, 0x48);
write_SCCB(0x7c, 0x08);
write_SCCB(0x7d, 0x20);
write_SCCB(0x7d, 0x10);
T
write_SCCB(0x7d, 0x0e);
//
V
write_SCCB(0x90, 0x00);
O
write_SCCB(0x91, 0x0e);
write_SCCB(0x91, 0x1a);
write_SCCB(0x91, 0x31);
write_SCCB(0x91, 0x5a);
write_SCCB(0x91, 0x69);
write_SCCB(0x91, 0x75);
write_SCCB(0x91, 0x7e);
write_SCCB(0x91, 0x88);
write_SCCB(0x91, 0x8f);
write_SCCB(0x91, 0x96);
write_SCCB(0x91, 0xa3);
write_SCCB(0x91, 0xaf);
write_SCCB(0x91, 0xc4);
write_SCCB(0x91, 0xd7);
write_SCCB(0x91, 0xe8);
28 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0x91, 0x20);
//
write_SCCB(0x92, 0x00);
write_SCCB(0x93, 0x06);
write_SCCB(0x93, 0xe3);
write_SCCB(0x93, 0x05);
write_SCCB(0x93, 0x05);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x04);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
l
//
ia
write_SCCB(0x96, 0x00);
nt
write_SCCB(0x97, 0x08);
write_SCCB(0x97, 0x19); e
write_SCCB(0x97, 0x02);
id
write_SCCB(0x97, 0x0c);
write_SCCB(0x97, 0x24);
nf
write_SCCB(0x97, 0x30);
write_SCCB(0x97, 0x28);
Co
write_SCCB(0x97, 0x26);
write_SCCB(0x97, 0x02);
write_SCCB(0x97, 0x98);
write_SCCB(0x97, 0x80);
write_SCCB(0x97, 0x00);
T
write_SCCB(0x97, 0x00);
//
V
write_SCCB(0xc3, 0xed);
O
write_SCCB(0xc4, 0x9a);
write_SCCB(0xa4, 0x00);
write_SCCB(0xa8, 0x00);
write_SCCB(0xc5, 0x11);
write_SCCB(0xc6, 0x51);
write_SCCB(0xbf, 0x80);
write_SCCB(0xc7, 0x10);
write_SCCB(0xb6, 0x66);
write_SCCB(0xb8, 0xA5);
write_SCCB(0xb7, 0x64);
write_SCCB(0xb9, 0x7C);
write_SCCB(0xb3, 0xaf);
write_SCCB(0xb4, 0x97);
write_SCCB(0xb5, 0xFF);
write_SCCB(0xb0, 0xC5);
29 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0xb1, 0x94);
write_SCCB(0xb2, 0x0f);
write_SCCB(0xc4, 0x5c);
//
write_SCCB(0xc0, 0xc8);
write_SCCB(0xc1, 0x96);
write_SCCB(0x86, 0x1d);
write_SCCB(0x50, 0x00);
write_SCCB(0x51, 0x90);
write_SCCB(0x52, 0x2c);
write_SCCB(0x53, 0x00);
write_SCCB(0x54, 0x00);
write_SCCB(0x55, 0x88);
write_SCCB(0x57, 0x00);
write_SCCB(0x5a, 0x90);
write_SCCB(0x5b, 0x2c);
l
write_SCCB(0x5c, 0x05);
ia
//
nt
write_SCCB(0xc3, 0xed);
write_SCCB(0x7f, 0x00); e
//
id
write_SCCB(0xda, 0x00);
//
nf
write_SCCB(0xe5, 0x1f);
write_SCCB(0xe1, 0x67);
Co
write_SCCB(0xe0, 0x00);
write_SCCB(0xdd, 0x7f);
write_SCCB(0x05, 0x00);
T
write_SCCB(0xff, 0x01);
write_SCCB(0x12, 0x80);
delay(5ms);
write_SCCB(0xff, 0x00);
write_SCCB(0x2c, 0xff);
write_SCCB(0x2e, 0xdf);
write_SCCB(0xff, 0x01);
write_SCCB(0x3c, 0x32);
//
write_SCCB(0x11, 0x00);
write_SCCB(0x09, 0x02);
write_SCCB(0x04, 0x28);
write_SCCB(0x13, 0xe5);
write_SCCB(0x14, 0x48);
30 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0x2c, 0x0c);
write_SCCB(0x33, 0x78);
write_SCCB(0x3a, 0x33);
write_SCCB(0x3b, 0xfB);
//
write_SCCB(0x3e, 0x00);
write_SCCB(0x43, 0x11);
write_SCCB(0x16, 0x10);
//
write_SCCB(0x39, 0x92);
//
write_SCCB(0x35, 0xda);
write_SCCB(0x22, 0x1a);
write_SCCB(0x37, 0xc3);
write_SCCB(0x23, 0x00);
write_SCCB(0x34, 0xc0);
l
write_SCCB(0x36, 0x1a);
ia
write_SCCB(0x06, 0x88);
nt
write_SCCB(0x07, 0xc0);
write_SCCB(0x0d, 0x87); e
write_SCCB(0x0e, 0x41);
id
write_SCCB(0x4c, 0x00);
write_SCCB(0x48, 0x00);
nf
write_SCCB(0x5B, 0x00);
write_SCCB(0x42, 0x03);
Co
//
write_SCCB(0x4a, 0x81);
write_SCCB(0x21, 0x99);
//
write_SCCB(0x24, 0x40);
T
write_SCCB(0x25, 0x38);
write_SCCB(0x26, 0x82);
V
write_SCCB(0x5c, 0x00);
O
write_SCCB(0x63, 0x00);
write_SCCB(0x46, 0x22);
write_SCCB(0x0c, 0x3c);
//
write_SCCB(0x61, 0x70);
write_SCCB(0x62, 0x80);
write_SCCB(0x7c, 0x05);
//
write_SCCB(0x20, 0x80);
write_SCCB(0x28, 0x30);
write_SCCB(0x6c, 0x00);
write_SCCB(0x6d, 0x80);
write_SCCB(0x6e, 0x00);
write_SCCB(0x70, 0x02);
write_SCCB(0x71, 0x94);
31 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0x73, 0xc1);
//
write_SCCB(0x12, 0x40);
write_SCCB(0x17, 0x11);
write_SCCB(0x18, 0x43);
write_SCCB(0x19, 0x00);
write_SCCB(0x1a, 0x4b);
write_SCCB(0x32, 0x09);
write_SCCB(0x37, 0xc0);
write_SCCB(0x4f, 0xca);
write_SCCB(0x50, 0xa8);
write_SCCB(0x5a, 0x23);
write_SCCB(0x6d, 0x00);
write_SCCB(0x3d, 0x38);
//
write_SCCB(0xff, 0x00);
l
write_SCCB(0xe5, 0x7f);
ia
write_SCCB(0xf9, 0xc0);
nt
write_SCCB(0x41, 0x24);
write_SCCB(0xe0, 0x14); e
write_SCCB(0x76, 0xff);
id
write_SCCB(0x33, 0xa0);
write_SCCB(0x42, 0x20);
nf
write_SCCB(0x43, 0x18);
write_SCCB(0x4c, 0x00);
Co
write_SCCB(0x87, 0xd5);
write_SCCB(0x88, 0x3f);
write_SCCB(0xd7, 0x03);
write_SCCB(0xd9, 0x10);
write_SCCB(0xd3, 0x82);
T
//
write_SCCB(0xc8, 0x08);
V
write_SCCB(0xc9, 0x80);
O
//
write_SCCB(0x7c, 0x00);
write_SCCB(0x7d, 0x00);
write_SCCB(0x7c, 0x03);
write_SCCB(0x7d, 0x48);
write_SCCB(0x7d, 0x48);
write_SCCB(0x7c, 0x08);
write_SCCB(0x7d, 0x20);
write_SCCB(0x7d, 0x10);
write_SCCB(0x7d, 0x0e);
//
write_SCCB(0x90, 0x00);
write_SCCB(0x91, 0x0e);
write_SCCB(0x91, 0x1a);
write_SCCB(0x91, 0x31);
32 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0x91, 0x5a);
write_SCCB(0x91, 0x69);
write_SCCB(0x91, 0x75);
write_SCCB(0x91, 0x7e);
write_SCCB(0x91, 0x88);
write_SCCB(0x91, 0x8f);
write_SCCB(0x91, 0x96);
write_SCCB(0x91, 0xa3);
write_SCCB(0x91, 0xaf);
write_SCCB(0x91, 0xc4);
write_SCCB(0x91, 0xd7);
write_SCCB(0x91, 0xe8);
write_SCCB(0x91, 0x20);
//
write_SCCB(0x92, 0x00);
write_SCCB(0x93, 0x06);
l
write_SCCB(0x93, 0xe3);
ia
write_SCCB(0x93, 0x05);
nt
write_SCCB(0x93, 0x05);
write_SCCB(0x93, 0x00); e
write_SCCB(0x93, 0x04);
id
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
nf
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
Co
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
write_SCCB(0x93, 0x00);
//
write_SCCB(0x96, 0x00);
T
write_SCCB(0x97, 0x08);
write_SCCB(0x97, 0x19);
V
write_SCCB(0x97, 0x02);
O
write_SCCB(0x97, 0x0c);
write_SCCB(0x97, 0x24);
write_SCCB(0x97, 0x30);
write_SCCB(0x97, 0x28);
write_SCCB(0x97, 0x26);
write_SCCB(0x97, 0x02);
write_SCCB(0x97, 0x98);
write_SCCB(0x97, 0x80);
write_SCCB(0x97, 0x00);
write_SCCB(0x97, 0x00);
//
write_SCCB(0xc3, 0xed);
write_SCCB(0xa4, 0x00);
write_SCCB(0xa8, 0x00);
write_SCCB(0xc5, 0x11);
33 Company Confidential
OV2640 Camera Module Software Application Notes
write_SCCB(0xc6, 0x51);
write_SCCB(0xbf, 0x80);
write_SCCB(0xc7, 0x10);
write_SCCB(0xb6, 0x66);
write_SCCB(0xb8, 0xA5);
write_SCCB(0xb7, 0x64);
write_SCCB(0xb9, 0x7C);
write_SCCB(0xb3, 0xaf);
write_SCCB(0xb4, 0x97);
write_SCCB(0xb5, 0xFF);
write_SCCB(0xb0, 0xC5);
write_SCCB(0xb1, 0x94);
write_SCCB(0xb2, 0x0f);
write_SCCB(0xc4, 0x5c);
//
write_SCCB(0xc0, 0x64);
l
write_SCCB(0xc1, 0x4B);
ia
write_SCCB(0x8c, 0x00);
nt
write_SCCB(0x86, 0x3D);
write_SCCB(0x50, 0x00); e
write_SCCB(0x51, 0xC8);
id
write_SCCB(0x52, 0x96);
write_SCCB(0x53, 0x00);
nf
write_SCCB(0x54, 0x00);
write_SCCB(0x55, 0x00);
Co
write_SCCB(0x5a, 0xC8);
write_SCCB(0x5b, 0x96);
write_SCCB(0x5c, 0x00);
write_SCCB(0xd3, 0x82);
//
T
write_SCCB(0xc3, 0xed);
write_SCCB(0x7f, 0x00);
V
//
O
write_SCCB(0xda, 0x08);
//
write_SCCB(0xe5, 0x1f);
write_SCCB(0xe1, 0x67);
write_SCCB(0xe0, 0x00);
write_SCCB(0xdd, 0x7f);
write_SCCB(0x05, 0x00);
34 Company Confidential
OV2640 Camera Module Software Application Notes
14.1 Shutter
The shutter of OV2640 controls exposure time. The unit of shutter is line period.
Shutter value has limitation for each output resolution. If no dummy lines are inserted, the
maximum shutter value for QXGA resolution is 1248. The maximum shutter value for XGA
resolution is 672.
Default_XGA_maximum_shutter = 672;
Default_QXGA_maximum_shutter = 1248;
The shutter value are stored in 3 registers, reg0x45, reg0x10 and reg0x04 of bank 1.
l
ia
The exposure could be increased further by insert dummy lines. When dummy lines are inserted,
frame rate also changes.
If dummy lines are inserted before data output, which is called extra line, the actual exposure
time is increased. The extra line is controlled by register 0x2d and 0x2e of bank 1.
The extra lines are inserted inside the active period of Vsync, the timing of output period in
which Vsync is inactive is not changed.
35 Company Confidential
OV2640 Camera Module Software Application Notes
value is changed. The dummy lines are inserted between two Vsync. The number of dummy lines is
controlled by register 0x46 and 0x47 of bank 1.
SVGA_maximum_shutter = Default_SVGA_Maximum_Shutter + Dummy_line
UXGA_maximum_shutter = Default_UXGA_Maximum_Shutter + Dummy_line
Exposure = Shutter
l
ia
672 for SVGA 672 + Dummy_line for SVGA
Minimum Exposure Extra_lines 0
Maximum Exposure
nt
Maximum_Shutter + Extra_lines Maximum_Shutter
e
id
So if both dummy line and extra line are inserted, the exposure time is
nf
If no dummy pixel is inserted, the line width is called default line width.
Default_SVGA_Line_Width = 1190;
Default_UXGA_Line_Width = 1922;
When dummy pixel is inserted, the line width changes and frame rate also changes.
14.4 Gain
Gain is stored in reg0x00 and Reg0x45[7:6] of bank 1. If only use the gain of Reg0x00, maximum
gain of 32x could be reached. It is enough for camera phone. So we don't discuss reg0x45 here.
36 Company Confidential
OV2640 Camera Module Software Application Notes
14.5.1 Preview
Automatic Banding filter is used for preview.
14.5.2 Capture
Manual banding filter is used for capture. The banding filter calculation is
l
Banding_Filter = Capture_PCLK_Frequency /100 /capture_line_width
ia
nt
For 60Hz, the banding filter calculation is
e
Banding_Filter = Capture_PCLK_Frequency /120 /capture_line_width
id
So Capture_Exposure = n*Banding_Filter
nf
n is an integer.
Co
14.7.1 Preview
// Initialize OV2640 for preview
37 Company Confidential
OV2640 Camera Module Software Application Notes
l
reg0x10 = SCCB_read(0x10);
ia
reg0x04 = SCCB_read(0x04);
nt
Shutter = (reg0x45 & 0x3f)<<10 + reg0x10<<2 + (reg0x04 & 0x03);
reg0x2b = SCCB_read(0x2b);
Preview_dummy_pixels = (reg0x2a & 0xf0)<<4 + reg0x2b;
38 Company Confidential
OV2640 Camera Module Software Application Notes
If (resolution ==SVGA) {
Capture_line_width = Default_SVGA_Line_Width + capture_Dummy_pixel;
}
else {
Capture_line_width = Default_UXGA_Line_Width + capture_Dummy_pixel;
}
If (resolution ==SVGA) {
Capture_maximum_shutter = Default_SVGA_maximum_shutter + capture_dummy_lines;
}
else {
Capture_maximum_shutter = Default_UXGA_maximum_shutter + capture_dummy_line;
}
Capture_Exposure =
Preview_Exposure * 2 * Capture_PCLK_Frequency/Preview_PCLK_Frequency *
l
Preview_Line_width/Capture_Line_Width;
ia
nt
//Calculate banding filter value
If (50Hz) { e
If (format == RGB) {//RGB indicates raw RGB
id
Capture_banding_Filter = Capture_PCLK_Frequency /100 /capture_line_width;
}
nf
else {
Capture_banding_Filter = Capture_PCLK_Frequency/ 100/ (2*capture_line_width);
Co
}
else {
If (format == RGB) {
Capture_banding_Filter = Capture_PCLK_Frequency /120 /capture_line_width;
}
T
else {
Capture_banding_Filter = Capture_PCLK_frequency /120 /(2*capture_line_width);
V
}
O
39 Company Confidential
OV2640 Camera Module Software Application Notes
l
}
ia
14.7.4 Switch to UXGA
// Write registers, change to UXGA resolution.
e nt
id
14.7.5 Write Registers
nf
Reg0x47 = Capture_Dummy_lines>>8;
SCCB_write(0x46, Reg0x46);
SCCB_write(0x47, Reg0x47);
//Write Exposure
If (Capture_Exposure > Capture_maximum_shutter) {
Shutter = Capture_maximum_shutter;
Extra_lines = Capture_Exposure – Capture_maximum_shutter;
}
else {
Shutter = Capture_Exposure;
Extra_lines = 0;
}
Reg0x04 = SCCB_read(0x04);
Reg0x04 = Reg0x04 & 0xfc | (Shutter & 0x000003);
40 Company Confidential
OV2640 Camera Module Software Application Notes
SCCB_write(0x45, Reg0x45);
SCCB_write(0x10, Reg0x10);
SCCB_write(0x04, Reg0x04);
// Write Gain
Gain = 0;
l
If (Capture_Gain16 > 16) {
ia
Capture_Gain16 = Capture_Gain /2;
nt
Gain = 0x10;
} e
If (Capture_Gain16 > 16) {
id
Capture_Gain16 = Capture_Gain /2;
Gain = Gain | 0x20;
nf
}
If (Capture_Gain16 > 16) {
Co
SCCB_write(0x00, Gain);
14.7.6 Capture
// Wait for 2 Vsync
// Capture the 3rd frame.
41 Company Confidential
OV2640 Camera Module Software Application Notes
Reg0x13 = SCCB_read(0x13);
Reg0x13 = Reg0x13 | 0x05;
SCCB_Write(0xff, 0x01);
SCCB_Write(0x13, Reg0x13);
l
ia
e nt
id
nf
Co
T
V
O
42 Company Confidential