📄 auto.c
字号:
return _ERROR_SUCCESS;
}
//--------------------------------------------------
// Description : Auto phase process
// Input Value : None
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoDoAutoPhase(void)
{
BYTE result, phase, best;
LWORD maxsum, temp0, temp1, temp2;
result = CAutoMeasurePositionH(_MIN_NOISE_MARGIN);
if(_ERROR_SUCCESS != result) return result;
// Set threshold for Phase Search
CScalerSetByte(_DIFF_THRESHOLD_79, 0x40);
maxsum = CAutoPhaseSearch(_COLOR_SELECT, _HWAUTO_STEP_8, HWAUTOSTEPNUM(8), HWAUTOSTEPSTART(0), &result);
if(maxsum == 0xffffffffL) return _ERROR_INPUT;
if(maxsum == 0) return _ERROR_ABORT;
if(maxsum < ((LWORD)stModeInfo.IVHeight * 1024 * 3 / 2)) return _ERROR_PHASE;
maxsum = CAutoPhaseSearch(_COLOR_SELECT, _HWAUTO_STEP_2, HWAUTOSTEPNUM(8), HWAUTOSTEPSTART((result - 8) & 0x3f), &result);
if(maxsum == 0xffffffffL) return _ERROR_INPUT;
if(maxsum == 0) return _ERROR_ABORT;
if(maxsum < ((LWORD)stModeInfo.IVHeight * 1024 * 3 / 2)) return _ERROR_PHASE;
// Search phase by weighting SOD
phase = (result - 3) & 0x3f;
CAdjustPhase(phase);
if(_ERROR_SUCCESS != CAutoReadPhaseInfo(_COLOR_SELECT)) return _ERROR_INPUT;
temp0 = ((LWORD *)pData)[1];
phase = (phase + 1) & 0x3f;
CAdjustPhase(phase);
if(_ERROR_SUCCESS != CAutoReadPhaseInfo(_COLOR_SELECT)) return _ERROR_INPUT;
temp1 = ((LWORD *)pData)[1];
result = (result + 3) & 0x3f;
maxsum = 0;
do
{
phase = (phase + 1) & 0x3f;
CAdjustPhase(phase);
if(_ERROR_SUCCESS != CAutoReadPhaseInfo(_COLOR_SELECT)) return _ERROR_INPUT;
temp2 = ((LWORD *)pData)[1];
((LWORD *)pData)[0] = temp2 + temp1 + temp0
- ((temp1 > temp0 ? temp1 - temp0 : temp0 - temp1) / 2)
- ((temp1 > temp2 ? temp1 - temp2 : temp2 - temp1) / 2);
if(((LWORD *)pData)[0] > maxsum)
{
maxsum = ((LWORD *)pData)[0];
best = (phase - 1) & 0x3f;
}
temp0 = temp1;
temp1 = temp2;
}
while(phase != result);
stModeUserData.Phase = best;
CAdjustPhase(stModeUserData.Phase);
return _ERROR_SUCCESS;
}
//--------------------------------------------------
// Description : Auto position process
// Input Value : None
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoDoAutoPosition(void)
{
BYTE result;
SWORD dtemp, ctemp, atemp;
result = CAutoMeasurePositionV(_MIN_NOISE_MARGIN);
if(_ERROR_SUCCESS != result) return result;
result = CAutoMeasurePositionH(_MIN_NOISE_MARGIN);
if(_ERROR_SUCCESS != result) return result;
/////////////////////////////////
// Calculate Vertical Position //
/////////////////////////////////
CScalerRead(_IPV_ACT_STA_H_0D, 2, pData, _AUTOINC);
ctemp = (((WORD)(pData[0] & 0x07)) << 8) | pData[1];
CScalerRead(_IVS_DELAY_11, 1, pData, _AUTOINC);
CScalerRead(_VGIP_HV_DELAY_13, 1, &pData[1], _AUTOINC);
dtemp = (((WORD)(pData[1] & _BIT0)) << 8) | pData[0];
dtemp = usVStartPos - dtemp;
atemp = abs(usVEndPos - usVStartPos + 1 - stModeInfo.IVHeight) / 2;
while(_TRUE)
{
if(abs(stModeUserData.VPosition + (ctemp - dtemp) - stModeInfo.IVStartPos + atemp) <= ucVStartBias)
{
stModeUserData.VPosition += ctemp - dtemp + atemp;
break;
}
else
{
stModeUserData.VPosition = stModeInfo.IVStartPos;
break;
}
}
CAdjustVPosition();
///////////////////////////////////
// Calculate Horizontal Position //
///////////////////////////////////
CScalerRead(_IPH_ACT_STA_H_09, 2, pData, _AUTOINC);
ctemp = (((WORD)(pData[0] & 0x07)) << 8) | pData[1];
CScalerRead(_IHS_DELAY_12, 2, pData, _AUTOINC);
dtemp = (((WORD)(pData[1] & _BIT0)) << 8) | pData[0];
dtemp = usHStartPos - dtemp - 2;
while(_TRUE)
{
if(abs(stModeUserData.HPosition + (ctemp - dtemp) - stModeInfo.IHStartPos) <= ucHStartBias)
{
stModeUserData.HPosition += ctemp - dtemp;
break;
}
else
{
stModeUserData.HPosition = stModeInfo.IHStartPos;
break;
}
}
CAdjustHPosition();
return _ERROR_SUCCESS;
}
//--------------------------------------------------
// Description : Tune ADC gain and offset
// Input Value : None
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoTuneBalance(void)
{
BYTE rev, result0, result1, color, count;
rev = CAutoMeasurePositionV(_MIN_NOISE_MARGIN);
if(rev != _ERROR_SUCCESS) return rev;
rev = CAutoMeasurePositionH(_MIN_NOISE_MARGIN);
if(rev != _ERROR_SUCCESS) return rev;
color = _BLUE;
while(_TRUE)
{
count = 0x30;
do
{
rev = CAutoTuneAdcGain(color, &result0);
if(rev == _ERROR_ABORT) return rev;
if(rev == _ERROR_FINISH) break;
rev = CAutoTuneAdcOffset(color, &result1);
if(rev == _ERROR_ABORT) return rev;
if(result0 == _WHITEBALANCE_MAX_LEVEL)
break;
}
while(--count);
if(color == _BLUE)
color = _GREEN;
else if(color == _GREEN)
color = _RED;
else
break;
}
}
*/
//version 200D
//--------------------------------------------------
// Description : Auto clock process
// Input Value : None
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoDoAutoClock(void)
{
BYTE result, phase;
WORD count, delta, stop;
LWORD maxval;
stModeUserData.Clock = stModeInfo.IHTotal;
stModeUserData.Clock &= 0xfffc;
CAdjustAdcClock(stModeUserData.Clock);
result = CAutoMeasurePositionV(_MIN_NOISE_MARGIN);
if(result != _ERROR_SUCCESS) return result;
delta = (stModeInfo.IHTotal - stModeInfo.IHWidth - (LWORD)stModeInfo.IHTotal * (LWORD)stModeInfo.IHSyncPulseCount / stModeInfo.IHCount) * 4 / 10;
stop = 0;
count = 10;
do
{
// Measure Horizontal Start/End
result = CAutoMeasurePositionH(_MIN_NOISE_MARGIN + 0x10);
if(result != _ERROR_SUCCESS) return result;
usHEndPos = usHEndPos + 1 - usHStartPos;
if(usHEndPos < stModeInfo.IHWidth)
{
if((stModeInfo.IHWidth - usHEndPos) >= (2 * delta))
{
stop = 1;
}
else
{
usHStartPos = (LWORD)(stModeInfo.IHWidth - usHEndPos) * (stModeUserData.Clock)
/ (LWORD)stModeInfo.IHWidth;
if(usHStartPos <= 2) break;
usHStartPos = (usHStartPos + 2) & 0xfffc;
//if((usHStartPos + stModeUserData.Clock - stModeInfo.IHTotal) > usDelta)
if((usHStartPos + stModeUserData.Clock) > (delta + stModeInfo.IHTotal))
{
stop = 1;
}
else
{
stModeUserData.Clock += usHStartPos;
}
}
}
else
{
if((usHEndPos - stModeInfo.IHWidth) >= (2 * delta))
{
stop = 1;
}
else
{
usHStartPos = (LWORD)(usHEndPos - stModeInfo.IHWidth) * (stModeUserData.Clock)
/ (LWORD)stModeInfo.IHWidth;
if(usHStartPos <= 2) break;
usHStartPos = (usHStartPos + 2) & 0xfffc;
//if((stModeInfo.IHTotal - (stModeUserData.Clock - usHStartPos)) > usDelta)
if((usHStartPos + stModeInfo.IHTotal) > (delta + stModeUserData.Clock))
{
stop = 1;
}
else
{
stModeUserData.Clock -= usHStartPos;
}
}
}
if(stop) break;
CAdjustAdcClock(stModeUserData.Clock);
}
while(--count);
if((count == 0) || (stop == 1)) return _ERROR_ABORT;
// Prevent from 1/2-line moire and smear effect.
if((usHEndPos >= stModeInfo.IHWidth && (stModeUserData.Clock - stModeInfo.IHTotal) == 4)
|| (usHEndPos < stModeInfo.IHWidth && (stModeInfo.IHTotal - stModeUserData.Clock) == 4))
{
stModeUserData.Clock = stModeInfo.IHTotal;
CAdjustAdcClock(stModeUserData.Clock);
result = CAutoMeasurePositionH(_MIN_NOISE_MARGIN + 0x10);
if(result != _ERROR_SUCCESS) return result;
usHEndPos = usHEndPos + 1 - usHStartPos;
}
#if(_AUTO_CLOCK_PRECISION < 4)
// Save 4N clock
stop = stModeUserData.Clock;
stModeUserData.Clock += (stModeInfo.IHWidth >= usHEndPos) ? 4 : 2;
CAdjustAdcClock(stModeUserData.Clock);
// Set threshold for Clock Search
CScalerSetByte(_DIFF_THRESHOLD_79, 0x18);
count = stop;
maxval = 0;
delta = 6; // Initial value must be (N * AUTO_CLOCK_STEP)
do
{
result = CAutoMeasurePositionH(_MIN_NOISE_MARGIN + 0x10);
if(result != _ERROR_SUCCESS) return result;
usHEndPos = usHEndPos + 1 - usHStartPos;
if(usHEndPos > (stModeInfo.IHWidth + 2))
{
((LWORD *)pData)[0] = 0;
}
else
{
((LWORD *)pData)[0] = CAutoPhaseSearch(_COLOR_SELECT, _HWAUTO_STEP_8, HWAUTOSTEPNUM(8), HWAUTOSTEPSTART(0), &phase);
if (0xffffffffL == ((LWORD *)pData)[0]) return _ERROR_INPUT;
}
if(maxval < ((LWORD *)pData)[0])
{
maxval = ((LWORD *)pData)[0];
count = stModeUserData.Clock;
}
if(delta == 0x00)
{
// Check if default clock is the best when clock searching range is larger than default.
if(stModeUserData.Clock > stModeInfo.IHTotal)
{
stModeUserData.Clock = stModeInfo.IHTotal;
CAdjustAdcClock(stModeUserData.Clock);
continue;
}
break;
}
delta -= _AUTO_CLOCK_PRECISION;
stModeUserData.Clock -= _AUTO_CLOCK_PRECISION;
CAdjustAdcClock(stModeUserData.Clock);
}
while(_TRUE);
maxval = maxval / 3;
stModeUserData.Clock = (maxval > ((LWORD)stModeInfo.IHWidth << 10)) ? count : stop;
CAdjustAdcClock(stModeUserData.Clock);
#endif
return _ERROR_SUCCESS;
}
//--------------------------------------------------
// Description : Auto phase process
// Input Value : None
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoDoAutoPhase(void)
{
BYTE result, phase, best;
LWORD maxsum, temp0, temp1, temp2;
result = CAutoMeasurePositionH(_MIN_NOISE_MARGIN);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -