Camera camera 7660/7670/7225/9650 and program Process (1)

Source: Internet
Author: User

To:

Http://www.baohe.com/album/view-26800-183286.html

 

Many cameras have been debugged. ov7660, ov7670, and ov7225 are 0.3 million cameras.

There is also a 1.3 million ov9650 camera

All the data transplanted to the ARM platform has been debugged successfully. The 7-inch Analog Screen is displayed, and it is expected to be useful.

Key Points of debugging:

AGC: Automatic Gain Control for images. The adjusted items include the gain range and the lower limit of the gain limit. The specific value depends on the application scenarios for debugging.

Generally, the gain will be increased, which will significantly improve the dark environment and be clear, so it will not be black. There are also upper and lower limits, depending on the effect. If the open range is relatively large, especially for the CMOS camera, there will be very obvious noise when the gain for the dark environment is large.

AWB: Automatic white balance. Sometimes it is reflected in the camera's night mode. Generally, when the night mode is enabled, the frame rate will be different because of different effects. In severe cases, there will be cutting. This is caused by frame drop and field frequency. At this time, we need to adjust CLK and different night modes to ensure the best effect.

Please send an email to: jk_new@163.com, because work, may not be able to reply in time, please forgive me!

Const unsigned char ov7660_ycbcr8bit [] [2] = {

{0x12, 0x80 },
{0x11, 0x80 },//
{0x92,0x00 },
{0x93,0x00 },
{0x9d, 0x4c },
{0x9e, 0x3f },
{0x3b, 0x88 },

{0x13, 0xf2 },
{0x10, 0x00 },
{0x00,0x00 },
{0x01,0x80 },
{0x02,0x80 },
{0x13, 0xf7 },

{0x12, 0x00 },
{0x04,0x00}, // No href skip
//// 640x480
{0x18, 0x01 },
{0x17,0x13 },
{0x32, 0x92 },
{0x19,0x02}, // B10 1000 (8)
{0x1a, 0x7a}, // b11110100 1111010000 (488)
{0x03, 0xf0}, // 00

{0x0e, 0x84 },
{0x0f, 0x62 },
{0x15, 0x10 },//
{0x16, 0x02 },
{0x1b, 0x01 },
{0x1e, 0x39}, // B

{0x29, 0x3c}, //; 20 for internal regulator
{0x33,0x00 },
{0x34,0x07 },
{0x35, 0x84 },
{0x36,0x00 },
{0x38,0x13 },
{0x39,0X43 },
{0x3a, 0x00}, // P

{0x3c, 0x6c },
{0x3d, 0x90 },
{0x3f, 0x29 },
{0x40, 0xc1}, // output full range enable bit7bit8 11: Output Range: [00] to [ff]
{0x41,0x20 },
{0x6b, 0x0a },
{0xa1, 0xc8 },
{0x69,0x80 },
{0x43, 0xf0 },
{0x44,0x10 },
{0x45, 0x78 },
{0x46, 0xa8 },
{0x47,0x60 },
{0x48, 0x80 },
{0x59, 0xba },
{0x5a, 0x9a },
{0x5b, 0x22 },
{0x5c, 0xb9 },
{0x5d, 0x9b },
{0x5e, 0x10 },
{0x5f, 0xe0 },
{0x60, 0x85}, //; 05 for advanced AWB
{0x61,0x60 },

{0x9f, 0x9d },
{0xa0, 0xa0 },
{0x4f, 0x66 },
{0x50, 0x6b },
{0x51,0x05 },
{0x52,0x19 },
{0x53,0x40 },
{0x54,0X59 },
{0x55, 0x40 },
{0x56, 0x40 },
{0x57,0x40 },
{0x58, 0x0d },
{0x8b, 0xcc },
{0x8c, 0xcc },
{0x8d, 0xcf },
{0x6c, 0x40 },
{0x6d, 0x30 },
{0x6e, 0x4b },
{0x6f, 0x60 },
{0x70, 0x70 },
{0x71,0x70 },
{0x72,0x70 },
{0x73,0x70 },
{0x74,0x60 },
{0x75, 0x60 },
{0x76,0x50 },
{0x77,0x48 },
{0x78, 0x3a },
{0x79, 0x2e },
{0x7a, 0x28 },
{0x7b, 0x22 },
{0x7c, 0x04 },
{0x7d, 0x07 },
{0x7e, 0x10 },
{0x7f, 0x28 },
{0x80, 0x36 },
{0x81,0x44 },
{0x82,0x52 },
{0x83,0x60 },
{0x84, 0x6c },
{0x85, 0x78 },
{0x86, 0x8c },
{0x87, 0x9e },
{0x88, 0xbb },
{0x89, 0xd2 },
{0x8a, 0xe6 },
{0x14, 0x2e },
{0x24, 0x78 },
{0x25, 0x5c}

}

/************************** JK 2008-01-17 color test7670 */

Const unsigned char ov7670_ycbcr8bit [] [2] = {
{0x12, 0x80 },
{0x11, 0x01 },
{0x3a, 0x04 },
{0x12, 0x00 },

{0x17,0x13 },
{0x18, 0x01 },
{0x32, 0xb6 },

{0x19,0x02 },
{0x1a, 0x7a },

{0x03, 0x0a },
{0x0c, 0x00 },
{0x3e, 0x00 },

{0x70, 0x3a },
{0x71,0x35 },
{0x72,0x11 },
{0x73, 0xf0 },
{0xa2, 0x02 },

{0x11, 0x83}, // this step is importance setting CLK
 
{0x7a, 0x20 },
{0x7b, 0x11 },
{0x7c, 0x1b },
{0x7d, 0x2a },
{0x7e, 0x42 },
{0x7f, 0x4c },
{0x80, 0x56 },
{0x81, 0x5f },
{0x82,0x68 },
{0x83,0x70 },
{0x84,0x78 },
{0x85, 0x87 },
{0x86,0x95 },
{0x87, 0xb0 },
{0x88, 0xc8 },
{0x89, 0xdf },

{0x13, 0xe0 },
{0x00,0x00 },
{0x10, 0x00 },
{0x0d, 0x40 },

{0x14,0x23}, // 0x61: open = 128x, 0x51 = 64x

{0xa5, 0x05 },
{0xab, 0x07 },

{0x24, 0x77}, // up AGC
{0x25, 0x44}, // low AGC

{0x26, 0xe3 },

{0x9f, 0x70}, // 20080117
{0xa0, 0x60}, // 20080117

{0xa1, 0x0b },
{0xa6, 0xd8 },
{0xa7, 0xd8 },
{0xa8, 0xf0 },
{0xa9, 0x90 },
{0xaa, 0x94 },
{0x13, 0xe5 },

{0x0e, 0x61 },
{0x0f, 0x4b },
{0x16, 0x02 },

{0x1e, 0x10}, // mirror
{0x21,0x02 },
{0x22,0x91 },

{0x33, 0x0b}, // 03
{0x35, 0x0b },
{0x37, 0x1d },
{0x38,0x71 },//
{0x39, 0x2a },//

{0x3c, 0x78 },

{0x4d, 0x40 },
{0x4e, 0x20 },
{0x69,0x00}, // 55
{0x6b, 0x4a },
{0x74,0x19 },
{0x8d, 0x4f },
{0x8e, 0x00 },
{0x8f, 0x00 },
{0x90,0x00 },
{0x91,0x00 },
{0x96,0x00 },
{0x9a, 0x80 },
{0xb0, 0x84}, // 8C
{0xb1, 0x0c },
{0xb2, 0x0e },
{0xb3, 0x82 },
{0xb8, 0x0a },

{0x43,0x14 },
{0x44, 0xf0 },
{0x45, 0x34 },
{0x46,0x58 },
{0x47,0x28 },
{0x48, 0x3a },
{0x59,0x88 },
{0x5a, 0x88 },
{0x5b, 0x44 },
{0x5c, 0x67 },
{0x5d, 0x49 },
{0x5e, 0x0e },
{0x6c, 0x0a },
{0x6d, 0x55 },
{0x6e, 0x11 },
{0x6f, 0x9f}, // 9e for advance AWB
{0x6a, 0x40 },

{0x01,0x80 },
{0x02,0x80 },
{0x13, 0xe7}, // sets automatic gain white balance and other content
{0x15, 0x10}, // PHT add 20071208 pclk reversed phase will see Flashing Noise points


{0x4f, 0x80 },
{0x50, 0x80}, // 20080117
{0x51,0x00}, // 20080117
{0x52,0x22}, // 20080117
{0x53, 0x5e}, // 20080117
{0x54,0x80}, // 20080117

{0x55, 0x25}, // ADDR brightness
// {0x56, 0x40}, // ADDR contrast
// {0x57,0x40}, // ADDR

{0x58, 0x1e },

{0x41,0x00 },
{0x3f, 0x00 },
{0x75, 0x05 },
{0x76, 0xe1 },
{0x4c, 0x00 },
{0x77,0x01 },
{0x3d, 0xc2 },
{0x4b, 0x09 },
{0xc9, 0xff },
{0x41,0x38 },

{0x34,0x11 },
// {0x3b, 0xfa },
{0x3b, 0x9a}, // adjust the content related to the night mode, and set whether to drop the frame.

// {0x3b, 0xc8}, // 20080117

// {0x3e, 0x00 },

{0xa4, 0x80 },
{0x96,0x00 },
{0x97,0x30 },
{0x98,0x20 },
{0x99,0x30 },
{0x9a, 0x84 },
{0x9b, 0x29 },
{0x9c, 0x03 },
//
// {0x9d, 0x99}, // R gain for LED output Frame
// {0x9e, 0x7f}, // B gain for LED output Frame
// {0x9f, 0x80}, // B gain for LED output Frame

{0x78,0x04 },

// Append lens correction setting,
{0x62,0x30 },
{0x63,0x30 },
{0x64, 0x08 },
{0x94,0x07 },
{0x95, 0x0b },
{0x65,0x00 },
{0x66,0x05 },

{0x79,0x01 },
{0xc8, 0xf0 },

/// 20080117
{0x79, 0x0f },
{0xc8, 0x00 },
{0x79,0x10 },
{0xc8, 0x7e },
{0x79, 0x0a },
{0xc8, 0x80 },
{0x79, 0x0b },
{0xc8, 0x01 },
{0x79, 0x0c },
{0xc8, 0x0f },
{0x79, 0x0d },
{0xc8, 0x20 },
{0x79,0x09 },
{0xc8, 0x80 },
{0x79,0x02 },
{0xc8, 0xc0 },
{0x79,0x03 },
{0xc8, 0x40 },
{0x79,0x05 },
{0xc8, 0x30 },
{0x79,0x26 },
// {0x3b, 0xd8 },
{0xf1, 0x10 },
{0x0f, 0x1d },
{0x0f, 0x4b },
{0xff, 0xff}

}

