大侠好,欢迎来到FPGA技术江湖,江湖偌大,相见即是缘分。大侠可以关注FPGA技术江湖,在“闯荡江湖”、"行侠仗义"栏里获取其他感兴趣的资源,或者一起煮酒言欢。
今天给大侠带来摄像头camera 7660/7670/7225/9650以及程序流程,话不多说,上货。
本人调试过很多摄像头,OV7660、OV7670、OV7225这3款是30万的摄像头。还有一个130万的OV9650摄像头,移植在ARM平台上的数据,都调试成功了,7寸模拟屏显示,希望对大家有些参考帮助。
调试的要点:
AGC:图像自动增益控制,调节的东西有增益范围、增益上限下限大小等等,具体的要看应用场合来调试效果。
一般会把增益开大一些,对暗的环境会有明显改善,看的清楚一些,不至于一片黑。还有上下限,要看效果,一般开的范围比较大的话,特别是CMOS的摄像头,对暗环境增益开大时候会出现非常明显的噪点。
AWB:自动白平衡,有时候一般都在摄像头的夜间模式反映出来,一般夜间模式开启时候,由于效果不同,输出的帧率也会不同。严重的话,会有切割现象,这是因为掉帧,场频引起的,这个时候就要调节CLK以及不同的夜模式来保证一个最佳的效果。
代码语言:javascript复制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}
}
/*********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}
}
/***********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×××*/
保存_GPJCON=rGPJCON;
保存_GPJDAT=rGPJDAT;
保存_GPJUP=rGPJUP;
rGPJCON=0x2aaaaa;//GPJ 12=CAMRESET,J3端口
rGPJDAT=0;//GPJ 11=CAMCLKOUT J4端口
rGPJUP=0;
/*时钟设置:rUPLLCON=(mdiv<<12)区(pdiv<4)x sdv;*/
ChangeUPllValue(60,4,1);//UPLL时钟=96 MHz,PLL输入16.9344MH
rCLKDIVN=(1<3);//UCLK 48 MHz UPLL 96 MHz设置
//见p 232的的相机时钟=UPLL/[(CAMCLK_DIV 1)X2]
//一般都根据象素来设置CAMCLK,如果是高象素如130万(1280*1024,那么至少需要设置48 Mhz,并且130万象素的可能传送显示只能达到15帧XSGA格式,但是如果30万象素,那么24 Mhz可能就能达到30帧的效果)
rCAMDIVN=(rCAMDIVN&(0Xf)x(1<4)x(Divn);//CAMCLK被除以.set CameraClock=24M(divn=1)
/*******************/
/CamModuleReset();摄像头外部模组的复位,或者也可以就外部硬件复位,工作之前都要复位的,很好理解,
rCIGCTRL=(1<30);//外部摄像机复位高度
延迟(30);
RCIGCTRL&=~(1<<30);//外部摄像机复位低
延迟;//一定要注意的是,这个延时,复位之后一定要加延时500 ms就够了
写入IIC();/初始化相机模块,这个模块就是IIC模块,最基本的功能,非常简单,就不再详细说了
/*后面开始就是预览抓捕并且液晶显示摄像头的程序部分*
三星的自定义程序有2个抓捕模式,一个是代码,一个是pview,选择pview讲解,通一个即可**/
//摄像机全局变量
camTestMode=CAM_test_mode_PVIEW;//选pview
camCodecCaptureCount=0;
camPviewCaptureCount=0;//计数
camPviewStatus=CAM_Stop;//状态,初始的时候定义为停止状态
CamCodecStatus=CAM_Stop;
鞭毛捕获P=0;//标志
凸轮_PVIEW_Output==CAM_RGB16B;//照相机输出格式,我这里定义摄像头为RGB 565格式输出,因此后面需要初始化为565格式的LCD显示输出
/*后面是lcd显示初始化*/
LCDinit();
/*包含了如下
lcd_port_init();//lcd口的设置
LCD_Init(模式);
*液晶显示器(模式)函数初始化步骤概解*
液晶根据物理屏分辨率大小设置虚拟屏的缓存大小,例如,实际屏大小为x=320,y=240,那么虚拟大小一般开原来大小×2,即Vx=x*2,Vy=y*2,然后在指定的位置开虚拟数组,三星里面用的是如下的几句来定义的:
U32(*frameBuffer16BitTft640480)[SCR_XSIZE_TFT_640480/2];//定义一个指针数组名为*FraBuffer16BitTft640480
帧Buffer16BitTft640480=(U32(*)[SCR_XSIZE_TFT_640480/2])LCDFRAMEBUFFER;//将FrameBuffer16BitTft640480这个数组名赋予硬件地址,LCDFRAMEBUFFER,这个就是硬件设计时候的SRAM的一部分,一般分配为0x33800000~0x33bffff,4MB的空间大小,为什么会这么定义,具体见三星手册的章节部分,有详细描述,此处不再说明了。
然后就是设置rLCDCON 1、rLCDCON 2、rLCDCON 3、rLCDCON 4、rLCDCON 5这些寄存器设置、Hclk、前肩、后肩、消隐还有其他信号波形脉宽.
rLCDSADDR 1、rLCDSADDR 2、rLCDSADDR 3指的是帧缓冲区启动地址寄存器,这几个寄存器的设置见三星手册页面402的几个示例。
rLCDINTMS K=(3);//掩码LCD子中断
rTCONSEL&=(~7);//禁用LPC 3600
rTPAL=0;//禁用临时调色板
然后看看void_putTft16Bit_240320(U32x,U32y,U32c)这个函数就是一个象素的打点了,显示的位置x,y以及颜色c,0x0000ffff==黑色后面的16位R5-G6-B5
{
IF(x<SCR_XSIZE_TFT_240320&<;SCR_YSIZE_TFT_240320)
帧Buffer16BitTft240320[(Y)][(X)/2]=(FrameBuffer16BitTft240320[(Y)][x/2]
(c&0x00ffff)<<((2-1-(X)%(X)%2)*16);
}
***********************************************************************/
GLOB_INIT(模式);//初始化象素点控制
选择_Tcon();
LCD_PowerEnable(0,1);
LCD_EnvidOnOff(1);
glib_ClearScr(0,模式);//清屏、写入全黑点
******/
//其实这个函数包含了挺多的东西了,包括lcd显示输出选择,相关lcd显示部分,网上资料也有很多了,也是初始化cpu寄存器,写入解码芯片的寄存器,里面还有帧缓冲的开显示缓存,来检查小寄存器
接着继续为摄像头定义不一样的寄存器
rLCDCON 5=1;//半字交换启用->相机数据是半字交换类型,16位
/*分配内存空间*
rLCDSADDR 3&=~(0x7ff<11);//偏移大小0
/*这个地址比较重要对于确定显存大小,第401页*
rLCDSADDR 2=M5D((LCDFRAMEBUFFER (LCD_XSIZE_TFT_240320*LCD_YSIZE_TFT_240320*2))>>1);
/*液晶屏幕上可以显示出彩条
数据=(U32*)LCDFRAMEBUFFER;
对于(i=0;i<240*160;i )//16 bpp测试
{
如果(i<240*40)*数据 =0x001f001f;//蓝色
如果((i<240*80)&&(i>=240*40))*数据 =0x07e007e0;//Green
如果((i<240*120)&(i>=240*80))*数据 =0xf800f800;//red
如果(i>=240*120)*data =0xf800001f;//Blue&red
}
*///
/*颜色的测定rgb 32=16*2*
*Data =0 xffffffff;//White
UART_Printf(“n像素为%d,%xn”,i,*data-2);
I ;
*数据 =0xf800f800;//红色
UART_Printf(“n像素为%d,%xn”,i,*data-1);
*Data =0x001f001f;//Blue
*数据 =0x07e007e0;//Green
*数据 =0xffe0ffe0;//黄色
/*初始化*
CamInit(640、480、480、234、0、0、CAM_FRAMEBUFFER_C、CAM_FRAMEBUFFER_P);
*重点是上面这个函数:摄像头的一些初始化工作*
/*参数说明
CoDstWidth:编码路径的目标宽度
CoDstH:Codec路径的目标高度
PrDstWidth:预览路径的目标宽度
PrDstH:预览路径的目标高度
WinHoroffset:水平方向窗口偏移的大小
WinVeroffset:垂直方向窗口偏移量的大小
CoFrameBuffer:Codec DMA的起始地址
PrFrameBuffer:PrevieDMA的起始地址
*/
voidCamInit(U32 CoDstWidth,U32 CoDstHight,U32 PrDstWidth,U32 PrDstHight,
U32 WinHoroffset,U32 WinVeroffset,U32 CoFrameBuffer,U32 PrFrameBuffer)
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
rSUBSRCPND=BIT_SUM_CAM_C_BIT_SUB_CAM_P;
信息交换(BIT_CAM);
pISR_CAM=(U32)CamIsr;
CamPreviewIntUnmud();
CamCaptureStart(CAM_PVIEW_SCALER_CAPTURE_ENABLE_BIT);
END
后续会持续更新,带来Vivado、 ISE、Quartus II 、candence等安
装相关设计教程,学习资源、项目资源、好文推荐等,希望大侠持续关注。
大侠们,江湖偌大,继续闯荡,愿一切安好,有缘再见!