I've spent quite a few hours testing (and failing) on getting the video in the correct position in the frame. Generally I've been doing this by calculating during the infra-red interrupt just how far "out" the video is, based on the video playback pointer. And then I was trying to add an offset to the video playback to adjust that. Unfortunately the playback pointer is ALSO the "system clock" so that added all sorts of complications.
And then I thought... "hey, why not just spin the DISC a little faster/slower"? So I tried that, and it's fantastic. The video here shows the first version in action - the adjustment is only 1 pixel/frame so it takes ages to adjust. But I can increase that by an (almost) arbitrary amount and make the shifting MUCH quicker. But the really neat thing here is that I can be pixel-perfect on the video position not only horizontally but ALSO vertically. And so in the video you see three or four "starts" and after the initial PID synch (still slow, but reliable), then it goes into the "vertical/horizontal picture shift" and stops/stabilises with the frame EXACTLY framed vertically and horizontally. It's a thing of beauty. And all it took was about 3 lines of code... here's the infra-red servicing interrupt with the added code commented.
- Code: Select all
ISR(ANALOG_COMP_vect) {
timeDiff = playbackAbsolute;
double deltaSample = timeDiff - lastDetectedIR;
if (deltaSample > 1000) { // cater for potential "bounce" on IR detect by not accepting closely spaced signals
lastDetectedIR = timeDiff;
interrupts();
// The following 3 lines of code are the complete code for perfect horizontal/vertical framing
// Achieved simply by changing the rotation speed of the disc ever so slightly
pbDelta = playbackAbsolute % singleFrame;
if (pbDelta > 45) { // The 45 gives us vertical positioning - hardwired here for my monitor
lastDetectedIR-= 1;
}
Setpoint = 0;
Input = singleFrame-deltaSample;
Compute(); // PID
OCR0B = (byte)(Output+0.5); // write motor PWM duty
}
So, for just three lines of code to solve two problems (horizontal AND vertical framing). It's amazing.
Here's the video... the first 'lock' happens at 54 seconds, if you're impatient.
youtu.be/zXrc1Xl-fEc
I'm going to make it faster, of course - but for now I'm really incredibly happy with this solution It's elegant.