/************************** JK 2008-01-17 color test7670 */

Const unsigned char ov7225_ycbcr8bit [] [2] = {

/***** 20080117-** 7225 ****
0x12, 0x80,
0x3d, 0x03,
0x17,0x26,
0x18, 0xa0,
0x19,0x07,
0x1a, 0xf0,
0x32, 0x00,
0x29, 0xa0,
0x2c, 0xf0,
0x65,0x20,
0x11, 0x03,
0x0d, 0x41,
0x41,0x00,
0x42, 0x7f,
0x63, 0xe0,
0x64, 0xff,
0x13, 0xf0,
0x22, 0x7f,
0x23,0x03,
0x24, 0x40,
0x25, 0x30,
0x26, 0xa1,
0x6b, 0xaa,
0x13, 0xf7,
0x90,0x05,
0x91,0x01,
0x92,0x03,
0x93,0x00,
0x94, 0xb0,
0x95, 0x9d,
0x96,0X13,
0x97,0x16,
0x98, 0x7b,
0x99,0x91,
0x9a, 0x1e,
0x9b, 0x08,
0x9c, 0x20,
0x9e, 0x81,
0xa6, 0x04,
0x7e, 0x0e,
0x7f, 0x22,
0x80, 0x3f,
0x81,0x63,
0x82, 0x6e,
0x83,0x77,
0x84,0x80,
0x85, 0x88,
0x86,0x90,
0x87,0x97,
0x88, 0xa4,
0x89, 0xaf,
0x8a, 0xc5,
0x8b, 0xd7,
0x8c, 0xe8,
0x8d, 0x20,
0x15, 0x10 ,*/

}

Const unsigned char ov9650_ycbcr8bit [] [2] =
{

 

}

Port_init ();
Mmu_init ();
Calc_clock (1 );
Update_refresh (hclk );
Isr_init ();
Uart_txempty (1 );
Delay (0); // calibrate delay ();

