• 转:摄像头camera 7660/7670/7225/9650以及程序流程(一)


    http://www.cnblogs.com/crazybingo/archive/2012/05/11/2495680.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.   | ");

    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(" pixel is  %d  ,%x "  ,i,*data-2);
              i++;
              *data++ = 0xf800f800;                  //red
           Uart_Printf(" pixel is  %d  ,%x "  ,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! ");

  • 相关阅读:
    德国10马克,高斯正态分布函数
    安装python的第三方库 geopandas
    Python版本的GDAL 安装
    [原创]App崩溃率统计工具推荐
    用户增长模型AARRR模型
    [原创]nginx日志分析工具
    [原创]浅谈移动互联网创业公司工具类产品
    [原创]浅谈在创业公司对PMF的理解
    [原创]浅谈创业公司如何选择产品方向
    [原创]浅谈在创业公司对MVP的理解
  • 原文地址:https://www.cnblogs.com/adxiaowei/p/4154650.html
Copyright © 2020-2023  润新知