Skip to content

Commit

Permalink
vs23: calibrateVsync(): repeat until we get a consistent result
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
uli committed Apr 28, 2018
1 parent faefb64 commit d6730e3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ttbasic/vs23s010.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,22 @@ void SMALL VS23S010::setMode(uint8_t mode)

void VS23S010::calibrateVsync()
{
uint32_t now;
uint32_t now, now2, cycles;
while (currentLine() != 100) {};
now = ESP.getCycleCount();
while (currentLine() == 100) {};
while (currentLine() != 100) {};
m_cycles_per_frame = m_cycles_per_frame_calculated = ESP.getCycleCount() - now;
for (;;) {
now2 = ESP.getCycleCount();
cycles = now2 - now;
if (abs(m_cycles_per_frame - cycles) < 80000)
break;
m_cycles_per_frame = cycles;
now = now2;
while (currentLine() == 100) {};
while (currentLine() != 100) {};
}
m_cycles_per_frame = m_cycles_per_frame_calculated = cycles;
}

void ICACHE_RAM_ATTR VS23S010::vsyncHandler(void)
Expand Down

0 comments on commit d6730e3

Please sign in to comment.