Uart_printf ("| s3c2440a firmware-test ver 0.03 Jan 2004. | \ n ");

Clk0_enable (2); // 0: mpllin, 1: upll, 2: fclk, 3: hclk, 4: pclk, 5: dclk0
Clk1_enable (3); // 0: mpllout, 1: upll, 2: RTC, 3: hclk, 4: pclk, 5: dclk1

/******* Camera start ********/

Rcigctrl | = (1 <31); // internal modules of camera I/F soft Reset
Delay (10); // camera also has a hardware reset, Which is set externally at 30 bits, such as rcigctrl | = (1 <30 );
Rcigctrl & = ~ (1 <31); // The rcigctrl register can also set the polarity of the field signal and line synchronization signal.

Rclkcon | = (1 <19); // enable camclk Outputs An hclk from the CPU to the camera, which starts to work.

// When the camera is working, an external clock is required for triggering.

/*************** Camportset ******/

Save_gpjcon = rgpjcon;
Save_gpjdat = rgpjdat;
Save_gpjup = rgpjup;

Rgpjcon = 0x2aaaaaa; // gpj12 = camreset, J3 Port
Rgpjdat = 0; // gpj11 = camclkout J4 Port
Rgpjup = 0;

/****** Clock setting: rupllcon = (mdiv <12) | (pdiv <4) | sdiv ;*******/

Changeupllvalue (60, 4, 1); // upll clock = 96 MHz, PLL input 16.9344mh

Rclkdivn | = (1 <3); // uclk 48 MHz setting for upll 96 MHz

//See p232 camdivn's camera clock = upll/[(camclk_div + 1) x2]

// Camclk is generally set based on pixels. If a high pixel is 1.3 million (1280*1024, at least 48 MHz is required, in addition, the possible transfer and display of 1.3 million pixels can only reach 15 xsga frames, but if 0.3 million pixels are transmitted, 24 MHz may achieve 30 frames)

Rcamdivn = (rcamdivn &~ (0xf) | (1 <4) | (divn); // camclk is divided .. set cameraclock = 24 m (divn = 1)

 

/*******************/

//// Cammodulereset (); resets the external module of the camera, or resets the external hardware before work. It is easy to understand,

Rcigctrl | = (1 <30); // external camera reset high
Delay (30 );
Rcigctrl & = ~ (1 <30); // external camera reset low

Delay; // The latency must be ms after the reset.

Write_iic (); // initialize the camera module. This module is the IIC module. It has the most basic functions and is very simple.

* Is followed by preview capture and LCD camera display.ProgramPart ****

Samsung's custom programs have two capture modes, one being code and the other being pview. You can choose pview to explain them **/

// Camera global variables

Camtestmode = cam_test_mode_pview; // select pview.
Camcodeccapturecount = 0;
Campviewcapturecount = 0; // count
Campviewstatus = cam_stopped; // status, which is initially defined as "STOPPED ".
Camcodecstatus = cam_stopped;
Flagcaptured_p = 0; // flag

Cam_pview_output = cam_rgb16b; // camera output format. I define the camera as rgb565 output. Therefore, the LCD output in the 565 format needs to be initialized later.

/***** LCD display initialization *****/

Lcdinit ();

/****** Includes the following

LCD _port_init (); // LCD port settings

LCD _init (mode );

/***************************** LCD _init (Mode) function initialization procedure *********************************** *****

LCD sets the cache size of the virtual screen based on the resolution size of the physical screen. For example, if the actual screen size is X = 320, y = 240, the virtual size is usually opened to the original size × 2, that is, VX = x * 2, Vy = y * 2, and then open the Virtual Array at the specified position. Samsung uses the following statements for definition:

U32 (* framebuffer16bittft640133) [scr_xsize_tft_640133/2]; // define a pointer array named * framebuffer16bittft640133

Framebuffer16bittft640480 = (u32 (*) [Bytes/2]) lcdframebuffer; // assign the array name framebuffer16bittft640480 to the hardware address and lcdframebuffer, which is part of the SRAM during hardware design, it is generally allocated as 0x33800000 ~ 0x33bffffff, 4 MB space, why is this definition? For details, see the LCD section in the Samsung manual. I will not describe it here.

Then, the registers rlcdcon1, rlcdcon2, rlcdcon3, rlcdcon4, and rlcdcon5 are set to vclk, hclk, front shoulder, back shoulder, blanking, and other signal waveform pulse widths.

Rlcdsaddr1, rlcdsaddr2, and rlcdsaddr3 refer to frame buffer start address register. For the settings of these registers, see the example of page402 In the Samsung manual.

Rlcdintmsk | = (3); // mask LCD sub interrupt
Rtconsel & = (~ 7); // disable lpc3600
Rtpal = 0; // disable temp palette

Then let's take a look at Void _ puttft16bit_240320 (u32 X, u32 y, u32 c). This function is a pixel hitting. The position X, Y, and color C are displayed, 0x0000ffff = black rear 16-bit R5-G6-B5
{
If (x <scr_xsize_tft_240320 & Y <scr_ysize_tft_240320)
Framebuffer16bittft240320 [(y)] [(X)/2] = (framebuffer16bittft240320 [(y)] [X/2]
&~ (0xffff0000> (x) % 2) * 16) | (C & 0x0000ffff) <(2-1-(x) % 2 )) * 16 ));
}

 

**************************************** *******************************/

Glib_init (mode); // initialize the pixel point control.
Select_tcon ();
LCD _powerenable (0, 1 );
LCD _envidonoff (1 );
Glib_clearscr (0, mode); // clear screen, write all black points

******/

// In fact, this function contains a lot of things, including LCD Display output selection, LCD display, and a lot of online information. It also initializes CPU registers, write the registers of the decoder chip, which also contains the on-display cache of framebuffer to check a little registers

Next, define different registers for the camera.

Rlcdcon5 | = 1; // halfword swap enable-> camera data is halfword swap type, 16bit

/*********** Allocate memory space **********/

Rlcdsaddr3 & = ~ (0x7ff <11); // offset size 0

/*************** This address is more important for determining the size of the video memory, page 401 ***************/
Rlcdsaddr2 = m5d (lcdframebuffer + (LCD _xsize_tft_240320 * LCD _ysize_tft_240320*2)> 1 );

/* The color bar can be displayed on the LCD screen.

Data = (u32 *) lcdframebuffer;
For (I = 0; I <240*160; I ++) // 16bpp Test
{
If (I <240*40) * Data ++ = 0x001f001f; // blue
Else if (I <240*80) & (I> = 240*40) * Data ++ = 0x07e007e0; // green
Else if (I <240*120) & (I> = 240*80) * Data ++ = 0xf800f800; // red
Else if (I> = 240*120) * Data ++ = 0xf800001f; // blue & red
}

 

*///

/********** Color Determination RGB 32 = 16*2 ***********/

* Data ++ = 0 xffffffff; // white

Uart_printf ("\ n pixel is % d, % x \ n", I, * Data-2 );
I ++;
* Data ++ = 0xf800f800; // red
Uart_printf ("\ n pixel is % d, % x \ n", I, * Data-1 );
* Data ++ = 0x001f001f; // blue
* Data ++ = 0x07e007e0; // green

* Data ++ = 0xffe0ffe0; // yellow
/************ Camera initialization **********/

Caminit (640,480,480,234, 0, 0, cam_framebuffer_c, cam_framebuffer_p );

/*************** The focus is on the above function: camera initialization ***************/

/* Description of parameters
Codstwidth: Destination width of codec path
Codstheight: Destination height of codec path
Prdstwidth: Destination width of preview path
Prdstheight: Destination height of preview path
Winhoroffset: size of window offset for Horizontal Direction
Winveroffset: size of window offset for vertical direction
Coframebuffer: Start address for Codec DMA
Prframebuffer: Start address for previe DMA
*/
Void caminit (u32 codstwidth, u32 codstheight, u32 prdstwidth, u32 prdstheight,
U32 winhoroffset, u32 winveroffset, u32 coframebuffer, u32 prframebuffer)

 

/*************************************** *************************************/
/*************************************** *************************************/

/*************************************** *************************************/

rsubsrcpnd | = bit_sub_cam_c | bit_sub_cam_p;
clearpending (bit_cam);
pisr_cam = (u32) camisr;
campreviewintunmask ();
camcapturestart (cam_pview_scaler_capture_enable_bit);
uart_printf ("Press ENTER key to exit! \ N ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.