高级会员
- 积分
- 546
- 威望
- 242
- 贡献
- 132
- 兑换币
- 149
- 注册时间
- 2015-1-5
- 在线时间
- 86 小时
- 毕业学校
- 曲阜师范大学
|
/*************************************************************************
* 蓝宙电子工作室
*
* 函数名称:CalculateIntegrationTime
* 功能说明:计算曝光时间
* 参数说明:
* 函数返回:无
* 修改时间:2012-10-20
* 备 注:
*************************************************************************/
/* 曝光时间,单位ms */
u8 IntegrationTime = 10;
void CalculateIntegrationTime(void) {
extern u8 Pixel[128];
/* 128个像素点的平均AD值 */
u8 PixelAverageValue;
/* 128个像素点的平均电压值的10倍 */
u8 PixelAverageVoltage;
/* 设定目标平均电压值,实际电压的10倍 */
s16 TargetPixelAverageVoltage = 25;
/* 设定目标平均电压值与实际值的偏差,实际电压的10倍 */
s16 PixelAverageVoltageError = 0;
/* 设定目标平均电压值允许的偏差,实际电压的10倍 */
s16 TargetPixelAverageVoltageAllowError = 2;
/* 计算128个像素点的平均AD值 */
PixelAverageValue = PixelAverage(128,Pixel);
/* 计算128个像素点的平均电压值,实际值的10倍 */
PixelAverageVoltage = (unsigned char)((int)PixelAverageValue * 25 / 194);
PixelAverageVoltageError = TargetPixelAverageVoltage - PixelAverageVoltage;
if(PixelAverageVoltageError < -TargetPixelAverageVoltageAllowError)
{
PixelAverageVoltageError = 0- PixelAverageVoltageError ;
PixelAverageVoltageError /= 2;
if(PixelAverageVoltageError > 10 )
PixelAverageVoltageError = 10 ;
IntegrationTime -= PixelAverageVoltageError;
}
if(PixelAverageVoltageError > TargetPixelAverageVoltageAllowError)
{
PixelAverageVoltageError /= 2;
if(PixelAverageVoltageError > 10 )
PixelAverageVoltageError = 10 ;
IntegrationTime += PixelAverageVoltageError;}
// uart_putchar(UART0,0XAA) ;
// uart_putchar(UART0,PixelAverageVoltage) ;
// uart_putchar(UART0,PixelAverageVoltageError) ;
// uart_putchar(UART0,IntegrationTime) ;
if(IntegrationTime <= 1)
IntegrationTime = 1;
if(IntegrationTime >= 100)
IntegrationTime = 100;
}
|
|