高级会员
- 积分
- 552
- 威望
- 315
- 贡献
- 145
- 兑换币
- 110
- 注册时间
- 2012-11-1
- 在线时间
- 46 小时
|
/* 曝光时间,单位ms */
u8 IntegrationTime = 10;
void CalculateIntegrationTime(void) {
extern u8 Pixel[128];
/* 128个像素点的平均AD值 */
u8 PixelAverageValue;
/* 128个像素点的平均电压值的10倍 */
u8 PixelAverageVoltage;
/* 设定目标平均电压值,实际电压的10倍 */
s16 TargetPixelAverageVoltage = 30;
/* 设定目标平均电压值与实际值的偏差,实际电压的10倍 */
s16 PixelAverageVoltageError = 0;
/* 设定目标平均电压值允许的偏差,实际电压的10倍 */
s16 TargetPixelAverageVoltageAllowError = 2;
/* 计算128个像素点的平均AD值 */
PixelAverageValue = PixelAverage(128,Pixel);
/* 计算128个像素点的平均电压值,实际值的10倍 */
PixelAverageVoltage = (uint8_t)((int)PixelAverageValue * 25 / 200);
PixelAverageVoltageError = TargetPixelAverageVoltage - PixelAverageVoltage;
if(PixelAverageVoltageError < -TargetPixelAverageVoltageAllowError)
IntegrationTime--;
if(PixelAverageVoltageError > TargetPixelAverageVoltageAllowError)
IntegrationTime++;
if(IntegrationTime <= 1)
IntegrationTime = 1;
if(IntegrationTime >= 20)
IntegrationTime = 20;
}
u8 PixelAverage(u8 len, u8 *data) {
uint8_t i;
unsigned int sum = 0;
for(i = 0; i<len; i++) {
sum = sum + *data++;
}
return ((uint8_t)(sum/len));
} |
|