攝像頭camera 7660/7670/7225/9650以及程序流程(一)


轉:

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

 

調試了好多攝像頭,OV7660、OV7670、OV7225這3款是30萬的攝像頭

還有一個130萬的OV9650攝像頭

移植在ARM平台上的數據,都調試成功了,7寸模擬屏顯示,希望有用

調試的要點:

AGC:圖像自動增益控制,調節的東西有增益范圍、增益上限下限大小等等,具體的要看應用場合來調試效果

         一般會把增益開大一些,對暗的環境會有明顯改善,看的清楚一些,不至於一片黑。還有上下限,要看效       果,一般開的范圍比較大的話,特別是CMOS的攝像頭,對暗環境增益開大時候會出現非常明顯的噪點。

AWB:自動白平衡,有時候一般都在攝像頭的夜間模式反映出來,一般夜間模式開啟時候,由於效果不同,輸             出的幀率也會不同。嚴重的話,會有切割現象,這是因為掉幀,場頻引起的,這個時候就要調節CLK以及不同的夜模式來保證一個最佳的效果。

需要手冊的請發郵件至:jk_new@163.com,因為上班,可能不能及時回復,請見諒!

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 設置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},//設置自動gain 白平衡等內容
{0X15,0X10},  //pht add 20071208 pclk 反相會出現閃爍的噪音點

     
{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},//調節夜間模式相關內容,是否掉幀也在次設置

//{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-15:50**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); //camera I/F soft reset   內部模塊
 Delay(10);                                //camera 還有一個硬件復位,外部的,在30位設置,如rCIGCTRL |=(1<<30);
 rCIGCTRL &= ~(1<<31);       //rCIGCTRL寄存器還可以設置場信號、行同步信號的極性等

   

rCLKCON |= (1<<19); // enable camclk  從CPU輸出一個HCLK給攝像頭,攝像頭開始工作起振

                                        //攝像頭工作的時候需要外部一個時鍾進行觸發

 /**********××××× CamPortSet××××××××××******/

save_GPJCON = rGPJCON;
 save_GPJDAT = rGPJDAT;
 save_GPJUP = rGPJUP;

 rGPJCON = 0x2aaaaaa;             //GPJ12= CAMRESET,J3  port   
 rGPJDAT = 0;                               //GPJ11=CAMCLKOUT J4 port 
 rGPJUP = 0;

/*******時鍾設置: rUPLLCON = (mdiv<<12) | (pdiv<<4) | sdiv;*******/

ChangeUPllValue(60, 4, 1);  // UPLL clock = 96MHz, PLL input 16.9344MH
           

rCLKDIVN|=(1<<3); // UCLK 48MHz setting for UPLL 96MHz  

//見p232的CAMDIVN 的Camera clock = UPLL/[(CAMCLK_DIV+1)X2]

//一般都根據象素來設置CAMCLK,如果是高象素如130萬(1280*1024,那么至少需要設置48Mhz,並且130萬象素的可能傳送顯示只能達到15幀XSGA格式,但是如果30萬象素,那么24Mhz可能就能達到30幀的效果)

rCAMDIVN = (rCAMDIVN & ~(0xf))|(1<<4)|(divn); // CAMCLK is divided..Set CameraClock=24M(divn =1)

 

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

////CamModuleReset(); 攝像頭外部模組的復位,或者也可以就外部硬件復位,工作之前都要復位的,很好理解,

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

Delay;   //一定要注意的是,這個延時,復位之后一定要加延時500mS就夠了

write_IIC(); //////////初始化camera 模塊,這個模塊就是IIC模塊,最基本的功能,非常簡單,就不再詳細說了

 /*********后面開始就是preview抓捕並且LCD顯示攝像頭的程序部分****

三星的自定義程序有2個抓捕模式,一個是code,一個是pview,  選擇pview講解,通一個即可**/

//camera global variables

camTestMode=CAM_TEST_MODE_PVIEW;  //選pview
 camCodecCaptureCount=0;          
 camPviewCaptureCount=0;                             //計數
 camPviewStatus=CAM_STOPPED;               //狀態,初始的時候定義為停止狀態
 camCodecStatus=CAM_STOPPED;
 flagCaptured_P=0;                                           //標志

CAM_PVIEW_OUTPUT==CAM_RGB16B;    //camera輸出格式,我這里定義攝像頭為RGB565格式輸出,因此后面需要初始化為565格式的LCD顯示輸出

/****后面是LCD顯示初始化*****/

LCDinit();

/******* 包含了如下

    Lcd_Port_Init();  //LCD口的設置

    Lcd_Init(mode);

/***************************** Lcd_Init(mode)函數初始化步驟概解****************************************

LCD根據物理屏分辨率大小設置虛擬屏的緩存大小,例如,實際屏大小為x=320,y=240,那么虛擬大小一般開原來Size ×2,即Vx=x*2,Vy=y*2,然后在指定的位置開虛擬數組,三星里面用的是如下的幾句來定義的:

U32 (*frameBuffer16BitTft640480)[SCR_XSIZE_TFT_640480/2]; //定義一個指針數組名為*frameBuffer16BitTft640480

frameBuffer16BitTft640480=(U32 (*)[SCR_XSIZE_TFT_640480/2])LCDFRAMEBUFFER; //將frameBuffer16BitTft640480這個數組名賦予硬件地址,LCDFRAMEBUFFER,這個就是硬件設計時候的SRAM的一部分,一般分配為0x33800000~0x33bffffff,4MB的空間大小,為什么會這么定義,具體見三星手冊的LCD章節部分,有詳細描述,此處不再說明了。

然后就是設置rLCDCON1、rLCDCON2、rLCDCON3、rLCDCON4、rLCDCON5這些寄存器設置Vclk、Hclk、前肩、后肩、消隱還有其他信號波形脈寬。

rLCDSADDR1、rLCDSADDR2、rLCDSADDR3指的是Frame buffer start address register,這幾個寄存器的設置見三星手冊page402的幾個example.

rLCDINTMSK|=(3); // MASK LCD Sub Interrupt      
rTCONSEL&=(~7); // Disable LPC3600 
rTPAL=0; // Disable Temp Palette  

然后看看void _PutTft16Bit_240320(U32 x,U32 y,U32 c)這個函數就是一個象素的打點了,顯示的位置x,y以及顏色c,0x0000ffff==黑色   后面的16位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);     //初始化象素點控制  
    Select_Tcon();
    Lcd_PowerEnable(0, 1);
    Lcd_EnvidOnOff(1);
    Glib_ClearScr(0, mode);   //  清屏、寫入全黑點

******/

//其實這個函數包含了挺多的東西了,包括LCD顯示輸出選擇,相關LCD顯示部分,網上資料也有很多了,也是初始化CPU寄存器,寫入解碼芯片的寄存器,里面還有framebuffer 的開顯示緩存,來check a little registers

接着繼續為攝像頭定義不一樣的寄存器

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

/**********分配內存空間**********/

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

/***************這個地址比較重要對於確定顯存大小  ,Page 401***************/
 rLCDSADDR2=M5D( (LCDFRAMEBUFFER+(LCD_XSIZE_TFT_240320*LCD_YSIZE_TFT_240320*2))>>1 );

/************LCD屏幕上可以顯示出彩條

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
    }

 

*///

    /**********顏色的測定RGB 32=16*2***********/   

      *data++ = 0xffffffff;                 //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 初始化**********/

CamInit(640, 480, 480, 234, 0, 0,  CAM_FRAMEBUFFER_C, CAM_FRAMEBUFFER_P);

/***************重點是上面這個函數:攝像頭的一些初始化工作***************/

/* 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");


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM