Skip to content

Commit d6730e3

Browse files
committed
vs23: calibrateVsync(): repeat until we get a consistent result
The calibration sometimes returned incorrect results, leading to off frame timings or mistaking of an NTSC system for PAL. This version keeps sampling the timing until two consecutive measurements with a difference below 80000 cycles (0.5 ms at 160 MHz) are taken.
1 parent faefb64 commit d6730e3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ttbasic/vs23s010.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,22 @@ void SMALL VS23S010::setMode(uint8_t mode)
185185

186186
void VS23S010::calibrateVsync()
187187
{
188-
uint32_t now;
188+
uint32_t now, now2, cycles;
189189
while (currentLine() != 100) {};
190190
now = ESP.getCycleCount();
191191
while (currentLine() == 100) {};
192192
while (currentLine() != 100) {};
193-
m_cycles_per_frame = m_cycles_per_frame_calculated = ESP.getCycleCount() - now;
193+
for (;;) {
194+
now2 = ESP.getCycleCount();
195+
cycles = now2 - now;
196+
if (abs(m_cycles_per_frame - cycles) < 80000)
197+
break;
198+
m_cycles_per_frame = cycles;
199+
now = now2;
200+
while (currentLine() == 100) {};
201+
while (currentLine() != 100) {};
202+
}
203+
m_cycles_per_frame = m_cycles_per_frame_calculated = cycles;
194204
}
195205

196206
void ICACHE_RAM_ATTR VS23S010::vsyncHandler(void)

0 commit comments

Comments
 (0)