一、基本概念
HTS = width_number_of_effective_cloumns+H_Blank,图像宽度+行消隐
VTS = height_number_of_effective_rows + V_Blank,图像高度+场消隐
OV9281 sensor array layout如下:
二、帧率配置
1、clock diagram
2、PLL configuration
XCLK:24MHz
PLL1 clock
0x030A[0]:0(default value),/1 24MHz
0x0300[2:0]:001(default value),/1.5 16MHz
0x0301[1:0],0x0302[7:0]:0x32(default value) 16MHzx50=800MHz
0x0303[3:0]:0000,/(1+0x0303[3:0]) 800MHz
0x0304[1:0]:11(default value),/8 100MHz
0x0305[1:0]:10(default value),/5 160Mhz
0x0306[0]:1(default value),/2 80MHz
MIPI_CLK=800MHz
PLL1 pix clk=100MHz
PLL1 pix clk=400MHz
PLL2 clock
0x0314[0]:0(default value),/1 24MHz
0x030B[2:0]:100(default value),/3 8MHz
0x030C[1:0],0x030D[7:0]:0x50(default value) 8MHzx80=640MHz
0x0313[3:0]:0001,/(1+0x0313[3:0]) 640MHz/2=320MHz
0x0312[3:0]:0111,/(1+0x0312[3:0]) 640MHz/8=80MHz
0x030F[3:0]:0011, /(1+0x030F[3:0]) 640MHz/4=160MHz
0x030E[2:0]:010,/2 160MHz/2=80MHz
PLL2 ADC clk=320MHz
PLL2 analog clk=80MHz
PLL2 sys clk=80MHz
datasheet配置参考:
3、HTS、VTS配置
HTS寄存器0x380C、0x380D,默认值0x02D8,实际值需要大于图像宽度+行消隐
VTS寄存器0x380E、0x380F,默认值0x038E,实际宽度需要大于图像高度+场消隐
4、FPS计算
计算公式:fps=sys_clk/(VTS*HTS),PLL2 sys_clk为sys_clk
以sys_clk=80MHz,VTS=0x038E(910),HTS=0x02D8(728)计算fps,fps=80000000/(910*728)=120.75
以sys_clk=80MHz,VTS=0x0E38(3640),HTS=0x02D8(728)计算fps,fps=80000000/(3640*728)=30.18
4、改变帧率
一般是通过改变vts的值改变帧率,以下为君正sdk中ov9281驱动中改变帧率的函数,参数fps的值为运算之后的值,如帧率为30,fps=30<<16 | 1;
static int ov9281_set_fps(int fps)
{
struct sensor_info *sensor_info = &ov9281_sensor_attr.sensor_info;
unsigned int sclk = 0;
unsigned short vts = 0;
unsigned short hts = 0;
unsigned int max_fps = 0;
unsigned char tmp;
unsigned int newformat = 0;
unsigned short expo = 0;
int ret = 0;
sclk = OV9281_SCLK;
max_fps = SENSOR_OUTPUT_MAX_FPS;
/* the format of fps is 16/16. for example 25 << 16 | 2, the value is 25/2 fps. */
newformat = (((fps >> 16) / (fps & 0xffff)) << 8) + ((((fps >> 16) % (fps & 0xffff)) << 8) / (fps & 0xffff));
if(newformat > (max_fps << 8) || newformat < (SENSOR_OUTPUT_MIN_FPS << 8)){
printf("ov9281 set fps warn: fps(%x) no in range\n", fps);
return -1;
}
/* hts */
ret = ov9281_read(sensor_i2c_dev, 0x380c, &tmp);
hts = tmp << 8;
ret += ov9281_read(sensor_i2c_dev, 0x380d, &tmp);
if (ret < 0)
return -1;
hts |= tmp;
/* vts */
vts = sclk * (fps & 0xffff) / hts / ((fps & 0xffff0000) >> 16);
ret = ov9281_write(sensor_i2c_dev, 0x380e, (unsigned char)(vts >> 8));
ret += ov9281_write(sensor_i2c_dev, 0x380f, (unsigned char)(vts & 0xff));
if (ret < 0)
return -1;
sensor_info->fps = fps;
sensor_info->total_height = vts;
sensor_info->max_integration_time = vts - 25;
return 0;
}
三、曝光配置
相关寄存器
EXPO单位是行周期,最小值是1个行周期,最大值是vts-25个行周期。 比如VTS=0x038E,那么EXPO MAX= 885。